地面オーバーレイ

プラットフォームを選択: Android iOS JavaScript
  1. はじめに
  2. 地面オーバーレイの追加
  3. 地面オーバーレイの除去

はじめに

オーバーレイは緯度と経度で表される座標に紐付いた地図上のオブジェクトで、地図をドラッグしたりズームしたりすると連動して動きます。地図上に配置したい画像がある場合は GroundOverlay オブジェクトを使用します。

オーバーレイのその他のタイプについては、地図上での描画をご覧ください。

地面オーバーレイの追加

GroundOverlay のコンストラクタは、画像の URL と画像の LatLngBounds をパラメータとして指定します。地図上に画像がレンダリングされます。その際、指定の領域に制約され、地図の投影法を使用して適合が行われます。

TypeScript

// This example uses a GroundOverlay to place an image on the map // showing an antique map of Newark, NJ.  let historicalOverlay;  function initMap(): void {   const map = new google.maps.Map(     document.getElementById("map") as HTMLElement,     {       zoom: 13,       center: { lat: 40.74, lng: -74.18 },     }   );    const imageBounds = {     north: 40.773941,     south: 40.712216,     east: -74.12544,     west: -74.22655,   };    historicalOverlay = new google.maps.GroundOverlay(     "https://storage.googleapis.com/geo-devrel-public-buckets/newark_nj_1922-661x516.jpeg",     imageBounds   );   historicalOverlay.setMap(map); }  declare global {   interface Window {     initMap: () => void;   } } window.initMap = initMap;

JavaScript

// This example uses a GroundOverlay to place an image on the map // showing an antique map of Newark, NJ. let historicalOverlay;  function initMap() {   const map = new google.maps.Map(document.getElementById("map"), {     zoom: 13,     center: { lat: 40.74, lng: -74.18 },   });   const imageBounds = {     north: 40.773941,     south: 40.712216,     east: -74.12544,     west: -74.22655,   };    historicalOverlay = new google.maps.GroundOverlay(     "https://storage.googleapis.com/geo-devrel-public-buckets/newark_nj_1922-661x516.jpeg",     imageBounds,   );   historicalOverlay.setMap(map); }  window.initMap = initMap;
サンプルを表示

サンプルを試す

地面オーバーレイの除去

オーバーレイを地図から除去するには、オーバーレイの setMap() メソッドを呼び出して null を渡します。このメソッドを呼び出してもオーバーレイは削除されないことに注意してください。地図からオーバーレイが除去されるだけです。オーバーレイを削除するには、地図から除去した後、オーバーレイそのものを null に設定してください。

function removeOverlay() {   historicalOverlay.setMap(null); }

サンプルを表示