Max*_*lan 6 javascript openlayers geojson
我的代码显示了GeoJSON中的标记,当我放大到缩放级别10时,它会加载GeoJSON文件,但是如何避免重新输出相同的标记呢?有没有办法检查特定地方是否已经存在标记?代码
map.events.register("zoomend", null, function(){
if(map.zoom == 10)
{
var bounds = map.getExtent();
console.log(bounds);
var ne = new OpenLayers.LonLat(bounds.right,bounds.top).transform(map.getProjectionObject(),wgs84);
var sw = new OpenLayers.LonLat(bounds.left,bounds.bottom).transform(map.getProjectionObject(),wgs84);
var vectorLayer = new OpenLayers.Layer.Vector();
map.addLayer(vectorLayer);
$.getJSON('ajax.php?a=markers&type=json&sw=('+sw.lon+','+sw.lat+')&ne=('+ne.lon+','+ne.lat+')',function(data){
//$.getJSON('test.json',function(data){
var geojson_format = new OpenLayers.Format.GeoJSON({
'externalProjection': wgs84,
'internalProjection': baseProjection
});
vectorLayer.addFeatures(geojson_format.read(data));
});
}
});
Run Code Online (Sandbox Code Playgroud)
为什么不使用BBOX\xc2\xa0 Strategy[1] ?
这将满足您的需求,并且性能肯定会更高(它将删除现有功能并在 上重新加载新功能zoomend)。比较功能以添加新功能需要进行大量比较,并且您的地图上可能会出现太多功能。
查看示例的js源码。
\n\n哈特哈,
\n\n1 - http://openlayers.org/dev/examples/strategy-bbox.html
\n\n编辑:如果您想更改较少的代码,则在添加之前调用vectorLayer.removeAllFeatures()将解决您的问题\xe2\x80\xa6 您真的需要使功能超出范围吗?
| 归档时间: |
|
| 查看次数: |
1756 次 |
| 最近记录: |