]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/id.js
Add CyclOSM layer
[rails.git] / app / assets / javascripts / id.js
1 //= require iD
2
3 /* globals iD */
4
5 document.addEventListener("DOMContentLoaded", function () {
6   var container = document.getElementById("id-container");
7
8   if (typeof iD === "undefined" || !iD.utilDetect().support) {
9     container.innerHTML = "This editor is supported " +
10       "in Firefox, Chrome, Safari, Opera, Edge, and Internet Explorer 11. " +
11       "Please upgrade your browser or use Potlatch 2 to edit the map.";
12     container.className = "unsupported";
13   } else {
14     var id = iD.coreContext()
15       .embed(true)
16       .assetPath("iD/")
17       .assetMap(JSON.parse(container.dataset.assetMap))
18       .locale(container.dataset.locale)
19       .preauth({
20         urlroot: location.protocol + "//" + location.host,
21         oauth_consumer_key: container.dataset.consumerKey,
22         oauth_secret: container.dataset.consumerSecret,
23         oauth_token: container.dataset.token,
24         oauth_token_secret: container.dataset.tokenSecret
25       })
26       .containerNode(container)
27       .init();
28
29     id.map().on("move.embed", parent.$.throttle(250, function () {
30       if (id.inIntro()) return;
31       var zoom = ~~id.map().zoom(),
32           center = id.map().center(),
33           llz = { lon: center[0], lat: center[1], zoom: zoom };
34
35       parent.updateLinks(llz, zoom);
36
37       // Manually resolve URL to avoid iframe JS context weirdness.
38       // http://bl.ocks.org/jfirebaugh/5439412
39       var hash = parent.OSM.formatHash(llz);
40       if (hash !== parent.location.hash) {
41         parent.location.replace(parent.location.href.replace(/(#.*|$)/, hash));
42       }
43     }));
44
45     parent.$("body").on("click", "a.set_position", function (e) {
46       e.preventDefault();
47       var data = parent.$(this).data();
48
49       // 0ms timeout to avoid iframe JS context weirdness.
50       // http://bl.ocks.org/jfirebaugh/5439412
51       setTimeout(function () {
52         id.map().centerZoom(
53           [data.lon, data.lat],
54           Math.max(data.zoom || 15, 13));
55       }, 0);
56     });
57   }
58 });