开发者

How can I use Google Maps API to import KML and click on polygons?

Basically I开发者_JS百科 have a KML file that has a TON of polygons to be mapped out. I need those polygons to be clickable in which I'd perform an ajax response.

I'm pretty lost, though. Can someone point me in the right direction? :)


Check out the polygon-array example that the Google Maps documentation refers to. It shows how to draw polygons, and how to respond to clicks on such polygons.

To view the example:

http://code.google.com/apis/maps/documentation/javascript/examples/polygon-arrays.html

To view the source-code behind it:

view-source:http://code.google.com/apis/maps/documentation/javascript/examples/polygon-arrays.html


function initialize() {

    var mapOptions = {
        zoom: 5,
        center: new google.maps.LatLng(41.376259, 25.055542),
        mapTypeId: google.maps.MapTypeId.TERRAIN
    };

    var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

    var Place = new google.maps.KmlLayer({
        url: 'path-to-kml.kml'
    });

    Place.setMap(map);

    google.maps.event.addListener(Place, 'click', function (event) {
        window.location.href = 'http://example.com'
    });  

}

google.maps.event.addDomListener(window, 'load', initialize);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