地面覆寫
介紹
疊加層是地圖上與緯度/經度坐标綁定的對象,是以在您拖動或縮放地圖時它們會移動。如果要在地圖上放置圖像,則可以使用 GroundOverlay對象。
有關其他類型的疊加層的資訊,請參見 在地圖上繪制。
添加地面覆寫
a的構造函數 指定圖檔的URL和圖檔的URL 作為參數。圖像将呈現在地圖上,并限制在給定的範圍内,并使用地圖的投影進行整合。 GroundOverlayLatLngBounds
// This example uses a GroundOverlay to place an image on the map
// showing an antique map of Newark, NJ.
var historicalOverlay;
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 13,
center: {lat: 40.740, lng: -74.18}
});
var imageBounds = {
north: 40.773941,
south: 40.712216,
east: -74.12544,
west: -74.22655
};
historicalOverlay = new google.maps.GroundOverlay(
'https://www.lib.utexas.edu/maps/historical/newark_nj_1922.jpg',
imageBounds);
historicalOverlay.setMap(map);
}
檢視示例。
去除地面覆寫物
要從地圖上删除疊加層,請setMap()通過調用疊加層的 方法null。請注意,調用此方法不會删除覆寫。它隻是從地圖上删除疊加層。相反,如果您希望删除疊加層,則應将其從地圖上删除,然後将疊加層本身設定為null。
function removeOverlay() {
historicalOverlay.setMap(null);