简体   繁体   English

Google Maps API 中特定于国家/地区的缩放级别

[英]Country specific zoom level in Google Maps API

I'm trying to make a Google Map that only shows the Netherlands.我正在尝试制作仅显示荷兰的 Google 地图。 But when I use zoom level 6 it shows Belgium and Germany as well and when I use zoom level 7 it zooms too far in that it doesn't show the complete country.但是,当我使用缩放级别 6 时,它也会显示比利时和德国,而当我使用缩放级别 7 时,它会放大得太远,因为它没有显示完整的国家/地区。

How can I make The Netherlands show only, and not germany and belgium (or at least a very tiny part of them).我怎样才能只展示荷兰,而不展示德国和比利时(或者至少是其中很小的一部分)。

Currently it looks something like this:目前它看起来像这样:

在此处输入图片说明

  1. go to http://www.gadm.org/download , download the adm0 file for the Netherlands转到http://www.gadm.org/download ,下载荷兰adm0 文件

  2. Combine that polygon (as the inner ring(s)) with a polygon that covers the whole earth将该多边形(作为内环)与覆盖整个地球的多边形组合在一起

  3. use the winding reversal tool to reverse any inner polygons that don't wind opposite the outer ring.使用缠绕反转工具反转任何不缠绕在外环对面的内部多边形。

  4. zip up the resulting kml, rename to kmz.压缩生成的kml,重命名为kmz。 Display on the map using geoxml3使用geoxml3在地图上显示

Code:代码:

function initialize() {
    var map = new google.maps.Map(
    document.getElementById("map_canvas"), {
        center: new google.maps.LatLng(85.4419, -122.1419),
        zoom: 13,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });
    var geocoder = new google.maps.Geocoder();
    var geoXml = new geoXML3.parser({
                    map: map,
                    zoom: false, 
                 });
    geoXml.parse("http://www.geocodezip.com/geoxml3_test/kmz/nld_adm0_inverted.kmz");
    google.maps.event.addListener(geoXml,'parsed', function() {
      geocoder.geocode( { 'address': "Netherlands"}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          map.fitBounds(results[0].geometry.viewport);
        } else {
          alert("Geocode was not successful for the following reason: " + status);
        }
      });    
    })
}
google.maps.event.addDomListener(window, "load", initialize);

Working example 工作示例

地图示例

To restrict it to be always displayed on the map see this page from Mike Williams' v2 tutorial要限制它始终显示在地图上,请参阅Mike Williams 的 v2 教程中的此页面

working example 工作示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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