-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmap.js
42 lines (39 loc) · 1.32 KB
/
map.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const html = `
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
<script id="l" src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<div id="map" style="width: 100%; height: 300px;"></div>
<script>
document.getElementById("l").addEventListener("load", () => {
const map = L.map("map").setView([0, 0], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
const marker = L.marker();
const cb = (block) => {
if (block && block.property && block.property.default && block.property.default.location) {
const latlng = [
block.property.default.location.lat,
block.property.default.location.lng
];
map.setView(latlng);
marker.setLatLng(latlng).addTo(map);
} else {
marker.remove();
}
parent.postMessage("updated", "*");
};
addEventListener("message", e => {
if (e.source !== parent) return;
cb(e.data);
});
cb(${JSON.stringify(reearth.block)});
});
</script>
`;
reearth.ui.show(html);
reearth.on("update", () => {
reearth.ui.postMessage(reearth.block);
});
reearth.on("message", msg => {
console.log("message received:", msg);
});