【问题标题】:How can I use Google Maps API to import KML and click on polygons?如何使用 Google Maps API 导入 KML 并单击多边形?
【发布时间】:2011-03-31 17:22:31
【问题描述】:

基本上我有一个 KML 文件,其中有大量的多边形要绘制出来。我需要这些多边形是可点击的,我将在其中执行 ajax 响应。

不过,我很迷茫。有人可以指出我正确的方向吗? :)

【问题讨论】:

    标签: google-maps-api-3 kml


    【解决方案1】:

    查看 Google 地图文档引用的多边形数组示例。它展示了如何绘制多边形,以及如何响应对此类多边形的点击。

    查看示例:

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

    查看其背后的源代码:

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

    【讨论】:

    • 这很酷且易于理解。我可以集成一个 KML 文件来生成这些多边形,然后添加这样的事件吗?
    【解决方案2】:
    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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-05
      • 1970-01-01
      • 2016-01-02
      • 2012-10-14
      • 2021-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多