]> git.openstreetmap.org Git - rails.git/commitdiff
Simplify geolink-related code
authorJohn Firebaugh <john.firebaugh@gmail.com>
Wed, 2 Oct 2013 21:46:00 +0000 (14:46 -0700)
committerJohn Firebaugh <john.firebaugh@gmail.com>
Sun, 13 Oct 2013 21:46:07 +0000 (14:46 -0700)
#zoom/lat/lon hash format is now used consistently.

app/assets/javascripts/application.js
app/assets/javascripts/index.js
app/assets/javascripts/index/notes.js.erb
app/views/layouts/_header.html.erb
app/views/site/_potlatch2.html.erb
app/views/site/id.html.erb

index 9804e323719aea370147262fcba8dd720fb90a32..a0ddcf9c2b0b0b14e643f693fcfc4a6298afe8d8 100644 (file)
@@ -28,13 +28,6 @@ function zoomPrecision(zoom) {
     return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
 }
 
-function normalBounds(bounds) {
-    if (bounds instanceof L.LatLngBounds) return bounds;
-    return new L.LatLngBounds(
-        new L.LatLng(bounds[0][0], bounds[0][1]),
-        new L.LatLng(bounds[1][0], bounds[1][1]));
-}
-
 function remoteEditHandler(bbox, select) {
   var loaded = false,
       query = {
@@ -69,31 +62,28 @@ function remoteEditHandler(bbox, select) {
  * Called as the user scrolls/zooms around to maniplate hrefs of the
  * view tab and various other links
  */
-function updatelinks(loc, zoom, layers, bounds, object) {
+function updatelinks(loc, zoom, layers, object) {
   $(".geolink").each(function(index, link) {
     var href = link.href.split(/[?#]/)[0],
         args = querystring.parse(link.search.substring(1));
 
-    if (bounds && $(link).hasClass("bbox")) args.bbox = normalBounds(bounds).toBBoxString();
     if (object && $(link).hasClass("object")) args[object.type] = object.id;
 
     var query = querystring.stringify(args);
     if (query) href += '?' + query;
 
-    if ($(link).hasClass("llz")) {
-      args = {
-        lat: loc.lat,
-        lon: loc.lon || loc.lng,
-        zoom: zoom
-      };
+    args = {
+      lat: loc.lat,
+      lon: loc.lon || loc.lng,
+      zoom: zoom
+    };
 
-      if (layers && $(link).hasClass("layers")) {
-        args.layers = layers;
-      }
-
-      href += OSM.formatHash(args);
+    if (layers && $(link).hasClass("layers")) {
+      args.layers = layers;
     }
 
+    href += OSM.formatHash(args);
+
     link.href = href;
   });
 
index d57b76b280be1c547790882398b674cd52746bf5..525be7e52db1982ef5ed92599641be631c3b5782 100644 (file)
@@ -139,7 +139,6 @@ $(document).ready(function () {
       map.getCenter().wrap(),
       map.getZoom(),
       map.getLayersCode(),
-      map.getBounds().wrap(),
       map._object);
 
       var expiry = new Date();
index 8972d6bf9df876c3f6c3933734deb024add59019..91b2c31e1fc61e491d22091f695cf2ae04344e14 100644 (file)
@@ -190,7 +190,7 @@ function initializeNotes(map, params) {
       notes[feature.properties.id] = updateMarker(marker, feature);
       newNote = null;
 
-      addNoteButton.removeClass("active").addClass("geolink");
+      addNoteButton.removeClass("active");
     }
   }
 
@@ -226,7 +226,7 @@ function initializeNotes(map, params) {
     if (addNoteButton.hasClass("disabled")) return;
     if (addNoteButton.hasClass("active")) return;
 
-    addNoteButton.removeClass("geolink").addClass("active");
+    addNoteButton.addClass("active");
 
     map.addLayer(noteLayer);
 
@@ -263,7 +263,7 @@ function initializeNotes(map, params) {
     newNote.addTo(noteLayer).bindPopup(popupContent[0], popupOptions()).openPopup();
 
     newNote.on("remove", function (e) {
-      addNoteButton.removeClass("active").addClass("geolink");
+      addNoteButton.removeClass("active");
     }).on("dragstart", function (e) {
       $(newNote).stopTime("removenote");
     }).on("dragend", function (e) {
index 5a72eeeb374ecbfa42597965974973d18745e74a..f1eab38ae9686887fb842d11e86ff4686812e9db 100644 (file)
@@ -1,6 +1,6 @@
 <header>
   <h1>
-    <a href="<% root_path %>" class="geolink llz layers">
+    <a href="<% root_path %>" class="geolink layers">
       <%= image_tag "osm_logo.png", :alt => t('layouts.logo.alt_text'), :class => 'logo' %>
       <%= t 'layouts.project_name.h1' %>
     </a>
@@ -8,9 +8,9 @@
   <nav class='primary'>
     <ul>
       <li id="view_tab" class="<%= current_page_class(root_path) %>">
-        <%= link_to t('layouts.view'), root_path, :class => 'tab geolink llz layers' %>
+        <%= link_to t('layouts.view'), root_path, :class => 'tab geolink layers' %>
       </li><li id="edit_tab" class="dropdown <%= current_page_class(edit_path) %>">
-      <%= link_to t('layouts.edit'), edit_path, :class => "tab geolink llz object",
+      <%= link_to t('layouts.edit'), edit_path, :class => "tab geolink object",
                   :id => 'editanchor',
                   :data => { :editor => preferred_editor }
       %><a class='dropdown-toggle' data-toggle='dropdown' href='#'><b class="caret"></b></a>
             <%= link_to t('layouts.edit_with', :editor => t("editor.#{editor}.description")),
                         edit_path(:editor => editor),
                         :data => { :editor => editor },
-                        :class => "geolink llz object" %>
+                        :class => "geolink object" %>
           </li>
         <% end %>
       </ul>
       </li><li id="history_tab" class="<%= current_page_class(browse_changesets_path) %>">
-        <%= link_to t('layouts.history'), browse_changesets_path, :class => 'tab geolink llz' %>
+        <%= link_to t('layouts.history'), browse_changesets_path, :class => 'tab geolink' %>
       </li><li id="export_tab" class="<%= current_page_class(export_path) %>">
-        <%= link_to t('layouts.export'), export_path, :class => 'tab geolink llz' %>
+        <%= link_to t('layouts.export'), export_path, :class => 'tab geolink' %>
       </li>
     </ul>
   </nav>
index a6cde596093a2cdf1ad8ef226ebf5ff003e68233..faff8de1e56749a7c70e9d1f7d61a187c5ac8a3f 100644 (file)
@@ -87,8 +87,8 @@
     });
   });
 
-  var mapMoved = $.throttle(250, function(lon, lat, zoom, minlon, minlat, maxlon, maxlat) {
-    updatelinks({ lon: lon, lat: lat }, zoom, null, [[minlat, minlon], [maxlat, maxlon]]);
+  var mapMoved = $.throttle(250, function(lon, lat, zoom) {
+    updatelinks({ lon: lon, lat: lat }, zoom);
 
     var hash = OSM.formatHash({ lon: lon, lat: lat, zoom: zoom });
     if (hash !== location.hash) {
index fde4a07cd394fd10067517fb9c13fd9749342c08..fa47bb00ce69a59c6fa24320cbaf941a6485e8d3 100644 (file)
       });
 
     id.map().on('move.embed', parent.$.throttle(250, function() {
-      var extent = id.map().extent(),
-          zoom = ~~id.map().zoom(),
-          center = id.map().center();
+      var zoom = ~~id.map().zoom(),
+        center = id.map().center(),
+        llz = { lon: center[0], lat: center[1], zoom: zoom };
 
-      parent.updatelinks({
-          lon: center[0],
-          lat: center[1]
-        },
-        zoom,
-        null,
-        [[extent[0][1],
-        extent[0][0]],
-        [extent[1][1],
-        extent[1][0]]]);
+      parent.updatelinks(llz, zoom);
 
       // Manually resolve URL to avoid iframe JS context weirdness.
       // http://bl.ocks.org/jfirebaugh/5439412
-      var hash = parent.OSM.formatHash({ lon: center[0], lat: center[1], zoom: zoom });
+      var hash = parent.OSM.formatHash(llz);
       if (hash !== parent.location.hash) {
         parent.location.replace(parent.location.href.replace(/(#.*|$)/, hash));
       }