你應該能夠完成,甚至沒有基於上下文的造型這項任務;您只需定期更改矢量圖層的樣式並重新繪製它。嘗試是這樣的:
window.setInterval(function(){
var defaultStyle = yourVectorLayer.styleMap.styles['default'].defaultStyle;
yourVectorLayer.styleMap.styles['default'].defaultStyle = {
fillColor: defaultStyle.fillColor === 'blue' ? 'green' : 'blue',
pointRadius: 10
}
yourVectorLayer.redraw();
}, 1000);
一個完整的工作示例如下
var map = new OpenLayers.Map('map', {
maxResolution:'auto',
layers: [
new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0",
{layers: 'basic'}
),
new OpenLayers.Layer.Vector('Points', {
styleMap: new OpenLayers.StyleMap({
pointRadius: 10,
fillColor: "blue"
})
})
],
center: [0,0]
});
var features = [];
for (var i=0; i<100; i++) {
var x = Math.random() * 360 - 180,
y = Math.random() * 180 - 90;
features.push(
new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(x, y)
)
);
}
map.layers[1].addFeatures(features);
window.setInterval(function(){
var defaultStyle = map.layers[1].styleMap.styles['default'].defaultStyle;
map.layers[1].styleMap.styles['default'].defaultStyle = {
fillColor: defaultStyle.fillColor === 'blue' ? 'green' : 'blue',
pointRadius: 10
}
map.layers[1].redraw();
}, 1000);
感謝ü非常..它工作得很好:) @ AFI – SSS
當我在地圖上點擊添加一個點這個工程。但是,如果該點以編程方式設置,則該項目符號會按照默認設置顯示爲黃色。 – raratiru