1

我正在从服务器加载 shapefile,然后在 OpenLayers 中绘制它。shapefile 包含超过 400,000 个具有不同不透明度的多面体。我需要设置不透明度和填充颜色,但 openlayers 似乎忽略了它,而只是绘制橙色方块。我在更改属性之前和之后使用 console.log(),它显示了我分配的内容。谁能告诉我为什么这样做?

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

}

4

1 回答 1

4

好吧,样式属于.style属性而不是.attributes功能。redraw()如果它已经在地图上,您还需要打电话。

pointLayer.features[featureNumber].style = green;
pointLayer.redraw();

如果您想从默认样式开始并仅更改一些内容,则可以执行以下操作:

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();
于 2012-11-28T21:18:09.953 回答