مقدمة
التراكبات هي عناصر على الخريطة مرتبطة بإحداثيات خطوط العرض/الطول، لذا تتحرك عند سحب الخريطة أو تكبيرها أو تصغيرها. إذا أردت وضع صورة على خريطة، يمكنك استخدام عنصر
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); }