Skip to content

Commit 205564a

Browse files
author
Emmanuel Garette
committed
add map in main menu
1 parent 4960ea9 commit 205564a

9 files changed

Lines changed: 165 additions & 8 deletions

File tree

admin/admin_config.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@
140140
'height' => $_POST['osm_cat_height'],
141141
'width' => $_POST['osm_cat_width'],
142142
),
143+
'main_menu' => array(
144+
'enabled' => get_boolean($_POST['osm_main_menu']),
145+
'height' => $_POST['osm_menu_height'],
146+
),
143147
'map' => array(
144148
'baselayer' => $_POST['osm_baselayer'],
145149
'custombaselayer' => $_POST['osm_custombaselayer'],

admin/admin_config.tpl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Refer to the <a href="https://github.com/xbgmsharp/piwigo-openstreetmap/wiki" ta
111111
<label>{'SHOWCMAP'|@translate} : </label>
112112
<label><input type="radio" name="osm_category_description" value="true" {if $category_description.enabled}checked="checked"{/if}/> {'Yes'|@translate}</label>
113113
<label><input type="radio" name="osm_category_description" value="false" {if not $category_description.enabled}checked="checked"{/if}/> {'No'|@translate}</label>
114-
<br/><small>{'SHOWCMAP'|@translate}</small>
114+
<br/><small>{'SHOWCMAP_DESC'|@translate}</small>
115115
</li>
116116
<li>
117117
<label>{'HEIGHT'|@translate} : </label>
@@ -125,6 +125,22 @@ Refer to the <a href="https://github.com/xbgmsharp/piwigo-openstreetmap/wiki" ta
125125
</li>
126126
</ul>
127127
</fieldset>
128+
<fieldset>
129+
<legend>{'M_MAP'|@translate}</legend>
130+
<ul>
131+
<li>
132+
<label>{'SHOWMMAP'|@translate} : </label>
133+
<label><input type="radio" name="osm_main_menu" value="true" {if $main_menu.enabled}checked="checked"{/if}/> {'Yes'|@translate}</label>
134+
<label><input type="radio" name="osm_main_menu" value="false" {if not $main_menu.enabled}checked="checked"{/if}/> {'No'|@translate}</label>
135+
<br/><small>{'SHOWMMAP_DESC'|@translate}</small>
136+
</li>
137+
<li>
138+
<label>{'HEIGHT'|@translate} : </label>
139+
<input type="text" value="{$main_menu.height}" name="osm_menu_height" size="4" required/>
140+
<br/><small>{'HEIGHT_DESC'|@translate}</small>
141+
</li>
142+
</ul>
143+
</fieldset>
128144
<fieldset>
129145
<legend>{'G_MAP'|@translate}</legend>
130146
<ul>

include/functions_map.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ function osm_get_js($conf, $local_conf, $js_data)
202202
$attrleaflet = isset($conf['osm_conf']['map']['attrleaflet']) ? $conf['osm_conf']['map']['attrleaflet'] : 'false';
203203
$attrimagery = isset($conf['osm_conf']['map']['attrimagery']) ? $conf['osm_conf']['map']['attrimagery'] : 'false';
204204
$attrmodule = isset($conf['osm_conf']['map']['attrplugin']) ? $conf['osm_conf']['map']['attrplugin'] : 'false';
205+
$divname = isset($local_conf['divname']) ? $local_conf['divname'] : 'map';
205206

206207
// Load baselayerURL
207208
// Key1 BC9A493B41014CAABB98F0471D759707
@@ -239,14 +240,14 @@ function osm_get_js($conf, $local_conf, $js_data)
239240
Attribution = '".$attribution."',
240241
TileLayer = new L.TileLayer(Url, {maxZoom: 18, noWrap: ".$nowarp.", attribution: Attribution}),
241242
latlng = new L.LatLng(".$local_conf['center_lat'].", ".$local_conf['center_lng'].");\n";
242-
$js .= "var map = new L.Map('map', {" . $worldcopyjump . ", center: latlng, zoom: ".$local_conf['zoom'].", layers: [TileLayer], contextmenu: " . $local_conf['contextmenu'] . "});\n";
243-
$js .= "map.attributionControl.setPrefix('');\n";
243+
$js .= "var " . $divname . " = new L.Map('" . $divname . "', {" . $worldcopyjump . ", center: latlng, zoom: ".$local_conf['zoom'].", layers: [TileLayer], contextmenu: " . $local_conf['contextmenu'] . "});\n";
244+
$js .= $divname . ".attributionControl.setPrefix('');\n";
244245
$js .= "var MarkerClusterList=[];\n";
245246
$js .= "if (typeof L.MarkerClusterGroup === 'function')\n";
246247
$js .= " var markers = new L.MarkerClusterGroup();\n";
247248
if ($local_conf['control'] === true)
248249
{
249-
$js .= "L.control.scale().addTo(map);\n";
250+
$js .= "L.control.scale().addTo(" . $divname . ");\n";
250251
// Icons
251252
$js .= "
252253
@@ -375,16 +376,16 @@ function osm_get_js($conf, $local_conf, $js_data)
375376
$js .= "\nif (typeof L.MarkerClusterGroup === 'function')
376377
\t markers.addLayer(marker);
377378
\telse
378-
\t map.addLayer(marker);
379+
\t " . $divname . ".addLayer(marker);
379380
\tMarkerClusterList.push(marker);
380381
\t}";
381382
$js .= "\nif (typeof L.MarkerClusterGroup === 'function')\n";
382-
$js .= " map.addLayer(markers);\n";
383+
$js .= " " . $divname . ".addLayer(markers);\n";
383384
if (isset($local_conf['auto_center']) and $local_conf['auto_center'] === 0 ) {
384385
$js .= "var group = new L.featureGroup(MarkerClusterList);";
385-
$js .= "this.map.whenReady(function () {
386+
$js .= "this." . $divname . ".whenReady(function () {
386387
window.setTimeout(function () {
387-
map.fitBounds(group.getBounds());
388+
" . $divname . ".fitBounds(group.getBounds());
388389
}.bind(this), 200);
389390
}, this);";
390391
}

