2015-10-21 69 views

回答

2

要素類型transit.lines可能是你在找什麼地圖功能。

https://developers.google.com/maps/documentation/javascript/reference?hl=en#MapTypeStyleFeatureType

但它包含了比僅鐵路線(我想,地鐵,船舶等),但仍可能會根據你正在嘗試做幫助更多...

JSFiddle demo

function initialize() { 
 

 
    // Create an array of styles. 
 
    var styles = [{ 
 
     "stylers": [{ 
 
      "saturation": -100 
 
     }] 
 
    }, { 
 
     "featureType": "transit.line", 
 
      "stylers": [{ 
 
      "saturation": 100 
 
     }, { 
 
      "color": "#ff3183" 
 
     }] 
 
    }]; 
 

 
    // Create a new StyledMapType object, passing it the array of styles, as well as the name to be displayed on the map type control. 
 
    var styledMap = new google.maps.StyledMapType(styles, { 
 
     name: "Styled Map" 
 
    }); 
 

 
    // Create a map object, and include the MapTypeId to add to the map type control. 
 
    var mapOptions = { 
 
     zoom: 13, 
 
     center: new google.maps.LatLng(40.7288, -74.1509), 
 
     mapTypeControlOptions: { 
 
      mapTypeIds: [google.maps.MapTypeId.TERRAIN, 'map_style'] 
 
     } 
 
    }; 
 

 
    var map = new google.maps.Map(document.getElementById('map-canvas'), 
 
    mapOptions); 
 

 
    // Associate the styled map with the MapTypeId and set it to display. 
 
    map.mapTypes.set('map_style', styledMap); 
 
    map.setMapTypeId('map_style'); 
 
} 
 

 
initialize();
#map-canvas { 
 
    height: 400px; 
 
}
<script src="//maps.google.com/maps/api/js?sensor=false"></script> 
 
<div id="map-canvas"></div>

相關問題