我正在敲牆頭,想知道爲什麼這種風格沒有被應用。點以默認樣式呈現。不能得到Openlayers 3風格的應用
if ((Math.abs(prevCoord[0] - currCoord[0]) < 500) && (Math.abs(prevCoord[1] - currCoord[1]) < 500)) {
console.log("tortuous");
var tortySource = new ol.source.Vector(); // create an empty source instance
var tortyPoint = new ol.geom.Point(currCoord);
var tortyFeature = new ol.Feature({ // create a feature with the point geometry
geometry: tortyPoint,
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255,0,0,0.5)'
})
})
});
tortySource.addFeature(tortyFeature); // add the feature to the source
var tortyLayer = new ol.layer.Vector({ // create a layer with that source
source: tortySource
});
map.addLayer(tortyLayer);
};
編輯當我試圖使用的setStyle,我做了這個樣子。我所有的觀點都消失了。
if ((Math.abs(prevCoord[0] - currCoord[0]) < 500) && (Math.abs(prevCoord[1] - currCoord[1]) < 500)) {
console.log("tortuous");
var tortySource = new ol.source.Vector(); // create an empty source instance
var tortyPoint = new ol.geom.Point(currCoord);
var tortyFeature = new ol.Feature({ // create a feature with the point geometry
geometry: tortyPoint
});
tortyFeature.setStyle(
new ol.style.Style({
fill: new ol.style.Fill({
color: [255, 0, 0, 0.5]
})
})
);
tortySource.addFeature(tortyFeature); // add the feature to the source
var tortyLayer = new ol.layer.Vector({ // create a layer with that source
source: tortySource
});
map.addLayer(tortyLayer);
};
如果您創建瞭如下功能,則代碼更少:'new ol.Feature(new ol.geom.Point(coord))'。 –