I'd like to zoom the map to set the current extent to the boundingbox of all Markers in a MarkerLayer. How is that done?
bob
I'd like to zoom the map to set the current extent to the boundingbox of all Markers in a MarkerLayer. How is that done?
bob
Hello Bob,
So what’s the MarkerLayer type? SimpleMarkerOverlay? InMemoryMarkerOverlay? If it’s these two, you can’t directly get the boundingbox, but every marker actually is a pointshape, so you can create a InMemoryFeatureLayer and add all the marker into this layer as pointshape, so that you can get this featurelayer’s boundingbox.
Regards,
Gary
Its a SimpleMarkerOverlay. So I guess we go with plan "B", thanks!!
bob
Hello Bob,
You are welcome, please feel free to let us know your problem.
Regards,
Gary
How about using ExtentHelper.GetBoundingBoxOfItems? It doesn't look like the Marker class comes from BaseShape so you probably can't just pass the list of markers, but since you obviously have the coordinates it would be easy build a list of PointShapes to pass to GetBoundingBoxOfItems.
Allen
Hello Allen,
Yes, it’s a good way, actually the key part is get the coordinates of marker and become the pointshape, but the way you suggest it’s easier to understand.
Thanks for your help.
Gary
I agree the second way was easier, but now the problem is, that when I set the WinFormMap control’s “CurrentExtent” to that rectangle, it doesn’t include ALL of the points!!
Ideas? I have to zoom out to see them all, which kind of defeats the point of the excercise. :(
bob
Hello Bob,
Can you give me all your marker’s location? I can make a test.
Regards,
Gary
Actually, I don't think that was my problem....but as a simple workaround I want to add a buffer around the bounding box so that I force it to expand a bit beyond the set of Markers. Can you give me some suggestions on how to accomplish that? i.e., take the bounding box given and add X meters to each side or better X % to each side.
bob
Bob,
Yeah I’ve seen that by using this method to generate a bounding box of vehicle positions…the points that are right on the edges tend not to be rendered. GetBoundingBoxOfItems returns a RectangleShape, so you could use RectangleShape.Buffer. This takes a distance, so you might say extent = RectangleShape.Buffer(RectangleShape.Width * 0.05) or something like that. Also note that depending on what gets sent to it GetBoundingBoxOfItems can return a bounding box with an aspect ratio way out of line with the map (say it’s 5 times taller than wide or 5 times wider than tall rather than a normal map that might be between 1:1 and 1.5:1) and MapSuite tends to ignore it. Whenever I use GetBoundingBoxOfItems I automatically follow it with ExtentHelper.GetDrawingExtent which seems to readjust the extent to match the map’s aspect ratio and MapSuite then accepts the new extent.
Allen
Thank you Allen.