user interface: reverse search remembers zoom level after map click

This commit is contained in:
marc tobias 2016-01-21 15:26:18 +00:00
parent 8f0199008d
commit ef1a7d9073
2 changed files with 12 additions and 6 deletions

View 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>
@ -74,9 +75,10 @@
<?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) . ';';

View 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();
});
}