]> git.openstreetmap.org Git - rails.git/blob - app/views/site/id.html.erb
Refactor search JS
[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') {
14     document.getElementById('id-container').innerHTML = 'This editor is supported ' +
15       'in Firefox, Chrome, Safari, Opera, and Internet Explorer 9 and above. ' +
16       'Please upgrade your browser or use Potlatch 2 to edit the map.';
17     document.getElementById('id-container').className = 'unsupported';
18   } else {
19     <% locale = select_locale(ID::LOCALES).to_s %>
20
21     var id = iD()
22       .embed(true)
23       .assetPath("/assets/iD/") <%# Can't use asset_path('iD/') in production. %>
24       .locale("<%= locale %>", "<%= asset_path("iD/locales/#{locale}.json") %>")
25       .preauth({
26         <% token = @user.access_token(ID_KEY) %>
27         url: "<%= request.protocol + request.host_with_port %>",
28         oauth_consumer_key: "<%= token.client_application.key %>",
29         oauth_secret: "<%= token.client_application.secret %>",
30         oauth_token: "<%= token.token %>",
31         oauth_token_secret: "<%= token.secret %>"
32       });
33
34     id.map().on('move.embed', parent.$.throttle(250, function() {
35       var extent = id.map().extent(),
36           zoom = ~~id.map().zoom(),
37           center = id.map().center();
38
39       parent.updatelinks({
40           lon: center[0],
41           lat: center[1]
42         },
43         zoom,
44         null,
45         [[extent[0][1],
46         extent[0][0]],
47         [extent[1][1],
48         extent[1][0]]]);
49
50       // 0ms timeout to avoid iframe JS context weirdness.
51       // http://bl.ocks.org/jfirebaugh/5439412
52       parent.setTimeout(function() {
53         var hash = parent.OSM.formatHash({ lon: center[0], lat: center[1], zoom: zoom });
54         if (hash !== parent.location.hash) {
55           parent.location.replace(hash);
56         }
57       }, 0);
58     }));
59
60     parent.$("body").on("click", "a.set_position", function (e) {
61       e.preventDefault();
62       var data = parent.$(this).data();
63
64       // 0ms timeout to avoid iframe JS context weirdness.
65       // http://bl.ocks.org/jfirebaugh/5439412
66       parent.setTimeout(function() {
67         id.map().centerZoom(
68           [data.lon, data.lat],
69           Math.max(data.zoom || 15, 13));
70       }, 0);
71     });
72
73     var maximized = false;
74     id.on('toggleFullscreen.embed', function() {
75       if (maximized) {
76         parent.minimiseMap();
77       } else {
78         parent.maximiseMap();
79       }
80       maximized = !maximized;
81     });
82
83     d3.select('#id-container')
84       .call(id.ui());
85   }
86 </script>
87 </body>
88 </html>