[OpenLayers-Users] Do not re-add markers...
Max Allan Niklasson
fisktarna at fagelboken.se
Thu Oct 20 17:35:23 EDT 2011
I've made a script, that is make an ajax-request when I zoomed into
level 10, then it add markers. Afterwords when I zoom into 11 and then
out to 10, the markers is being re-added to the map... Is there a way to
not have it like this?
My code....
**************************************************
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){//GeoJSON
//$.getJSON('test.json',function(data){
var geojson_format = new OpenLayers.Format.GeoJSON({
'externalProjection': wgs84,
'internalProjection': baseProjection
});
vectorLayer.addFeatures(geojson_format.read(data));
});
}
});
**************************************************
Best regards
The Red Kite
More information about the Users
mailing list