Back to school on Polygons and map placement, (HI OverlayCollection)

Ok, so i am back to working on the UI for the map so my customers can really be effective with the way it sits.  Until today whenever i put a polygon on the screen i just wrote it straight to the map, so something like

myMap.addOverlay(myOverlay);

This is good and all, but here is the problem.  If you were to have more than one overlay that was realted and you wanted to manipulate it, you would have an extreamly hard time with it written directly to the map.  Try this proposal. 

Use an overlayCollection(olc)!  This is the coolest thing because now you have all the polygons that relate to one another, you can just throw them in this thing, make sure you assign a key to all of them and now whenever you want to manupluate the way one looks just loop through the overlayCollection, find the key of the item that you are looking for and make the change, then that is it.  It will write it out on the screen for you. 

 One issue you might encounter is if your polygons share a border, if so the last border laid goes on top. 

  • solution 1:  remove the polygon and add it back, this will happen after the map redraws the polys initially and your borders will appear all cool and such, here is the code:
    myMap.removeOverlay(PolygonOverlay(olc.get(a)));
    myMap.addOverlay(PolygonOverlay(olc.
    get(a)));
  • Possible solution 2:  make your other borders as transparent as possible, this will allow the black to bleed through?  have not tried this though

So in summary i think that you should never put a polygon on the map straight away unless you plan on destroying it and never manipulating it.  Put it in the overlayCollection then add them to the map from it.

That’s all for now, come back soon and i will try to impart some more wisdom in your skull!


About this entry