[英]Openlayers export to KML and keep my map styles
I successfully write a KML from Openlayers, however no styles (colors, stroke, etc.) are present in the kml file. 我成功地从Openlayers写了一个KML,但kml文件中没有样式(颜色,笔画等)。 Is it possible to generate the KML with the styles? 是否可以使用样式生成KML?
I found a similar question here: https://gis.stackexchange.com/questions/17031/openlayers-format-kml-write-style 我在这里找到了类似的问题: https : //gis.stackexchange.com/questions/17031/openlayers-format-kml-write-style
Thanks in advance. 提前致谢。
As of yet the WRITE method does not make use of the 'extractStyles':true,
property as you can see here . 到目前为止,WRITE方法没有使用'extractStyles':true,
属性,你可以在这里看到。 Only the READ method does. 只有READ方法才有。
The only way I saw was simply to recreate them. 我看到的唯一方法就是重新创建它们。 In the example below, I've created the KML style I wanted and Injected it into openlayers created kml string. 在下面的示例中,我创建了我想要的KML样式,并将其注入openlayers创建的kml字符串。
myorg.Util.GetKMLFromFeatures = function (features, strfolderName, strfolderDescription) {
var format = new OpenLayers.Format.KML({
'maxDepth': 10,
'extractStyles': true,
'internalProjection': myorg.UI.Map.getMap().baseLayer.projection,
'externalProjection': myorg.UI.Map.Projections.Geographic
});
var kmlStyle = "<Style id='OutlineOnlyStyle'><PolyStyle><color>ff0000cc</color><fill>0</fill><outline>1</outline></PolyStyle></Style>";
format.foldersName = strfolderName;
format.foldersDesc = strfolderDescription;
//add style description
var kml = format.write(features).replace(/<Folder>/g, '<Folder>' + kmlStyle)
.replace(/><name>/g, '><styleUrl>#OutlineOnlyStyle</styleUrl><name>');
return kml;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.