开发者

Removing all controls from a google map

开发者 https://www.devze.com 2023-03-12 03:09 出处:网络
I am trying to remove all the controls (zoom, map type drop down, and street view) 开发者_如何学Gofrom my map.

I am trying to remove all the controls (zoom, map type drop down, and street view) 开发者_如何学Gofrom my map.

There's a method

map.removeControl(GControl)

but I haven't been able to successfully remove any default ones that I hadn't added myself.

Any tips on remove/clearing all controls from the map?


Have you tried this:

http://code.google.com/apis/maps/documentation/javascript/controls.html#DisablingDefaults

function initialize() {
  var myOptions = {
    zoom: 4,
    center: new google.maps.LatLng(-33, 151),
    disableDefaultUI: true,
    mapTypeId: google.maps.MapTypeId.ROADMAP  
  }
  var map = new google.maps.Map(document.getElementById("map_canvas"),
       myOptions);
}


You may see this: google map api by w3schools

As you see in the link, this disables all controls:

var mapOptions = {disableDefaultUI: true}

and the bellow is the options to make them enabled or disabled.

var mapOptions = {
  panControl: true,
  zoomControl: true,
  mapTypeControl: true,
  scaleControl: true,
  streetViewControl: true,
  overviewMapControl: true,
  rotateControl: true
}


just disableDefaultUI: true

function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 4,
    center: {lat: -33, lng: 151},
    disableDefaultUI: true
  });
}


I believe you can create a copy of the GMapUIOptions object and then remove the items you don't want to appear.

From http://code.google.com/apis/maps/documentation/javascript/v2/controls.html#MapUIOptions

"Using the GMapUIOptions Object

The GMapUIOptions object contains a set of properties that specify control placement and UI behavior, which you may modify. For a full set of properties, see the GMapUIOptions reference. Rather than write a GMapUIOptions structure from scratch, you may wish to prepopulate it with the UI behavior available on Google Maps. To do so, use the GMap2.getDefaultUI() method. Once populated, you can modify individual properties to tweak the behavior and initialize the map's UI controls using the GMap2.setUI() method. The following code retrieves the default UI on a "large" map, removes the GScaleControl and resets the map to use the modified UI.

map = new GMap2(document.getElementById("map_canvas"),
    { size: new GSize(400,150) } );
map.setCenter(new GLatLng(41.897997,-87.790203), 11);
var customUI = map.getDefaultUI();
customUI.controls.scalecontrol = false;
map.setUI(customUI);

"

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号