5 document.addEventListener("DOMContentLoaded", function () {
6 const container = document.getElementById("id-container");
8 if (typeof iD === "undefined" || !iD.utilDetect().support) {
9 container.innerHTML = "This editor is supported " +
10 "in Firefox, Chrome, Safari, Opera and Edge. " +
11 "Please upgrade your browser or use JOSM to edit the map.";
12 container.className = "unsupported";
14 const idContext = iD.coreContext();
15 idContext.connection().apiConnections([]);
16 const url = location.protocol + "//" + location.host;
19 apiUrl: url.replace("www.openstreetmap.org", "api.openstreetmap.org"),
20 access_token: container.dataset.token
26 .assetMap(JSON.parse(container.dataset.assetMap))
27 .locale(container.dataset.locale)
28 .theme(container.dataset.theme)
29 .containerNode(container)
32 if (parent === window) {
33 // iD not opened in an iframe -> skip setting of parent handlers
37 let hashChangedAutomatically = false;
38 id.map().on("move.embed", parent.$.throttle(250, function () {
39 if (id.inIntro()) return;
40 const zoom = ~~id.map().zoom(),
41 center = id.map().center(),
42 llz = { lon: center[0], lat: center[1], zoom: zoom };
44 parent.updateLinks(llz, zoom);
46 // Manually resolve URL to avoid iframe JS context weirdness.
47 // https://gist.github.com/jfirebaugh/5439412
48 const hash = parent.OSM.formatHash(llz);
49 if (hash !== parent.location.hash) {
50 hashChangedAutomatically = true;
51 parent.location.replace(parent.location.href.replace(/(#.*|$)/, hash));
55 function goToLocation(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 parent.$("body").on("click", "a.set_position", function (e) {
67 const data = parent.$(this).data();
71 parent.addEventListener("hashchange", function (e) {
72 if (hashChangedAutomatically) {
73 hashChangedAutomatically = false;
77 const data = parent.OSM.mapParams();
81 const projectTitle = parent.document.title;
82 new MutationObserver(() =>
83 parent.document.title = [document.title, projectTitle].filter(t => t).join(" | ")
84 ).observe(document.querySelector("title"), { childList: true, subtree: true, characterData: true });