详细程度调整(Google Maps API)

时间:2013-03-03 02:04:25

标签: google-maps google-maps-api-3

是否有可能在不同的缩放级别上更改地图上显示的名称(标签)/边界的方式?

例如我有17个缩放级别。我想开始只在缩放级别10上显示详细信息(国家/地区名称)。

换句话说:地图上的细节水平如何与缩放级别相关联以及如何调整它?

1 个答案:

答案 0 :(得分:4)

function show_map(lat, lng) {
    var labelsOff = [{
        featureType: "administrative",
        elementType: "labels",
        stylers: [{
            visibility: "off"
        }]
    }, {
        featureType: "poi",
        elementType: "labels",
        stylers: [{
            visibility: "off"
        }]
    }, {
        featureType: "water",
        elementType: "labels",
        stylers: [{
            visibility: "off"
        }]
    }, {
        featureType: "road",
        elementType: "labels",
        stylers: [{
            visibility: "off"
        }]
    }];

    var labelsOn = [{
        featureType: "administrative",
        elementType: "labels",
        stylers: [{
            visibility: "on"
        }]
    }, {
        featureType: "poi",
        elementType: "labels",
        stylers: [{
            visibility: "on"
        }]
    }, {
        featureType: "water",
        elementType: "labels",
        stylers: [{
            visibility: "on"
        }]
    }, {
        featureType: "road",
        elementType: "labels",
        stylers: [{
            visibility: "on"
        }]
    }];

    latlng = new google.maps.LatLng(51.477391, -0.000853);
    myOptions = {
        zoom: 3,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map"), myOptions);
    map.setOptions({
        styles: labelsOff
    });

    google.maps.event.addListener(map, 'zoom_changed', function () {
        google.maps.event.addListenerOnce(map, 'tilesloaded', function () {
            if (map.getZoom() >= 10) {
                map.setOptions({
                    styles: labelsOn
                });
            } else {
                map.setOptions({
                    styles: labelsOff
                });
            }
        });
    });

}


show_map();

希望这就是你要找的东西。显然,您可以编辑这些要素类型以隐藏不同的内容。

抱歉,不得不编辑。忘了the fiddle