Put All The Markers at Once!
The way OpenLayers puts markers on the stage is fine when they are not so much, but once you need more than 100, the library’s solution is not good. The question is is there a way to put all the markers faster than the built in method.
Yes, There is a Way to Speed Up Markers Load
I once wrote about how to speed up markers on OpenLayers, it is clear that my decision was to concatenate the DOM elements like a string after I’ve generated all the markers as markup with innerHTML as it’s faster than appendChild. The only question left is how to convert Longitude/Latitude pair in pixels.
The Answer’s Given by OpenLayers
There is a method called getLayerPxFromLonLat() which do the job. Let me show you a snippet:
ll = map.getLayerPxFromLonLat(new OpenLayers.LonLat(lon,lat)); console.log(ll); |
You can see what’s inside the ll object. You can now reference the pixel as ll.y and ll.x.