Openlayers标记大小

时间:2013-08-01 16:00:34

标签: vector openlayers

我有一个openlayers地图,标记被添加为几何矢量点。在样式选项中,我为每个设置了一个大小。但问题是,如果我放大或缩小,它们都会变成相同的大小,直到我再次加载整个页面。换句话说,一旦我放大或缩小,它们都是一样的。

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]);

当我加载它时,我得到两个标记,一个尺寸为10,另一个为40.但是当我放大或缩小时,它们都变得相同。

1 个答案:

答案 0 :(得分:0)

每次都会覆盖样式对象的pointRadius属性,因此最后将使用最后一个值,因为OpenLayers只会指向样式。 您需要做的是使用查找让pointRadius依赖于给定的要素属性。 请参阅基于规则的样式:http://trac.osgeo.org/openlayers/wiki/Styles#Rule-basedStyling