]> git.openstreetmap.org Git - rails.git/blob - app/views/site/id_iframe.html.erb
Support maximize/minimize (systemed/iD#1327)
[rails.git] / app / views / site / id_iframe.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     var id = iD()
20       .embed(true)
21       .assetPath("/assets/iD/") <%# Can't use asset_path('iD/') in production. %>
22       .preauth({
23         <% token = @user.access_token(ID_KEY) %>
24         url: "<%= request.protocol + request.host_with_port %>",
25         oauth_consumer_key: "<%= token.client_application.key %>",
26         oauth_secret: "<%= token.client_application.secret %>",
27         oauth_token: "<%= token.token %>",
28         oauth_token_secret: "<%= token.secret %>"
29       });
30
31     id.map().on('move.embed', function() {
32       var extent = id.map().extent(),
33           zoom = ~~id.map().zoom(),
34           center = id.map().center();
35
36       parent.updatelinks(
37         center[0],
38         center[1],
39         zoom,
40         null,
41         extent[0][0],
42         extent[0][1],
43         extent[1][0],
44         extent[1][1]);
45     });
46
47     parent.$("body").on("click", "a.set_position", function (e) {
48       e.preventDefault();
49       var data = parent.$(this).data();
50       id.map().centerZoom(
51         [data.lon, data.lat],
52         Math.max(data.zoom || 15, 13));
53     });
54
55     var maximized = false;
56     id.on('toggleFullscreen.embed', function() {
57       if (maximized) {
58         parent.minimiseMap();
59       } else {
60         parent.maximiseMap();
61       }
62       maximized = !maximized;
63     });
64
65     d3.select('#id-container')
66       .call(id.ui());
67   }
68 </script>
69 </body>
70 </html>