admin管理员组文章数量:1202340
In the following example the markers are loaded from a JSON.
If there are 20,000 markers the JSON is going to be quite big.
Is there any way to send different JSON files according to zoom level instead of sending one huge array?
.html
In the following example the markers are loaded from a JSON.
If there are 20,000 markers the JSON is going to be quite big.
Is there any way to send different JSON files according to zoom level instead of sending one huge array?
http://gmaps-utility-library.googlecode.com/svn/trunk/markermanager/release/examples/weather_map.html
Share Improve this question edited Jan 31, 2014 at 5:31 Kara 6,22616 gold badges53 silver badges58 bronze badges asked Apr 29, 2009 at 18:57 FranekFranek 2,0554 gold badges20 silver badges20 bronze badges5 Answers
Reset to default 8There's the notion of a "bounding rectangle" for a map view. The map api supplies this to you as two lat/long coordinate pairs - one for the SW corner, and one for the NE corner.
So if you have a custom data service that returns JSON points, you'll need to accept these coordinates as input, and adjust the returned dataset accordingly (most likely as a WHERE clause in your SELECT statement).
I don't have the details of getting this bounding rectangle memorized, but that's what API docs are for.
There is a new library called MarketClustered that will help you
(source: googlecode.com)
Even if the data is too big, I think that will be better to feed the map will all the data, and let it do it's thing.
Yes, I did something similar in an application for a local authority where we were displaying the volume each house recycled across 6,000 odd households. As the total volume of data (which included address and statistical info for each household) was quite large pulling back the whole data file in one go caused the browser to appear to hang.
So instead in the AJAX call to the database we sent the bounding rectangle coordinates (latitude,longitude) of the map area then only returned those points that we visible. Because of the nature of the application a user-driven button to 'fetch data' was quite acceptable, but there's obviously lots of other variations you can play on the theme - once you are delivering the bounding coordinates to the server side you can decide what to do there - for instance only return a subset if the zoom level is too high. You should be able to catch the map draw event too and action this automatically.
When the zoom changes, send the new zoom level to your JSON service and return the markers that should be visible at that level. Use addMarkers() to add the results to MarkerManager and make them visible only at the current zoom level.
The other responses here have suggested returning only the markers within the current view, but you could also just return all of the markers at that zoom level. It depends on how much you know about which markers you want to show at each level.
Possible ways to solve this problem:
- Build the
JSON
on serverside, depending to the zoomlevel (con: needs reload after a zoom, pro: only small amouts of data need to be loaded) - Include the informations about how a marker is accessible in the
JSON
data (pro: only one time data need to be loaded, con: iterate through the data withJavaScript
) - Calculate visible markers in
JavaScript
(pro: very dynamic, con: heavy calculation load)
本文标签: javascriptGoogle MapsThousands of markersJSONStack Overflow
版权声明:本文标题:javascript - Google Maps - Thousands of markers - JSON - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738634235a2103929.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论