[英]Changing the draw attributes of a vector feature in open layers
I am loading a shapefile from a server and than drawing it n OpenLayers. 我正在从服务器加载shapefile,而不是在OpenLayers中绘制它。 The shapefile contains over 400,000 multipolygons with varying opacity.
shapefile包含超过400,000个具有不同不透明度的多边形。 I need to set the opacity and fill color yet openlayers seems to be ignoring it and just drawing orange squares instead.
我需要设置不透明度和填充颜色,但openlayers似乎忽略它,而只是绘制橙色方块。 I console.log() before I change the attributes and after and it shows what I assigned it.
我更改属性之前是console.log(),然后它显示我分配的内容。 Can anyone tell me why it is doing that?
任何人都可以告诉我为什么这样做?
var green = {
fill: true,
fillColor: "#006633",
fillOpacity: 1
};
var features = wkt.read(element);
if (featureNumber == 0){
document.getElementById('result').innerHTML=element;
}
features = element.toString();
var bounds;
var b = features.indexOf('MULTIPOLYGON', 0);
var c = features.indexOf('MULTIPOLYGON', 40);
if (c == -1) {
c = element.indexOf(':',b+1);
}
leftovers = features.substring(c,100000000000000000);
features = features.substring(b,c);
features = wkt.read(features);
if(features) {
if(features.constructor != Array) {
features = [features];
}
for(var i=0; i<features.length; ++i) {
if (!bounds) {
bounds = features[i].geometry.getBounds();
} else {
bounds.extend(features[i].geometry.getBounds());
}
}
pointLayer.addFeatures(features);
console.log(pointLayer.features[featureNumber].attributes );
pointLayer.features[featureNumber].attributes = green;
console.log(pointLayer.features[featureNumber].attributes );
featureNumber++
map.zoomToExtent(bounds);
var plural = (features.length > 1) ? 's' : '';
console.log('Feature' + plural + ' added');
console.log('feature number: '+featureNumber)
if (leftovers.indexOf('MULTIPOLYGON',0) != -1) {
parseWKT(leftovers,shapefile);
}
} else {
final(leftovers, shapefile);
}
} }
well the style belongs in the .style
property not the .attributes
of the feature. 该样式属于
.style
属性,而不属于该功能的.attributes
。 You'll also need to call redraw()
if it's already on the map. 如果已经在地图上,你还需要调用
redraw()
。
pointLayer.features[featureNumber].style = green;
pointLayer.redraw();
If you want to start out with the default style and just change a few things, you can do something like this: 如果您想从默认样式开始并只是更改一些内容,您可以执行以下操作:
var green = OpenLayers.Util.applyDefaults(green, OpenLayers.Feature.Vector.style['default']);
green.fill = true;
green.fillColor = "#006633";
green.fillOpacity = 1;
pointLayer.features[featureNumber].style = green;
pointLayer.redraw();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.