שכבות-על של קרקע

בחירת פלטפורמה: Android iOS JavaScript
  1. מבוא
  2. הוספת שכבת-על של פני השטח
  3. הסרת שכבת-על של פני שטח

מבוא

שכבות-על הן אובייקטים במפה שקשורים לקואורדינטות של קווי רוחב/אורך, ולכן הם זזים כשגוררים את המפה או משנים את מרחק התצוגה. אם רוצים להציב תמונה במפה, אפשר להשתמש באובייקט GroundOverlay.

למידע על סוגים אחרים של שכבות-על, ראו שרטוט על המפה.

הוספת שכבת-על של פני השטח

ה-constructor של 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;
להצגת דוגמה

הסרת שכבת-על של פני שטח

כדי להסיר שכבת-על ממפה, צריך להפעיל את ה-method‏ setMap() של שכבת-העל ולהעביר את הערך null. חשוב לזכור שהפעלת השיטה הזו לא מוחקת את שכבת-העל. היא מסירה את שכבת-העל מהמפה. אם רוצים למחוק את שכבת-העל, צריך להסיר אותה מהמפה ואז להגדיר את שכבת-העל עצמה לערך null.

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

להצגת דוגמה