如何隐藏菲利普斯风格地图中的标签?

时间:2015-12-02 23:25:07

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

菲利普斯在地图上的观点有问题:

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"
                   }
               ]
           }
       ];

一切都很好,除了菲利普斯有奇怪的"头衔"在上面。我没有任何想法......

1 个答案:

答案 0 :(得分:2)

我看到“Spratty 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>