2015-12-02 63 views
3

我有Philipines`s看待問題的地圖:如何隱藏菲律賓風格地圖中的標籤?

enter image description here enter image description here

地圖樣式:

 var styles = [ 
      {"stylers": [{ "visibility": "off" }]}, 
      { 
       "featureType": "administrative", 
       "elementType": "geometry.stroke", 
       "stylers": [ 
        { 
         "visibility": "on" 
        }, 
        { 
         "color": "#ffffff" 
        }, 
        { 
         "weight": 1 
        } 
       ] 
      }, 
      { 
       featureType: "administrative.province", 
       elementType: "geometry", 
       stylers: [ 
        { visibility: "off" } 
       ] 
      }, 
      { 
       featureType: "administrative.country", 
       elementType: "labels", 
       stylers: [ 
        { visibility: "off" } 
       ] 
      }, 
      { 
       "featureType": "landscape", 
       "elementType": "all", 
       "stylers": [ 
        { 
         "visibility": "on" 
        }, 
        { 
         "color": "#a2d39c" 
        } 
       ] 
      }, 
      { 
       "featureType": "water", 
       "elementType": "all", 
       "stylers": [ 
        { 
         "visibility": "on" 
        }, 
        { 
         "color": "#0e76bc" 
        } 
       ] 
      } 
     ]; 

一切都很好,除了菲律賓,上面有奇怪的 「頭銜」。我沒有任何想法......

回答

2

我看到「Spratty Islands」,「Paracel Islands」。您需要關閉:

{ 
    "featureType": "landscape.natural", 
    "elementType": "labels", 
    "stylers": [ 
    { "visibility": "off" } 
    ] 
} 

proof of concept fiddle

代碼片段:

var geocoder; 
 
var map; 
 

 
function initialize() { 
 
    var map = new google.maps.Map(
 
    document.getElementById("map_canvas"), { 
 
     center: new google.maps.LatLng(37.4419, -122.1419), 
 
     zoom: 13, 
 
     mapTypeId: google.maps.MapTypeId.ROADMAP, 
 
     styles: styles 
 
    }); 
 
    geocoder = new google.maps.Geocoder(); 
 
    geocoder.geocode({ 
 
    'address': "Philipines" 
 
    }, function(results, status) { 
 
    if (status === google.maps.GeocoderStatus.OK) { 
 
     map.fitBounds(results[0].geometry.bounds); 
 
    } else { 
 
     alert('Geocode was not successful for the following reason: ' + status); 
 
    } 
 
    }); 
 

 
} 
 
google.maps.event.addDomListener(window, "load", initialize); 
 

 
var styles = [{ 
 
    "stylers": [{ 
 
    "visibility": "off" 
 
    }] 
 
}, { 
 
    "featureType": "administrative", 
 
    "elementType": "geometry.stroke", 
 
    "stylers": [{ 
 
    "visibility": "on" 
 
    }, { 
 
    "color": "#ffffff" 
 
    }, { 
 
    "weight": 1 
 
    }] 
 
}, { 
 
    featureType: "administrative.province", 
 
    elementType: "geometry", 
 
    stylers: [{ 
 
    visibility: "off" 
 
    }] 
 
}, { 
 
    featureType: "administrative.country", 
 
    elementType: "labels", 
 
    stylers: [{ 
 
    visibility: "off" 
 
    }] 
 
}, { 
 
    "featureType": "landscape", 
 
    "elementType": "all", 
 
    "stylers": [{ 
 
    "visibility": "on" 
 
    }, { 
 
    "color": "#a2d39c" 
 
    }] 
 
}, { 
 
    "featureType": "water", 
 
    "elementType": "all", 
 
    "stylers": [{ 
 
    "visibility": "on" 
 
    }, { 
 
    "color": "#0e76bc" 
 
    }] 
 
}, { 
 
    "featureType": "landscape.natural", 
 
    "elementType": "labels", 
 
    "stylers": [{ 
 
    "visibility": "off" 
 
    }] 
 
}];
html, 
 
body, 
 
#map_canvas { 
 
    height: 100%; 
 
    width: 100%; 
 
    margin: 0px; 
 
    padding: 0px 
 
}
<script src="https://maps.googleapis.com/maps/api/js"></script> 
 
<div id="map_canvas"></div>

+0

非常感謝!附:這是不明顯的行爲(對我來說)。 – voodoo417

+1

我同意它沒有很好的記錄。這個哲學似乎是「與巫師一起玩,直到你得到你想要的東西」...... – geocodezip