So I am having trouble with plotting hundreds of markers in a timely way. I have more than 400 markers, all set up in XML (whoes quality is so-so and I am already working on making that nicer). But the issue is that the page takes more than 10 seconds to parse the XML and attach the markers.
I have seen some other sites that are handling almost equal amounts of points and process in a flash. So there must be a better way than what I am doing. And I have searched through lots of post here and on the various gmap wiki sites etc. I have not seen this clearly spelled out, so I hope there is a genius in the house who can lend some help.
Your site looks great! Keep up the good work. I don't think your
issue is the parsing of the xml. I believe it is the rendering of the
points on the map that takes a while. If you look at the housing map
that you used in your example, they rarely plot more than 100 points at
the same time. The system seems to start crawling somewhere around
250-300 points.
A very good example can be found at
http://www.localligence.com/demos/maps/lotsofpoints/map-all.html. Here
the loading takes a while but you can see the progress. I have not
tried to replicate this but I believe it is a more elegant solution
than keeping a user waiting.
atomicBirdsong wrote:
> So I am having trouble with plotting hundreds of markers in a timely
> way. I have more than 400 markers, all set up in XML (whoes quality is
> so-so and I am already working on making that nicer). But the issue is
> that the page takes more than 10 seconds to parse the XML and attach
> the markers.
> I have seen some other sites that are handling almost equal amounts of
> points and process in a flash. So there must be a better way than what
> I am doing. And I have searched through lots of post here and on the
> various gmap wiki sites etc. I have not seen this clearly spelled out,
> so I hope there is a genius in the house who can lend some help.
atomicBirdsong wrote: > So I am having trouble with plotting hundreds of markers in a timely > way. I have more than 400 markers, all set up in XML (whoes quality is > so-so and I am already working on making that nicer). But the issue is > that the page takes more than 10 seconds to parse the XML and attach > the markers.
I notice you're creating a completely new map type and using that instead of the default street map. Maybe that's the reason. If use the default map do the markers appear any faster?
I don't care for your use of a new map type, since it renders the satilite view useless. (IMHO)
My solution was to allow people to click the map (and return a lat/lon at where the click was, then place these coordinates into a couple of form boxes) then ask people to choose a radius in miles. Click search.
Using a bit of maths it find all sites located within the radius, loads up the new map centered to the lat/lon of the previous click, and then loop through using php placing all the points within 20 miles of the click. You could also adjust zoom level depending on radius selected.
You could obviously preselect a radius to make it work from a single click.
Is there any advantage to having the data already parsed on the server and just sending it to the client as js variables? Or something like that - to get rid of all the processing...or is the time really in the attaching the markers to the map?
thanks Inspireme. I was thinking about doing something like this.
Probably would want to tie that to a map repositioning function and marker caching so you dont reload points already plotted. I'll have to look at the API to see if the first is possible.
Using sql is the best because I can limit what is shown using queries. Gives lots of flexibility and allows me to load less points which is loads quicker.
Like-for-Like Its perhaps a little faster than loading the data.xml file, i havent tested it though.
The performance problem appears to stem from the 'AddOverlay' method. It would make sense if you could add the markers to a collection as you create them, and then call 'AddOverlay' just once when you are done. This might allow some time savings, depending on how their code is set up.
I agree with the poster. As it currently sits, this is a significant limitation. My application will easily require 100 to 200 objects visible at once, which takes between 1 and 2 minutes to load at present.
4) this is an experimental page using some code i kind poster on these
forums provided to do a "zoom" function. I have lots of work to do on
it but hopefully this will replace the above slow map
http://www.bigfreeguide.com/camping/GAPI/livepoint1.htm
the last link *may* only work in firefox - i cant seem to get it to
load the headers and footers on this page in IE without causing errors.
(Even wrapping the code in a function wont work)
Hope this give you some ideas. most works on the radius search i posted
above.
A subsequent test seems to confirm that the problem is the 'AddOverlay' call. If you display a 500 segment polyline with a single 'AddOverlay' call it is fast. If you display 500 individual polylines with an 'AddOverlay' for each one it takes forever. This makes me think that the speed problem could be eliminated by adding a collection class for Markers and passing the collection class into the 'AddOverlay' method.
sounds great, would it work with each marker having seperate html info
boxes? I havent looked into that greatly as it just worked from the
examples (havent altered it much yet)
hmmm....trying MAB's suggestion of putting at least a counter on the map while it loads, and noticed something interesting.
The way my script is structured I use a for() loop to go through all the XML, but when I put in the counter, it never changed the visible text on the window until it was done with all the elements. But after doing a little check it was definately changing the DOM element.
In looking at the structure of the provided link by MAB, I noticed the author structured their XML load as a redundant function call...first the XML is parsed in an onload function, then there is another function which only adds one Marker. The author also uses a time delay between each call with: window.setTimeout();
like so, where mapOne adds a Marker:
if (request.readyState == 4) { var xmlDoc = request.responseXML; markers = xmlDoc.documentElement.getElementsByTagName("marker"); window.setTimeout(mapOne,timeOut); }
The interesting consequence of this seems to be is that this allows the visible window to redraw in between each marker load...as there is a break in the process of adding markers, at this time the screen updates and the user can also move the map and make clicks.
This seems to be a reverse alternative to the one being pursued by inspireme and crash who are looking to find a way to add the markers all at once.
Ok, as asked for, a method to load multiple overlays at once. Simply pass the function an array of markers (a non-associative array, please!), and it seems to increase load speed dramatically. To use, simply place in a script tag anywhere after you load the Google Maps API script, and then call it instead of using multiple addOverlay calls.
take this under consideration:
GMap.prototype.addOverlays=function(a){ var b=this; for (i=0;i<a.length;i++) { try { this.overlays.push(a[i]); a[i].initialize(this); a[i].redraw(true); } catch(ex) { alert('err: ' + i + ', ' + ex.toString()); } } this.reOrderOverlays();
};
Also, if anyone is interested, I have an API addon I have written to allow USGS Terraserver images to be loaded (as extra maptypes). In fact, the structure of it would easily enable anyone to make there own Map Type extention
Holy Crap. I just tested this further. I loaded 1300 Markers in less then 20 seconds... I think this is problem solved... The map does move a bit sluggishly, both on panning and zooming, so 1300 is probably a bit much - but 500 or so seems to have no issues, and is FAST to load.
Interesting - thats your function? It looks like ;n.prototype.addOverlay() but with an array loop added...?
although it also looks like you left out adding a click method to your markers?: from ;n.prototype.addOverlay():
//-----
var b=this; j.addListener(a,"click",function(){j.trigger(b,"click",a)
//-----
1300 in 20 secs is damn fast! I'll try it out.
Also I've just been combing through version 11 and pulling this stuff apart to try to find the related .redraw() to suspend the likely "this.map.div.appendChild" -- guessing here -- that plots a marker...thinking to suspend it after all markers are appended to the overlays array....but your report it curious too
if anyone wants to email me to work on this you can at wjames5 -=at=- nyc.rr.com
yes, it is based on the prototype function in the API - that stands to reason. As for the click event, I do not see any functional differance between it being there and not - I always add a click event later, to pop up an info window, so...