默认情况下,Google地图地形视图

时间:2011-12-20 17:56:36

标签: javascript google-maps-api-3

我正在试图弄清楚如何将我的谷歌地图嵌入默认为“地形视图”并禁用其他选项,如卫星视图和街景视图。谁能指出我正确的方向?这是我的代码......

以下是目前呈现的方式:http://img842.imageshack.us/img842/7299/screenshot20111220at125.png

var map;
var middle_earth_MORADOR = new google.maps.LatLng(38, 0);

    function initialize() {

        // Define Styles
        var styles = [ 
            {
                //featureType: "all", elementType: "all", stylers: [ { visibility: "on" }, { hue: "#e5f5fb" } ]
            }
        ];


        // Default map options
        var mapOptions = {
            zoom: 2,
            center: middle_earth_MORADOR,
            backgroundColor: "#000"
        };

        var locations = [
            <?php foreach ($Projects as $Project) {             

                $oProjectPhotos = new clsProjectPhotos($Project['idProject']);
                $photos = $oProjectPhotos->getProjectPhotos();
                echo '["'.$Project["Name"].'", '.$Project["gmapslat"].', '.$Project["gmapslng"].', "'.$Project["CountryName"].'"],';
                echo "\n";
                echo "\t\t";
            }
            ?>  
        ];


        map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions);
        var styledMapOptions = {
            map: map,
            name: "map"
        }
        var build =  new google.maps.StyledMapType(styles,styledMapOptions);
        map.mapTypes.set('map', build);
        map.setMapTypeId('map');

        var infowindow = new google.maps.InfoWindow();

        var marker, i;

        for (i = 0; i < locations.length; i++) {  
          marker = new google.maps.Marker({
            position: new google.maps.LatLng(locations[i][1], locations[i][2]),
            map: map
          });

          google.maps.event.addListener(marker, 'mouseover', (function(marker, i) {
            return function() {
              infowindow.setContent(
                '<div>' + locations[i][0] + '</div>'+
                '<div>' + locations[i][4] + '</div>'+
                '<div>' + locations[i][5] + '</div>'+
                '<div>' + locations[i][6] + '</div>'
              );
              infowindow.open(map, marker);
            }

          })(marker, i));
        }

    }

1 个答案:

答案 0 :(得分:3)

您可以指定用户可以选择的地图类型:

  var mapOptions = {
    zoom: 12,
    //center: brooklyn,
    center: new google.maps.LatLng(-23.565, -46.6565),
    mapTypeControlOptions: {
       mapTypeIds: [google.maps.MapTypeId.TERRAIN]
    },
    mapTypeId: google.maps.MapTypeId.TERRAIN
  };

  map = new google.maps.Map(document.getElementById("map_canvas"),
      mapOptions);

其中mapTypeControlOptions是类型控制选项,mapTypeId是默认地图类型。

相关问题