language/en_UK/plugin.lang.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@
3737

3838
$lang['C_MAP'] = "Category's description";
3939
$lang['SHOWCMAP'] = "Add a map in category's description";
40+
$lang['SHOWCMAP_DESC'] = 'Show a world map menu on category\'s description, will display all the images in the gallery.';
4041
$lang['WIDTH'] = 'Map width';
4142
$lang['WIDTH_DESC'] = 'in px or auto';
4243

44+
$lang['M_MAP'] = "Main menu";
45+
$lang['SHOWMMAP'] = "Add a map in main menu";
46+
$lang['SHOWMMAP_DESC'] = 'Show a world map menu on main menu, will display all the images in the gallery.';
47+
4348
$lang['G_MAP'] = "Map configuration";
4449
$lang['BASELAYER'] = "Map style";
4550
$lang['BASELAYER_DESC'] = "Mapnik is the default style of OpenStreetMap.";

language/fr_FR/plugin.lang.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
$lang['WIDTH'] = 'Largeur de la carte';
4040
$lang['WIDTH_DESC'] = 'en pixel ou auto';
4141

42+
$lang['M_MAP'] = "Menu principal";
43+
$lang['SHOWMMAP'] = "Ajouter la carte dans le menu principal";
44+
$lang['SHOWMMAP_DESC'] = 'Show a world map menu on main menu, will display all the images in the gallery.';
45+
4246
$lang['G_MAP'] = "Configuration de la Carte";
4347
$lang['BASELAYER'] = "Style de Carte";
4448
$lang['BASELAYER_DESC'] = "Mapnik est le style par défaut d'OpenStreetMap.";

main.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
elseif (script_basename() == 'index')
2828
{
2929
include_once(dirname(__FILE__).'/index.inc.php');
30+
include_once(dirname(__FILE__).'/menu.inc.php');
3031
}
3132

3233
// Do we have to show a link on the left menu

