]> git.openstreetmap.org Git - rails.git/blob - app/views/site/id.html.erb
Merge remote-tracking branch 'openstreetmap/pull/1375'
[rails.git] / app / views / site / id.html.erb
1 <!DOCTYPE html>
2 <html>
3 <head>
4   <meta charset='utf-8'>
5   <%= stylesheet_link_tag 'id' %>
6   <!--[if !IE || gte IE 9]><!-->
7   <%= javascript_include_tag 'id' %>
8   <!-- <![endif]-->
9 </head>
10 <body>
11 <div id='id-container'></div>
12 <script>
13   if (typeof iD == 'undefined' || !iD.Detect().support) {
14     document.getElementById('id-container').innerHTML = 'This editor is supported ' +
15       'in Firefox, Chrome, Safari, Opera, Edge, and Internet Explorer 11. ' +
16       'Please upgrade your browser or use Potlatch 2 to edit the map.';
17     document.getElementById('id-container').className = 'unsupported';
18   } else {
19     <% locale = ID::LOCALES.preferred(preferred_languages).to_s %>
20
21     var id = iD.Context()
22       .embed(true)
23       .assetPath("iD/")
24       .assetMap(<%= assets("iD").to_json.html_safe %>)
25       .locale("<%= locale %>", "<%= asset_path("iD/locales/#{locale}.json") %>")
26       .preauth({
27         <% token = @user.access_token(ID_KEY) %>
28         urlroot: "<%= request.protocol + request.host_with_port %>",
29         oauth_consumer_key: "<%= token.client_application.key %>",
30         oauth_secret: "<%= token.client_application.secret %>",
31         oauth_token: "<%= token.token %>",
32         oauth_token_secret: "<%= token.secret %>"
33       });
34
35     id.map().on('move.embed', parent.$.throttle(250, function() {
36       if (id.inIntro()) return;
37       var zoom = ~~id.map().zoom(),
38         center = id.map().center(),
39         llz = { lon: center[0], lat: center[1], zoom: zoom };
40
41       parent.updateLinks(llz, zoom);
42
43       // Manually resolve URL to avoid iframe JS context weirdness.
44       // http://bl.ocks.org/jfirebaugh/5439412
45       var hash = parent.OSM.formatHash(llz);
46       if (hash !== parent.location.hash) {
47         parent.location.replace(parent.location.href.replace(/(#.*|$)/, hash));
48       }
49     }));
50
51     parent.$("body").on("click", "a.set_position", function (e) {
52       e.preventDefault();
53       var data = parent.$(this).data();
54
55       // 0ms timeout to avoid iframe JS context weirdness.
56       // http://bl.ocks.org/jfirebaugh/5439412
57       setTimeout(function() {
58         id.map().centerZoom(
59           [data.lon, data.lat],
60           Math.max(data.zoom || 15, 13));
61       }, 0);
62     });
63
64     id.ui()(document.getElementById("id-container"));
65   }
66 </script>
67 </body>
68 </html>