HTML link to location on KML layer

泄露秘密 提交于 2021-01-29 08:10:10

问题


I am trying to add links on my webpage to different locations on my google map. The map is two different kml files, one of the two is displayed to the user based on their zoom level. I have tried the traditional ways to add a link to a location in javascript but the link doesnt work. This is what I have right now:

google.maps.KmlMouseEvent.latlng(bathrooms_link, 'click', function(){
            var bath = new google.maps.LatLng(38.04851723912264, -84.59609386082468);
            });
            map.panTo(bath);

回答1:


You can't access the information in a KmlLayer except by actually clicking on it (with an actual click), if you want to trigger a mouse event like you are, you need to provide all the rest of the information required in the mouse event (featureData, latLng, pixelOffset).

And you need to trigger the click event, not what you are doing.

Something like:

google.maps.event.trigger(layer, "click", {
  latLng: new google.maps.LatLng(38.04851723912264, -84.59609386082468),
  featureData:{},
  pixelOffset: new google.maps.Size(0,0)     
});
map.panTo(bath);

Haven't been able to make that work (and not sure it is worth doing so). Perhaps if your KML isn't very complex, investigate using a third party KML parser like geoxml3 or geoxml-v3, which render the KML using native Google Maps Javascript API v3 objects.



来源:https://stackoverflow.com/questions/22977035/html-link-to-location-on-kml-layer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!