Skip to content

Commit 72ca809

Browse files
committed
Merge pull request #78 from joubu/autocenter
Add the ability to auto center/zoom the map
2 parents f81072b + e5591fd commit 72ca809

5 files changed

Lines changed: 43 additions & 11 deletions

File tree

admin/admin_config.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@
134134
if (isset($_POST['submit']) && !empty($_POST['osm_height']))
135135
{
136136
// Check the center GPS position is valid
137-
if (isset($_POST['osm_left_center']) and strlen($_POST['osm_left_center']) != 0)
138-
$center_arr = explode(',', $_POST['osm_left_center']);
137+
$osm_left_center = (isset($_POST['osm_left_center']) and strlen($_POST['osm_left_center']) != 0) ? $_POST['osm_left_center'] : '0,0';
138+
$center_arr = explode(',', $osm_left_center);
139139
//print_r($center_arr);
140140
$latitude = $center_arr[0];
141141
$longitude = $center_arr[1];
@@ -168,7 +168,8 @@
168168
'popupinfo_comment' => isset($_POST['osm_left_popupinfo_comment']),
169169
'popupinfo_author' => isset($_POST['osm_left_popupinfo_author']),
170170
'zoom' => $_POST['osm_left_zoom'],
171-
'center' => $_POST['osm_left_center'],
171+
'center' => $osm_left_center,
172+
'autocenter' => get_boolean($_POST['osm_left_autocenter']),
172173
'layout' => $_POST['osm_left_layout'],
173174
),
174175
'category_description' => array(

admin/admin_config.tpl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,19 @@ Refer to the <a href="https://github.com/xbgmsharp/piwigo-openstreetmap/wiki" ta
110110
<small>{'LEFTPOPUPINFO_DESC'|@translate}</small>
111111
</li>
112112
<li>
113+
<label>{'Auto center'|@translate} : </label>
114+
<label><input id="autocenter_enabled" type="radio" name="osm_left_autocenter" value="true" {if $left_menu.autocenter}checked="checked"{/if} onchange="autocenter_toggle(this);"/> {'Yes'|@translate}</label>
115+
<label><input type="radio" name="osm_left_autocenter" value="false" {if not $left_menu.autocenter}checked="checked"{/if} onchange="autocenter_toggle(this);"/> {'No'|@translate}</label>
116+
<br/><small>{'The map will be automatically centered and zoomed to contain all infos.'|@translate}</small>
117+
</li>
118+
<li id="osm_left_zoom_block">
113119
<label>{'ZOOM'|@translate} : </label>
114120
<select name="osm_left_zoom">
115121
{html_options options=$AVAILABLE_ZOOM selected=$left_menu.zoom}
116122
</select>
117123
<br/><small>{'ZOOM_DESC'|@translate}</small>
118124
</li>
119-
<li>
125+
<li id="osm_left_center_block">
120126
<label>{'CENTER_MAP'|@translate} : </label>
121127
<input type="text" value="{$left_menu.center}" name="osm_left_center" size="30" placeholder="0,0"/>
122128
<br/><small>{'CENTER_MAP_DESC'|@translate}</small>
@@ -329,6 +335,21 @@ function pin_toggle()
329335
pin_preview();
330336
}
331337
338+
function autocenter_toggle()
339+
{
340+
var radio = document.getElementById("autocenter_enabled");
341+
var zoom_block = document.getElementById("osm_left_zoom_block");
342+
var center_block = document.getElementById("osm_left_center_block");
343+
if (radio.checked) // If autocenter
344+
{
345+
zoom_block.setAttribute("style", "display:none;");
346+
center_block.setAttribute("style", "display:none;");
347+
} else {
348+
zoom_block.removeAttribute("style");
349+
center_block.removeAttribute("style");
350+
}
351+
}
352+
332353
function tile_preview()
333354
{
334355
var select = document.getElementById("osm_baselayer");
@@ -391,6 +412,7 @@ function pin_preview()
391412
392413
window.onload = pin_preview();
393414
window.onload = tile_preview();
415+
window.onload = autocenter_toggle()
394416
395417
</script>
396418
{/literal}

category.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function osm_render_category()
5555
$local_conf['center_lat'] = 0;
5656
$local_conf['center_lng'] = 0;
5757
$local_conf['zoom'] = 2;
58-
$local_conf['auto_center'] = 0;
58+
$local_conf['autocenter'] = 1;
5959
$local_conf['paths'] = osm_get_gps($page);
6060
$height = isset($conf['osm_conf']['category_description']['height']) ? $conf['osm_conf']['category_description']['height'] : '200';
6161
$width = isset($conf['osm_conf']['category_description']['width']) ? $conf['osm_conf']['category_description']['width'] : 'auto';

include/functions_map.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,26 @@ function osm_get_js($conf, $local_conf, $js_data)
279279
$divname = isset($local_conf['divname']) ? $local_conf['divname'] : 'map';
280280

281281
/* If the config include parameters get them */
282-
$zoom = isset($conf['osm_conf']['left_menu']['zoom']) ? $conf['osm_conf']['left_menu']['zoom'] : 2;
283282
$center = isset($conf['osm_conf']['left_menu']['center']) ? $conf['osm_conf']['left_menu']['center'] : '0,0';
284283
$center_arr = preg_split('/,/', $center);
285284
$center_lat = isset($center_arr) ? $center_arr[0] : 0;
286285
$center_lng = isset($center_arr) ? $center_arr[1] : 0;
287286

288287
/* If we have zoom and center coordonate, set it otherwise fallback default */
289-
$zoom = isset($_GET['zoom']) ? $_GET['zoom'] : $zoom;
288+
$zoom = isset($_GET['zoom'])
289+
? $_GET['zoom']
290+
: (
291+
isset($local_conf['zoom'])
292+
? $local_conf['zoom']
293+
: 2
294+
);
290295
$center_lat = isset($_GET['center_lat']) ? $_GET['center_lat'] : $center_lat;
291296
$center_lng = isset($_GET['center_lng']) ? $_GET['center_lng'] : $center_lng;
292297

298+
$autocenter = isset($local_conf['autocenter'])
299+
? $local_conf['autocenter']
300+
: 0;
301+
293302
// Load baselayerURL
294303
if ($baselayer == 'mapnik') $baselayerurl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
295304
else if($baselayer == 'mapquest') $baselayerurl = 'http://otile1.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png';
@@ -344,7 +353,7 @@ function osm_get_js($conf, $local_conf, $js_data)
344353
$js .= "\nvar Url = '".$baselayerurl."',
345354
Attribution = '".$attribution."',
346355
TileLayer = new L.TileLayer(Url, {maxZoom: 18, noWrap: ".$nowarp.", attribution: Attribution});\n";
347-
$js .= "var " . $divname . " = new L.Map('" . $divname . "', {" . $worldcopyjump . ", zoom: ".$local_conf['zoom'].", layers: [TileLayer], contextmenu: " . $local_conf['contextmenu'] . "});\n";
356+
$js .= "var " . $divname . " = new L.Map('" . $divname . "', {" . $worldcopyjump . ", zoom: ".$zoom.", layers: [TileLayer], contextmenu: " . $local_conf['contextmenu'] . "});\n";
348357
$js .= $divname . ".attributionControl.setPrefix('');\n";
349358
$js .= "\nL.control.scale().addTo(" . $divname . ");\n";
350359
return $js;
@@ -354,7 +363,7 @@ function osm_get_js($conf, $local_conf, $js_data)
354363
Attribution = '".$attribution."',
355364
TileLayer = new L.TileLayer(Url, {maxZoom: 18, noWrap: ".$nowarp.", attribution: Attribution}),
356365
latlng = new L.LatLng(".$local_conf['center_lat'].", ".$local_conf['center_lng'].");\n";
357-
$js .= "var " . $divname . " = new L.Map('" . $divname . "', {" . $worldcopyjump . ", center: latlng, ".$editor." zoom: ".$local_conf['zoom'].", layers: [TileLayer], contextmenu: " . $local_conf['contextmenu'] . "});\n";
366+
$js .= "var " . $divname . " = new L.Map('" . $divname . "', {" . $worldcopyjump . ", center: latlng, ".$editor." zoom: ".$zoom.", layers: [TileLayer], contextmenu: " . $local_conf['contextmenu'] . "});\n";
358367
$js .= $divname . ".attributionControl.setPrefix('');\n";
359368
$js .= "var MarkerClusterList=[];\n";
360369
$js .= "if (typeof L.MarkerClusterGroup === 'function')\n";
@@ -508,7 +517,7 @@ function osm_get_js($conf, $local_conf, $js_data)
508517
}
509518
$js .= "\nif (typeof L.MarkerClusterGroup === 'function')\n";
510519
$js .= " " . $divname . ".addLayer(markers);\n";
511-
if (isset($local_conf['auto_center']) and $local_conf['auto_center'] === 0 ) {
520+
if ( $autocenter ) {
512521
$js .= "var group = new L.featureGroup(MarkerClusterList);";
513522
$js .= "this." . $divname . ".whenReady(function () {
514523
window.setTimeout(function () {

menu.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function osm_apply_menu($menu_ref_arr)
6565
$local_conf['center_lat'] = 0;
6666
$local_conf['center_lng'] = 0;
6767
$local_conf['zoom'] = 2;
68-
$local_conf['auto_center'] = 0;
68+
$local_conf['autocenter'] = 1;
6969
$local_conf['divname'] = 'mapmenu';
7070
$local_conf['paths'] = osm_get_gps($page);
7171
$height = isset($conf['osm_conf']['main_menu']['height']) ? $conf['osm_conf']['main_menu']['height'] : '200';

0 commit comments

Comments
 (0)