]> git.openstreetmap.org Git - nominatim.git/commitdiff
user interface: reverse search remembers zoom level after map click
authormarc tobias <mtm@marcs-MacBook-Pro.local>
Thu, 21 Jan 2016 15:26:18 +0000 (15:26 +0000)
committermarc tobias <mtm@marcs-MacBook-Pro.local>
Thu, 21 Jan 2016 15:26:18 +0000 (15:26 +0000)
lib/template/address-html.php
website/js/nominatim-ui.js

index 34bf852cacceadb5c5a50766ba485162a05be927..3a47e6acb3197521d1c5693af90f190406ed8073 100644 (file)
@@ -13,6 +13,7 @@
   <form class="form-inline" role="search" accept-charset="UTF-8" action="<?php echo CONST_Website_BaseURL; ?>reverse.php">
     <div class="form-group">
       <input name="format" type="hidden" value="html">
+      <input name="prevmapzoom" type="hidden" value="">
       <input name="lat" type="text" class="form-control input-sm" placeholder="latitude"  value="<?php echo htmlspecialchars($_GET['lat']); ?>" >
       <input name="lon" type="text" class="form-control input-sm" placeholder="longitude" value="<?php echo htmlspecialchars($_GET['lon']); ?>" >
     </div>
   <?php
 
     $aNominatimMapInit = [
-      'zoom' => (isset($_GET['lat'])||$_GET['lat'])?16:NULL,
-      'lat' => isset($_GET['lat'])?htmlspecialchars($_GET['lat']):NULL,
-      'lon' => isset($_GET['lon'])?htmlspecialchars($_GET['lon']):NULL
+      'prevmapzoom' => isset($_GET['prevmapzoom'])?htmlspecialchars($_GET['prevmapzoom']):NULL,
+      'zoom' => isset($_GET['zoom'])?htmlspecialchars($_GET['zoom']):NULL,
+      'lat'  => isset($_GET['lat'] )?htmlspecialchars($_GET['lat']):NULL,
+      'lon'  => isset($_GET['lon'] )?htmlspecialchars($_GET['lon']):NULL
     ];
     echo 'var nominatim_map_init = ' . json_encode($aNominatimMapInit, JSON_PRETTY_PRINT) . ';';
 
index 1c90cb0f618074556cc52c73082307acc92ee147..8c82c344b2e7296c2dda6e56d59d4b5e56aecd17 100644 (file)
@@ -24,13 +24,14 @@ jQuery(document).on('ready', function(){
        }).addTo(map);
 
        if ( nominatim_map_init.lat ){
-               map.setView([nominatim_map_init.lat || 0, nominatim_map_init.lon], nominatim_map_init.zoom);
+               map.setView([nominatim_map_init.lat || 0, nominatim_map_init.lon], (nominatim_map_init.prevmapzoom || nominatim_map_init.zoom) );
 
                if ( is_reverse_search ){
                        // not really a market, but the .circle changes radius once you zoom in/out
                        var cm = L.circleMarker([nominatim_map_init.lat,nominatim_map_init.lon], { radius: 5, weight: 2, fillColor: '#ff7800', color: 'red', opacity: 0.75, clickable: false});
                        cm.addTo(map);
                }
+
        } else {
                map.setView([0,0],2);
        }
@@ -49,7 +50,9 @@ jQuery(document).on('ready', function(){
 
                html_viewbox = "viewbox: " + map_viewbox_as_string();
 
-               $('#map-position').html([html_center,html_viewbox,html_click,html_mouse].join('<br/>'));
+               html_zoom = "zoom: " + map.getZoom();
+
+               $('#map-position').html([html_center,html_zoom,html_viewbox,html_click,html_mouse].join('<br/>'));
                $('input#use_viewbox').trigger('change');
        }
 
@@ -133,7 +136,7 @@ jQuery(document).on('ready', function(){
                else {
                        if ( is_reverse_search ){
                                // make sure the search coordinates are in the map view as well
-                               map.fitBounds([[result.lat,result.lon], [nominatim_map_init.lat,nominatim_map_init.lon]], {padding: [50,50]});
+                               map.fitBounds([[result.lat,result.lon], [nominatim_map_init.lat,nominatim_map_init.lon]], {padding: [50,50], maxZoom: map.getZoom()});
 
                                // better, but causes a leaflet warning
                                // map.panInsideBounds([[result.lat,result.lon], [nominatim_map_init.lat,nominatim_map_init.lon]], {animate: false});
@@ -167,6 +170,7 @@ jQuery(document).on('ready', function(){
                map.on('click', function(e){
                        $('form input[name=lat]').val( e.latlng.lat);
                        $('form input[name=lon]').val( e.latlng.lng);
+                       if ( map.getZoom() > 2 ){ $('form input[name=prevmapzoom]').val( map.getZoom() ); }
                        $('form').submit();
                });
        }