Afternoon ThinkGeo.
During the init of my map I need to set where the map is looking. All the examples you have use a fixed RectangleShape and that works well. But I cannot use a set in code fixed point.
Being a mobile app I want to use the following rules in the defined order when the previous one cannot be used:
- If I have any features then get a bounding box of those and use that as extent.
- If no features yet then lets use the Devices location as a starting point.
- If I cannot obtain Devices location (permissions not given, etc) then I will simply show the country as the extent.
Lets talk about each of those rules as I have a few questions on each. I now see why your samples all use a set in code fixed Rectangle as this is hard.
- If I have any features. I say if I have any as the features will be coming down the line using SignalR so the data may have arrived or not. I cannot be sure. In the early stages of my development I had the simple scenario of a single Overlay and Layer. I used the following code:
MapView.CurrentExtent = RectangleShape.ScaleUp(MapView.Overlays[MyOverlay].GetBoundingBox(), 100).GetBoundingBox();
This worked well when there are features within that Overlay. I get a box, then I scaled it a little and it looked perfect. I note that when there are no features to be found in that Overlay then the bounding box is small and is the middle of the map. No error just in the middle of the ocean. Today as my app progresses I have many Overlays with many Layers so I need to do something different. I also have to be careful to not try to obtain a bounding box for no features.
So the logic here I use is to iterate over all the Overlays, then iterate over the layers and if there are features I get the bounding box and pop that into a collection as I may have quite a few.
At the end if there are entries in the the collection I then take the first entry as a bounding box and then for each one after the first I use RectangularShape.ExpandToInclude. At the end of this I should have a bounding box that encompasses all my features. I have yet to test this but I think this logic is sound. What do you think?
-
Center on Device Location.
If I have no features, which is quite possible, I then request for the devices coordinates.
I have those and I create a baseshape from the coordinates using the correct projection.
This is where I am having some issue as I create a boundingbox from that baseshape and set that as my extent. It is the correct position on map but the zoom is not right and the tiles do not render correctly. If I then zoom out using the map controls it is perfectly rendered. How do I get the correct zoomlevel during mapview init? I cannot use zoomto as the map has not completed. I guess I am looking to be at the city block zoom level if I am centering on Device. How do I set that using the extent? -
Have the extent set to the country level.
This one is easy as I can hard code this in code and this is my final fall back if the user insists on not allowing my app to obtain the device location.
I hope you can help here with the Center on Device Location.
My environment is:
Xamarin Forms 5.0.0.2401
ThinkGeo Maps 12.3.18
Cheers
Chris …