【发布时间】:2014-03-20 16:38:49
【问题描述】:
我使用 OpenLayer 加载 KML。加载图标,但不显示标签。如果我删除“样式”部分,则会显示标签,但不会显示图标。任何想法都受到高度赞赏。谢谢
我的代码:
var myStyles2 = new OpenLayers.StyleMap({
"default": new OpenLayers.Style({
strokeColor: "#FFCC33",
strokeWidth: 6,
strokeOpacity: 1,
fillColor: "#003399",
fillOpacity: 0,
label: "${name}",
fontSize: "40px"
})
});
var OMapShips = new OpenLayers.Layer.Vector("KML", { styleMap: myStyles2,
projection: new OpenLayers.Projection("EPSG:4326"),
strategies: [new OpenLayers.Strategy.Fixed({ preload: false })],
protocol: new OpenLayers.Protocol.HTTP({
url: 'js/hl/XMLFile.xml',
format: new OpenLayers.Format.KML({
extractStyles: true,
extractAttributes: true,
maxDepth: 2
})
}),
renderers: ["SVG"]
});
OMap.addLayers([OMapShips]);
KML 摘录
<?xml version="1.0" encoding="utf-16" standalone="yes"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="shipsKML">
<name>shipsKML</name>
<Placemark id="366943240">
<name>Aet Shelby</name>
<description><![CDATA[<table width = "250px" style="font-size:10px;"<tr><td align="left">Vessel Name</td><td align="right">AET SHELBY</td></tr></table>]]></description>
<Point>
<coordinates>-94.78686,29.3203483333333,0</coordinates>
</Point>
<Style>
<IconStyle>
<color>ffffffff</color>
<heading>511</heading>
<Icon>
<href><![CDATA[http://XX.XX.XX.XX/Icons/Moored/MPR_Moored.png]]></href>
</Icon>
</IconStyle>
<BalloonStyle>
<bgColor>ff000000</bgColor>
<textColor>ffffffff</textColor>
<text><![CDATA[$[description]]]></text>
</BalloonStyle>
</Style>
</Placemark>
</Document>
</kml>
【问题讨论】:
标签: openlayers kml