1 //= require @openstreetmap/id/dist/iD.js
2 //= require jquery.throttle-debounce
6 document.addEventListener("DOMContentLoaded", function () {
7 const container = document.getElementById("id-container");
9 if (typeof iD === "undefined" || !iD.utilDetect().support) {
10 container.innerHTML = "This editor is supported " +
11 "in Firefox, Chrome, Safari, Opera and Edge. " +
12 "Please upgrade your browser or use JOSM to edit the map.";
13 container.className = "unsupported";
15 const idContext = iD.coreContext();
16 idContext.connection().apiConnections([]);
17 const url = location.protocol + "//" + location.host;
20 apiUrl: url.replace("www.openstreetmap.org", "api.openstreetmap.org"),
21 access_token: container.dataset.token
26 .assetPath("@openstreetmap/id/dist/")
27 .assetMap(JSON.parse(container.dataset.assetMap))
28 .locale(container.dataset.locale)
29 .theme(container.dataset.theme)
30 .containerNode(container)
33 if (parent === window) {
34 // iD not opened in an iframe -> skip setting of parent handlers
38 function postMessageToParent(type, data) {
39 parent.postMessage({ type, data }, location.origin);
42 id.map().on("move.embed", window.Cowboy.throttle(250, function () {
43 if (id.inIntro()) return;
44 const zoom = ~~id.map().zoom(),
45 center = id.map().center(),
46 llz = { lon: center[0], lat: center[1], zoom: zoom };
48 postMessageToParent("hashchange", llz);
51 window.addEventListener("message", function (event) {
52 if (event.source !== parent || event.origin !== location.origin) return;
53 const msg = event.data;
54 if (!msg || msg.type !== "hashchange") return;
55 const data = msg.data;
56 // 0ms timeout to avoid iframe JS context weirdness.
57 // https://gist.github.com/jfirebaugh/5439412
58 setTimeout(function () {
61 Math.max(data.zoom || 15, 13));
65 new MutationObserver(() =>
66 postMessageToParent("titlechange", document.title)
67 ).observe(document.querySelector("title"), { childList: true, subtree: true, characterData: true });