问题描述
我有一张地图,上面标有源自 kml 文件的图标。 kml文件是:
- name: execute first task
shell: /tmp/somescript
register: myResult
- name: another shell script
shell: /tmp/anotherscript
when: "happy" in myResult.
<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Dove.kml</name>
<Style id="Dove6">
<IconStyle id="DoveRIconStyle">
<Icon>
<href>https://wcsb.nz/wellringers/dove6.bmp</href>
</Icon>
</IconStyle>
<LabelStyle>
<color>9fffffff</color>
<scale>0.67</scale>
</LabelStyle>
</Style>
<Placemark>
<name>Ab Kettleby</name>
<styleUrl>#Dove6</styleUrl>
<Point>
<coordinates>-0.92747,52.79858</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Asfordby,Leics,6,12cwt,Mon</name>
<styleUrl>#Dove6</styleUrl>
<Point>
<coordinates>-0.95214,52.76339,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
遗憾的是,当我单击该图标时没有任何反应。 该页面位于 https://wcsb.nz/wellringers/kmltest.html。 感激地收到任何帮助。
解决方法
我可以看到您在点击事件处理程序中使用了 ev.target.getPosition()
。您要使用的函数是 evt.target.getGeometry()
。
所以你的代码片段看起来像这样。
kml.getProvider().addEventListener('tap',function (ev) {
if (ev.target instanceof H.map.Marker) {
const info = ev.target.getData();
let content = '<b>' + info.name + '</b><br/>';
let bubble = new H.ui.InfoBubble(ev.target.getGeometry(),{
content: content
});
ui.addBubble(bubble);
}
});