I have an OpenLayers.Map
(map
) that has an OpenLayers.Layer.Vector
(map.addLayer(vectorLayer)
), and I use the vectorLayer.addFeatures
to add a series of OpenLayers.Feature.Vector
objects to vectorLayer
.
The process is a bit like this:
var map, vectorLayer;
function initialize()
{
map = new OpenLayers.Map(/*...*/);
vectorLayer = new OpenLayers.Layer.Vector(/*...*/);
map.addLayer(vectorLayer);
}
function populate()
{
arrayOfStuff.foreach(function(thing, i) // data from an AJAX call
{
var feature = new OpenLayers.Feature.Vector(/*...based on thing*/));
feature.vector_type = 'marker';
vectorLayer.addFeature(feature);
}
}
When I then use map.setCenter
to move the map, the vectors get misplaced: some shift with the map, some do not, some do both (causing duplicates), and so on. Manually panning the map even slightly immediately fixes these misplaced vectors. Unfortunately, simply calling map.pan
does not (consistently) have the same effect, and vectorLayer.refresh()
doesn't seem to have any effect at all.
Why is this happening and how do I get it to stop? Failing that, what can I do to force the map to fix itself (as it does when I move the map).