mobile-sdk icon indicating copy to clipboard operation
mobile-sdk copied to clipboard

MoveToFitBounds / Screenbounds calculation Xamarin iOS

Open boehlefeld opened this issue 7 years ago • 2 comments

Does Carto not resize and pan correctly on iOS binding when calling moveToFitBounds with reduced screen bounds?

Assuming following calculation on iOS side:

nfloat intHeight = UIScreen.MainScreen.NativeBounds.Height;
nfloat intWidth = UIScreen.MainScreen.NativeBounds.Width;
nfloat scale = UIScreen.MainScreen.NativeScale;
ScreenPos minScreenPos = new ScreenPos(50, 50);
ScreenPos maxScreenPos = new ScreenPos((float)(intWidth - 50), (float)(intHeight - 50));

MoveToFitBounds(mapBounds, ScreenBounds(minScreenPos, maxScreenPos), false, 1.5f);

Left side has more space than ride side. In case of ScreenPos(0,0) and ScreenPos(width, height) everything is fine.

Android works as expected.

Any idea?

[Edit] I may need to say, that in mapBounds exist a couple of coordinates. I just wanted to set a (scaled) delta to each side.

boehlefeld avatar Nov 24 '17 10:11 boehlefeld

Hey

It looks like you're not using scale. iOS automatically translates to scaled coordinates, you need to multiply by the scale for it to be correct. Android's api returns actual resolution.

Either that, or your calculation is wrong. If you want "reduced bounds" to be centered, you need to substract double your padding/margin (your 50).

A sample of using Scale and MoveToFitBounds is available here: https://github.com/CartoDB/mobile-sample-data-collection/blob/master/iOS/MainController.cs#L220

Nikituh avatar Nov 24 '17 11:11 Nikituh

Thanks for the help. Solution was adapting only maxX, maxY. It gets centered afterwards.

nfloat height = UIScreen.MainScreen.Bounds.Height;
nfloat width = UIScreen.MainScreen.Bounds.Width;

ScreenPos minScreenPos = new ScreenPos(0, 0);
ScreenPos maxScreenPos = new ScreenPos((float)(width * 1.7), (float)(height * 1.7));

boehlefeld avatar Nov 24 '17 14:11 boehlefeld