谷歌地图KML图层文件大小限制问题

时间:2016-12-05 10:17:34

标签: javascript google-maps kml

我想使用84MB KML文件在谷歌地图上显示KML图层,但Google地图不支持超过10MB的KML文件。

关于KML呈现的大小和复杂性限制的Google Map Developer链接

https://developers.google.com/maps/documentation/javascript/kmllayer

请检查下面的代码,我用它来显示谷歌地图中的KML图层。它与小KML文件一起工作正常。

<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="initial-scale=1.0">
        <meta charset="utf-8">
        <title>KML Layer</title>
        <style>
            #map {
                height: 80%;
            }
            html, body {
                height: 100%;
                margin: 0;
                padding: 0;
            }
        </style>
    </head>
    <body>
        <div>
            <a href="#" class="button" data-latLng="cta_red.kml">Red Fibre</a><br>
            <a href="#" class="button" data-latLng="cta_green.kml">Green Fibre</a><br>
            <a href="#" class="button" data-latLng="cta_blue.kml">Blue Fibre</a><br>
        </div><br>
        <div id="map"></div>
        <script async defer
                src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAWsZy8xWxT9yNBvYcO1dpxBzDttr7DqLA&sensor=false">
        </script>
        <script src="https://code.jquery.com/jquery-2.2.4.min.js"
  integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="  crossorigin="anonymous"></script>
        <script>
            jQuery(document).ready(function() {
                var defaultu = 'cta.kml';
                initMapp(defaultu);
                jQuery(document).on("click", ".button", function(e) {
                    e.preventDefault();
                    var url = jQuery(this).attr("data-latLng");
                    initMapp(url);
                });

                function initMapp(url) {
                    var myLatLng = {lat: 41.876, lng: -87.624}
                    var map = new google.maps.Map(document.getElementById('map'), {
                        zoom: 17,
                        center: myLatLng
                    });
                    var marker = new google.maps.Marker({
                        position: myLatLng,
                        map: map,
                        title: 'Hello David!'
                    });
                    var kmlurl = url;

                    var ctaLayer = new google.maps.KmlLayer({
                        url: kmlurl,
                        map: map
                    });
                }
            });
        </script>
    </body>
</html>

0 个答案:

没有答案