maintain.inc.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ function plugin_install()
6767
'enabled' => true,
6868
'height' => '200',
6969
'width' => 'auto',
70+
),
71+
'main_menu' => array(
72+
'enabled' => false,
73+
'height' => '200',
7074
),
7175
'map' => array(
7276
'baselayer' => 'mapnik',

menu.inc.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/***********************************************
3+
* File : picture.inc.php
4+
* Project : piwigo-openstreetmap
5+
* Descr : Display map on right panel
6+
*
7+
* Created : 20.08.2014
8+
*
9+
* Copyright 2013-2014 <xbgmsharp@gmail.com>
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation, either version 3 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*
24+
************************************************/
25+
26+
// Chech whether we are indeed included by Piwigo.
27+
if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
28+
29+
if ($conf['osm_conf']['main_menu']['enabled'])
30+
{
31+
add_event_handler('blockmanager_register_blocks', 'osm_register_menu');
32+
add_event_handler('blockmanager_apply', 'osm_apply_menu');
33+
}
34+
function osm_register_menu( $menu_ref_arr )
35+
{
36+
$menu = & $menu_ref_arr[0];
37+
if ($menu->get_id() != 'menubar')
38+
return;
39+
$menu->register_block( new RegisteredBlock( 'mbAbout', 'About', 'A1M'));
40+
}
41+
42+
function osm_apply_menu($menu_ref_arr)
43+
{
44+
global $template, $page, $conf;
45+
46+
$menu = & $menu_ref_arr[0];
47+
48+
if (($block = $menu->get_block('mbLinks')) != null) {
49+
include_once( dirname(__FILE__) .'/include/functions.php');
50+
include_once(dirname(__FILE__).'/include/functions_map.php');
51+
osm_load_language();
52+
load_language('plugin.lang', OSM_PATH);
53+
54+
#comment are used only with this condition index.php l294
55+
if ($page['start']==0 and !isset($page['chronology_field']) )
56+
{
57+
$js_data = osm_get_items($page);
58+
if ($js_data != array())
59+
{
60+
$local_conf = array();
61+
$local_conf['pinid'] = 1;
62+
$local_conf['contextmenu'] = 'false';
63+
$local_conf['available_pin'] = '';
64+
$local_conf['control'] = false;
65+
$local_conf['img_popup'] = false;
66+
$local_conf['popup'] = 2;
67+
$local_conf['center_lat'] = 0;
68+
$local_conf['center_lng'] = 0;
69+
$local_conf['zoom'] = 2;
70+
$local_conf['auto_center'] = 0;
71+
$local_conf['divname'] = 'mapmenu';
72+
$height = isset($conf['osm_conf']['main_menu']['height']) ? $conf['osm_conf']['main_menu']['height'] : '200';
73+
$js = osm_get_js($conf, $local_conf, $js_data);
74+
$template->set_template_dir(dirname(__FILE__).'/template/');
75+
$template->assign(
76+
array(
77+
'OSM_PATH' => embellish_url(get_absolute_root_url().OSM_PATH),
78+
'OSMJS' => $js,
79+
'HEIGHT' => $height,
80+
)
81+
);
82+
$block->template = 'osm-menu.tpl';
83+
}
84+
}
85+
}
86+
}
87+
?>

template/osm-menu.tpl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{html_head}
2+
<link href="{$OSM_PATH}leaflet/leaflet.css" rel="stylesheet">
3+
<script src="{$OSM_PATH}leaflet/leaflet.js"></script>
4+
<!--<script src="{$OSM_PATH}togeojson.js"></script>-->
5+
<link rel="stylesheet" href="{$OSM_PATH}leaflet/MarkerCluster.css" />
6+
<link rel="stylesheet" href="{$OSM_PATH}leaflet/MarkerCluster.Default.css" />
7+
<script src="{$OSM_PATH}leaflet/leaflet.markercluster.js"></script>
8+
{/html_head}
9+
10+
{html_style}
11+
{literal}
12+
#mapmenu {
13+
height: {/literal}{$HEIGHT}{literal}px;
14+
15+
}
16+
{/literal}
17+
{/html_style}
18+
19+
<dt>{'MAP'|@translate}</dt><dd>
20+
<div id="mapmenu"></div></dd>
21+
<script type="text/javascript">{$OSMJS}
22+
23+
{literal}
24+
map.on('moveend', onMapMove);
25+
26+
function onMapMove(e){
27+
getMarkers();
28+
}
29+
30+
function getMarkers(){
31+
var bounds = map.getBounds();
32+
}
33+
{/literal}
34+
</script>
35+

0 commit comments

Comments
 (0)