0
使用ol.format.KML writeFeatures()時,我無法理解defaultStyle
。我寫出的功能沒有單獨的樣式,因此我想將圖層樣式應用於KML功能。我試過這個:KML格式writeFeatures defaultStyle
var features = vectorLayer.getSource().getFeatures(); // these do not have styles
var layerStyle = vectorLayer.getStyleFunction()(features[0], map.getView().getResolution());
var kmlFormat = new ol.format.KML({
defaultStyle: layerStyle
})
var kml = kmlFormat.writeFeatures(features, {
featureProjection: map.getView().getProjection() // source coord sys
});
console.log(kml);
但是kml沒有造型。如果我圖層樣式複製到每個功能:
features.forEach(function(feature) {
feature.setStyle(layerStyle);
});
然後KML具有造型,即使我刪除{defaultStyle: layerStyle}
。但我不希望將圖層中的樣式複製到每個單獨的功能中。理想情況下,我希望kml爲沒有自己樣式的功能提供圖層樣式,並將功能樣式用於具有自己樣式的功能。
那麼defaultStyle
做什麼以及什麼時候使用?
也許defaultStyle
僅適用於讀取KML,不寫?