KML layer does not always respond to clicks [ Google Maps API ]

匿名 (未验证) 提交于 2019-12-03 09:02:45

问题:

I am working on a project .jsp file, that displays 4 kml layers: gas pipes, gas sensors, valves, and areas.

The problem is that I want to extract data from the placemark's description and use it, but when I click the placemark, sometimes it works, other it doesn't. And I simply can't see why..

I have created a JSFiddle example of my code. I've added 2 kml layers, one for pipes and one for sensors. Each pipe has multiple sensors( or at least one). I added the layers one after the other on metadata change to be sure of layer order consistency. I added 2 click listeners for both layers that extract the description and I process the string and extract what I need, to display in a separate div as text.

Sometimes when I click the sensors or pipes the data is extracted, other times it says it's not found(string undefined). I get the status = "ZERO_RESULTS". According to Google, this may occur if the geocoder was passed a latlng in a remote location. I looked at the log and the latlog has more than 9 numbers after the dot(.), wheras in my kml I only have 6.

But this isn't the problem i guess because sometimes, although the latlng coord are very accurate,( >9 chars after the dot) the placemark is found and the info I need is extracted. It's just hit or miss.

Can someone explain to my why this is happening?

JSFiddle link: http://jsfiddle.net/sxNy9/185/light/

KML files: - https://sites.google.com/site/kmlholdersherb/BrasovLayer_TeziGaz.kml?attredirects=0&d=1 - https://sites.google.com/site/kmlholdersherb/BrasovLayer_Senzori.kml?attredirects=0&d=1

Thanks!

EDITED:

Included the kml layers:

var PIPES= new google.maps.KmlLayer({url: 'URL HERE', preserveViewport:true});  var SENSORS= new google.maps.KmlLayer({url: 'URL HERE', preserveViewport:true }); 

After that I added them to the map.

And now the listeners.

google.maps.event.addListener(SENSORS, 'click', function(kmlEvent) {     var text = kmlEvent.featureData.name;     var str = kmlEvent.featureData.description;      //FIND OUT THE STREET     var x = str.indexOf(".");     var y = str.indexOf(":");     var street= str.substring(y+2,x);       //ID     var a = str.indexOf("#");     var ID = str.substring(a+1,str.length);      var finaltext = street+ " " + ID;      showInContentWindow(finaltext); // adding the string into html ( aka the result) }); 

And then another listener for PIPES, which is identical.

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