]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index.js
Pre-fill directions 'from' field with search query, if any.
[rails.git] / app / assets / javascripts / index.js
index 1c0812485100b6100c8a5be5b5eef1e065a3f6f8..66dfa5b6fac3975a2c00daa6b651d76034303ef0 100644 (file)
@@ -6,6 +6,7 @@
 //= require leaflet.note
 //= require leaflet.share
 //= require leaflet.polyline
 //= require leaflet.note
 //= require leaflet.share
 //= require leaflet.polyline
+//= require leaflet.query
 //= require index/search
 //= require index/browse
 //= require index/export
 //= require index/search
 //= require index/browse
 //= require index/export
@@ -14,6 +15,8 @@
 //= require index/note
 //= require index/new_note
 //= require index/directions
 //= require index/note
 //= require index/new_note
 //= require index/directions
+//= require index/changeset
+//= require index/query
 //= require router
 
 $(document).ready(function () {
 //= require router
 
 $(document).ready(function () {
@@ -125,6 +128,11 @@ $(document).ready(function () {
     sidebar: sidebar
   }).addTo(map);
 
     sidebar: sidebar
   }).addTo(map);
 
+  L.OSM.query({
+    position: position,
+    sidebar: sidebar
+  }).addTo(map);
+
   L.control.scale()
     .addTo(map);
 
   L.control.scale()
     .addTo(map);
 
@@ -252,10 +260,11 @@ $(document).ready(function () {
 
     function addObject(type, id, center) {
       var bounds = map.addObject({type: type, id: parseInt(id)}, function(bounds) {
 
     function addObject(type, id, center) {
       var bounds = map.addObject({type: type, id: parseInt(id)}, function(bounds) {
-        if (!window.location.hash && bounds.isValid()) {
-          OSM.router.moveListenerOff();
-          map.once('moveend', OSM.router.moveListenerOn);
-          if (center || !map.getBounds().contains(bounds)) map.fitBounds(bounds);
+        if (!window.location.hash && bounds.isValid() &&
+            (center || !map.getBounds().contains(bounds))) {
+          OSM.router.withoutMoveListener(function () {
+            map.fitBounds(bounds);
+          });
         }
       });
     }
         }
       });
     }
@@ -283,7 +292,8 @@ $(document).ready(function () {
     "/node/:id(/history)":         OSM.Browse(map, 'node'),
     "/way/:id(/history)":          OSM.Browse(map, 'way'),
     "/relation/:id(/history)":     OSM.Browse(map, 'relation'),
     "/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.Changeset(map),
+    "/query":                      OSM.Query(map)
   });
 
   if (OSM.preferred_editor == "remote" && document.location.pathname == "/edit") {
   });
 
   if (OSM.preferred_editor == "remote" && document.location.pathname == "/edit") {
@@ -308,4 +318,24 @@ $(document).ready(function () {
     if (OSM.router.route(this.pathname + this.search + this.hash))
       e.preventDefault();
   });
     if (OSM.router.route(this.pathname + this.search + this.hash))
       e.preventDefault();
   });
+
+  $(".search_form").on("submit", function(e) {
+    e.preventDefault();
+    $("header").addClass("closed");
+    var query = $(this).find("input[name=query]").val();
+    if (query) {
+      OSM.router.route("/search?query=" + encodeURIComponent(query) + OSM.formatHash(map));
+    } else {
+      OSM.router.route("/");
+    }
+  });
+
+  $(".describe_location").on("click", function(e) {
+    e.preventDefault();
+    var center = map.getCenter().wrap(),
+      precision = OSM.zoomPrecision(map.getZoom());
+    OSM.router.route("/search?query=" + encodeURIComponent(
+      center.lat.toFixed(precision) + "," + center.lng.toFixed(precision)
+    ));
+  });
 });
 });