]> git.openstreetmap.org Git - rails.git/blobdiff - app/views/site/id_iframe.html.erb
Load search result locations in iD
[rails.git] / app / views / site / id_iframe.html.erb
index 0422446b34390199cc56711fddbaf3db702ae885..8ca8523d1e05df0cdb7da3213d78253161ac3520 100644 (file)
       'Please upgrade your browser or use Potlatch 2 to edit the map.';
     document.getElementById('id-container').className = 'unsupported';
   } else {
-    var qs = iD.util.stringQs(location.hash);
-    if (qs.preauth) {
-      var preauth = JSON.parse(qs.preauth);
+    var id = iD()
+      .embed(true)
+      .imagePath("/assets/iD/img/")<%# Can't use asset_path('id/img/') in production. %>
+      .preauth({
+        <% token = @user.access_token(ID_KEY) %>
+        url: "<%= request.protocol + request.host_with_port %>",
+        oauth_consumer_key: "<%= token.client_application.key %>",
+        oauth_secret: "<%= token.client_application.secret %>",
+        oauth_token: "<%= token.token %>",
+        oauth_token_secret: "<%= token.secret %>"
+      });
 
-      var id = iD()
-        .embed(true)
-        .imagePath("/assets/iD/img/"); <%# Can't use asset_path('id/img/') in production. %>
+    id.map().on('move.embed', function() {
+      var extent = id.map().extent(),
+          zoom = ~~id.map().zoom(),
+          center = id.map().center();
 
-      id.connection()
-        .url(Object.keys(preauth)[0])
-        .keys(preauth);
+      parent.updatelinks(
+        center[0],
+        center[1],
+        zoom,
+        null,
+        extent[0][0],
+        extent[0][1],
+        extent[1][0],
+        extent[1][1]);
+    });
 
-      d3.select('#id-container')
-        .call(id.ui());
-    }
+    parent.$("body").on("click", "a.set_position", function (e) {
+      e.preventDefault();
+      var data = parent.$(this).data();
+      id.map().centerZoom(
+        [data.lon, data.lat],
+        Math.max(data.zoom || 15, 13));
+    });
+
+    d3.select('#id-container')
+      .call(id.ui());
   }
 </script>
 </body>