A popover
แสดงเนื้อหา (โดยปกติจะเป็นข้อความหรือรูปภาพ) ในหน้าต่างโต้ตอบเหนือแผนที่ ณ ตำแหน่งที่กำหนด
ป๊อปโอเวอร์มีพื้นที่เนื้อหาและก้านเรียว ส่วนปลายของก้านจะติดอยู่กับตำแหน่งที่ระบุบนแผนที่ ป๊อปโอเวอร์จะปรากฏเป็นหน้าต่างโต้ตอบในโปรแกรมอ่านหน้าจอ
โดยปกติแล้วคุณจะแนบป๊อปโอเวอร์กับเครื่องหมายแบบโต้ตอบ แต่คุณยังแนบป๊อปโอเวอร์กับพิกัด LatLngAltitude ที่เฉพาะเจาะจง หรือ
ชดเชย
จากเครื่องหมายได้ด้วย
เพิ่มป๊อปโอเวอร์
ตัวสร้าง
PopoverElement
จะใช้ออบเจ็กต์ลิเทอรัล
PopoverElementOptions
ซึ่งระบุพารามิเตอร์เริ่มต้นสำหรับการแสดง
ป๊อปโอเวอร์
ออบเจ็กต์ลิเทอรัล PopoverElementOptions มีช่องต่อไปนี้
positionAnchor: ตำแหน่งLatLngAltitudeที่จะแสดงเครื่องหมาย หากใช้เครื่องหมาย ระบบจะใช้ตำแหน่งของเครื่องหมายแทนaltitudeMode: วิธีตีความความสูงของป๊อปโอเวอร์lightDismissDisabled: ระบุว่าป๊อปโอเวอร์จะเปิดอยู่เมื่อผู้ใช้คลิกภายนอกป๊อปโอเวอร์หรือกดปุ่มEscหรือไม่ เมื่อตั้งค่าตัวเลือกนี้เป็นtrueคุณจะแสดงป๊อปโอเวอร์lightDismissDisabledหลายรายการบนแผนที่พร้อมกันได้open: กำหนดว่าป๊อปโอเวอร์ควรเปิดอยู่หรือไม่ ค่าเริ่มต้นคือfalse
เนื้อหาของ PopoverElement อาจมีสตริงข้อความ ข้อมูลโค้ด HTML หรือองค์ประกอบ DOM คุณตั้งค่าเนื้อหาโดยผนวกเนื้อหาเข้ากับ PopoverElement อย่างชัดเจนในช่อง header หรือ default
หากต้องการกำหนดขนาดเนื้อหาอย่างชัดเจน คุณสามารถใส่เนื้อหาในองค์ประกอบ <div> element
และจัดรูปแบบ <div> ด้วย CSS ป๊อปโอเวอร์เลื่อนได้โดยค่าเริ่มต้นและมีความสูงสูงสุดที่กำหนดไว้ล่วงหน้า
ยึดป๊อปโอเวอร์กับพิกัด LatLngAltitude
เมื่อสร้างป๊อปโอเวอร์ ระบบจะไม่แสดงป๊อปโอเวอร์บนแผนที่โดยอัตโนมัติ หากต้องการให้ป๊อปโอเวอร์ปรากฏ คุณต้องตั้งค่าตัวเลือก open เป็น true ใน PopoverElement คุณสามารถดำเนินการนี้ได้ในระหว่างการสร้างหรือหลังจากการสร้างอินสแตนซ์
async function init() { const { Map3DElement, PopoverElement } = await google.maps.importLibrary('maps3d'); const map = new Map3DElement({ center: { lat: 37.8204, lng: -122.4783, altitude: 0.407 }, range: 4000, tilt: 74, heading: 38, mode: 'HYBRID', gestureHandling: 'COOPERATIVE', }); const popover = new PopoverElement({ altitudeMode: 'ABSOLUTE', open: true, positionAnchor: { lat: 37.819852, lng: -122.478549, altitude: 150 }, }); popover.append('Golden Gate Bridge'); map.append(popover); document.body.append(map); } void init();
ยึดป๊อปโอเวอร์กับเครื่องหมาย
คุณสามารถยึดป๊อปโอเวอร์กับเครื่องหมายได้ เมื่อเพิ่มป๊อปโอเวอร์ที่ยึดกับเครื่องหมาย ให้ตั้งค่าตัวเลือก PopoverElement.positionAnchor เพื่อใช้เครื่องหมาย
async function init() { const { Map3DElement, Marker3DInteractiveElement, PopoverElement } = await google.maps.importLibrary('maps3d'); const map = new Map3DElement({ center: { lat: 37.8204, lng: -122.4783, altitude: 0.407 }, range: 4000, tilt: 74, heading: 38, mode: 'HYBRID', gestureHandling: 'COOPERATIVE', }); // Popovers can only be added to interactive Markers const interactiveMarker = new Marker3DInteractiveElement({ altitudeMode: 'ABSOLUTE', position: { lat: 37.819852, lng: -122.478549, altitude: 100 }, }); const popover = new PopoverElement({ open: false, positionAnchor: interactiveMarker, }); popover.append('Golden Gate Bridge'); interactiveMarker.addEventListener('gmp-click', () => { // toggle the marker to the other state (unlee you are clicking on the marker itself when it reopens it) popover.open = !popover.open; }); map.append(interactiveMarker); map.append(popover); document.body.append(map); } void init();
ยึดป๊อปโอเวอร์กับเครื่องหมายโดยใช้ HTML
คุณยังยึดป๊อปโอเวอร์กับเครื่องหมายได้โดยไม่ต้องเขียนโค้ด JavaScript ดังที่แสดงด้านล่าง
<gmp-map-3d mode="hybrid" center="37.819852,-122.478549" tilt="75" range="2000" heading="330">
<gmp-marker-3d-interactive gmp-popover-target="my-popover" position="37.819852,-122.478549,100"></gmp-marker-3d-interactive>
<gmp-popover id="my-popover">
Golden Gate Bridge
</gmp-popover>
</gmp-map-3d>
<script async src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDGl0teQ6qwaBEdHazOWIEXd8XGWOZvoaM&v=beta&libraries=maps3d">
</script>
เพิ่มเนื้อหาที่กำหนดเองลงในป๊อปโอเวอร์
คุณสามารถเพิ่มเนื้อหาที่กำหนดเองลงในป๊อปโอเวอร์ได้โดยตั้งค่าตัวเลือก header และ content ดังนี้
async function init() {
const {Map3DElement, MapMode, PopoverElement, AltitudeMode} = await google.maps.importLibrary('maps3d');
const map = new Map3DElement({
center: { lat: 37.819852, lng: -122.478549, altitude: 2000 },
tilt: 75,
heading: 330,
mode: MapMode.SATELLITE,
});
const popover = new PopoverElement({
altitudeMode: AltitudeMode.ABSOLUTE,
open: true,
positionAnchor: {lat: 37.819852, lng: -122.478549, altitude: 100},
});
const header = document.createElement('div');
header.style.fontWeight = 'bold';
header.slot = 'header';
header.textContent = 'Golden Gate Bridge';
const content = document.createElement('div');
content.textContent = 'Iconic orange bridge connecting San Francisco to Marin.';
popover.append(header);
popover.append(content);
document.body.append(map);
map.append(popover);
}
init();