0
votes

I have an openlayers map with markers added as geometry vector points. In the style option I set a size for each. However, the problem is, that if I zoom in or zoom out, they all become the same size until I load the entire page again. In other words, once I zoom in or out, they are all the same.

var layer_style = OpenLayers.Util.extend({},
OpenLayers.Feature.Vector.style['default']);
var style = OpenLayers.Util.extend({}, layer_style);

var pointLayer = new OpenLayers.Layer.Vector("Point Layer");

map.addLayers([terrain, road, satellite, hybrid, pointLayer]);
var lonlat = new OpenLayers.LonLat(0, 140);
lonlat.transform(proj, map.getProjectionObject());
map.setCenter(lonlat, 2);

var point = new OpenLayers.Geometry.Point(-40, -40);
point = point.transform(proj, map.getProjectionObject());
style.pointRadius = 10;
var pointFeature = new OpenLayers.Feature.Vector(point, null, style);
pointLayer.addFeatures([pointFeature]);

var point = new OpenLayers.Geometry.Point(-40, -40);
point = point.transform(proj, map.getProjectionObject());
style.pointRadius = 40;
var pointFeature = new OpenLayers.Feature.Vector(point, null, style);
pointLayer.addFeatures([pointFeature]);

When I load this, I get two markers, one size 10, the other 40. But when I zoom in or out, they all become same size.

1

1 Answers

0
votes

You are overwriting the pointRadius property of the style object each time, so in the end the last value will be used as OpenLayers will only point to the style. What you need to do is use a lookup to let the pointRadius depend on a given feature attribute. See Rule-based Styling: http://trac.osgeo.org/openlayers/wiki/Styles#Rule-basedStyling