简体   繁体   中英

Get latitude and longitude of mouse click in KML plotted using geoxml3

Is there any way to get the right click event on a parsed KML layer using geoxml3 on google map.I am getting the right click event of map ie outer region of KML. But i am not able to get the click event on the parsed KML.

I have used like this

 var geoXml = new geoXML3.parser({
                        map: map           
                    });

    geoXml.parse('file.kml');

geoxml3 parses the KML to native Google Maps Javascript API v3 objects. To add a right click events to them, you need to either add custom createMarker, createPolyline, createPolygon functions that add the right click listeners as the objects are created or process the results and add the listeners to the output.

The following was helpful and got the latitude and longitude when right clicked on a KML layer in google map

var geoXml = new geoXML3.parser({
                    map: map,
                    afterParse: function (doc) {
                        for (var i = 0; i < doc[0].placemarks.length; i++) {
                            var p = doc[0].placemarks[i];
                            clickablePolygon(p);
                        }
                    }        
                });

geoXml.parse(parameter.FileName);

function clickablePolygon(p) {
            google.maps.event.addListener(
            p.polygon,
            "rightclick",
            function (event) {
                var clickedLocation = event.latLng;
                var latlng = {
                    lat: clickedLocation.lat(),
                    lng: clickedLocation.lng(),
                    zlevel: map.getZoom()
                };
            }
            );
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM