]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index.js
Remove highlight from map when clicking on a feature
[rails.git] / app / assets / javascripts / index.js
index 55f1f8f1e95a60ef680798f58503ca3f095ffde4..54ccb88ed08a277b8079cd74b7b3ed6476171c72 100644 (file)
@@ -5,6 +5,7 @@
 //= require leaflet.key
 //= require leaflet.note
 //= require leaflet.share
+//= require leaflet.query
 //= require index/search
 //= require index/browse
 //= require index/export
@@ -12,6 +13,7 @@
 //= require index/history
 //= require index/note
 //= require index/new_note
+//= require index/query
 //= require router
 
 (function() {
@@ -123,6 +125,11 @@ $(document).ready(function () {
     sidebar: sidebar
   }).addTo(map);
 
+  L.OSM.query({
+    position: position,
+    sidebar: sidebar
+  }).addTo(map);
+
   L.control.scale()
     .addTo(map);
 
@@ -150,7 +157,8 @@ $(document).ready(function () {
       map.getLayersCode(),
       map._object);
 
-    $.cookie("_osm_location", cookieContent(map), { expires: expiry });
+    $.removeCookie("_osm_location");
+    $.cookie("_osm_location", OSM.locationCookie(map), { expires: expiry, path: "/" });
   });
 
   if ($.cookie('_osm_welcome') == 'hide') {
@@ -197,8 +205,9 @@ $(document).ready(function () {
   });
 
   $("a[data-editor=remote]").click(function(e) {
-      remoteEditHandler(map.getBounds());
-      e.preventDefault();
+    var params = OSM.mapParams(this.search);
+    remoteEditHandler(map.getBounds(), params.object);
+    e.preventDefault();
   });
 
   if (OSM.params().edit_help) {
@@ -222,15 +231,20 @@ $(document).ready(function () {
       $("#content").addClass("overlay-sidebar");
       map.invalidateSize({pan: false})
         .panBy([-350, 0], {animate: false});
+      document.title = I18n.t('layouts.project_name.title');
     };
 
     page.load = function() {
+      if (!("autofocus" in document.createElement("input"))) {
+        $("#sidebar .search_form input[name=query]").focus();
+      }
       return map.getState();
     };
 
     page.popstate = function() {
       $("#content").addClass("overlay-sidebar");
       map.invalidateSize({pan: false});
+      document.title = I18n.t('layouts.project_name.title');
     };
 
     page.unload = function() {
@@ -247,14 +261,25 @@ $(document).ready(function () {
 
     page.pushstate = page.popstate = function(path, id) {
       OSM.loadSidebarContent(path, function() {
-        page.load(path, id);
+        addObject(type, id);
       });
     };
 
     page.load = function(path, id) {
-      map.addObject({type: type, id: parseInt(id)});
+      addObject(type, id, true);
     };
 
+    function addObject(type, id, center) {
+      var bounds = map.addObject({type: type, id: parseInt(id)}, function(bounds) {
+        if (!window.location.hash && bounds.isValid() &&
+            (center || !map.getBounds().contains(bounds))) {
+          OSM.router.withoutMoveListener(function () {
+            map.fitBounds(bounds);
+          });
+        }
+      });
+    }
+
     page.unload = function() {
       map.removeObject();
     };
@@ -277,11 +302,12 @@ $(document).ready(function () {
     "/node/:id(/history)":         OSM.Browse(map, 'node'),
     "/way/:id(/history)":          OSM.Browse(map, 'way'),
     "/relation/:id(/history)":     OSM.Browse(map, 'relation'),
-    "/changeset/:id":              OSM.Browse(map, 'changeset')
+    "/changeset/:id":              OSM.Browse(map, 'changeset'),
+    "/query":                      OSM.Query(map)
   });
 
   if (OSM.preferred_editor == "remote" && document.location.pathname == "/edit") {
-    remoteEditHandler(map.getBounds());
+    remoteEditHandler(map.getBounds(), params.object);
     OSM.router.setCurrentPath("/");
   }
 
@@ -316,7 +342,7 @@ $(document).ready(function () {
 
   $(".describe_location").on("click", function(e) {
     e.preventDefault();
-    var precision = zoomPrecision(map.getZoom());
+    var precision = OSM.zoomPrecision(map.getZoom());
     OSM.router.route("/search?query=" + encodeURIComponent(
       map.getCenter().lat.toFixed(precision) + "," +
       map.getCenter().lng.toFixed(precision)));