[24677] | 1 | <?php |
---|
| 2 | /*********************************************** |
---|
| 3 | * File : picture.inc.php |
---|
| 4 | * Project : piwigo-openstreetmap |
---|
| 5 | * Descr : Display map on right panel |
---|
| 6 | * |
---|
| 7 | * Created : 28.05.2013 |
---|
| 8 | * |
---|
| 9 | * Copyright 2013 <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 | // Do we have to show the right panel |
---|
| 27 | if ($conf['osm_conf']['right_panel']['enabled']) |
---|
| 28 | { |
---|
| 29 | // Hook to add the div in the right menu, No idea about the number!! |
---|
| 30 | add_event_handler('loc_begin_picture', 'osm_loc_begin_picture', 56); |
---|
| 31 | |
---|
| 32 | // Hook to populate the div in the right menu, No idea about the number after!! |
---|
| 33 | add_event_handler('loc_begin_picture', 'osm_render_element_content', EVENT_HANDLER_PRIORITY_NEUTRAL+1 /*in order to have picture content*/, 2); |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | function osm_loc_begin_picture() |
---|
| 37 | { |
---|
| 38 | global $template; |
---|
| 39 | $template->set_prefilter('picture', 'osm_insert_map'); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | function osm_insert_map($content, &$smarty) |
---|
| 43 | { |
---|
| 44 | global $conf; |
---|
| 45 | load_language('plugin.lang', OSM_PATH); |
---|
| 46 | |
---|
| 47 | /* Would be better if you could be like the Metdata but how? |
---|
| 48 | $search = '#<dl id="Metadata" class="imageInfoTable">#'; |
---|
| 49 | $replacement = ' |
---|
| 50 | <dl id="map-info" class="imageInfoTable"> |
---|
| 51 | <h3>{\'LOCATION\'|@translate}</h3> |
---|
| 52 | <div class="imageInfo"> |
---|
| 53 | <div id="map"></div> |
---|
| 54 | </div> |
---|
| 55 | </dl> |
---|
| 56 | <dl id="Metadata" class="imageInfoTable">'; |
---|
| 57 | */ |
---|
| 58 | |
---|
| 59 | $search = '#<div id="'. $conf['osm_conf']['right_panel']['add_before'] .'" class="imageInfo">#'; |
---|
| 60 | $replacement = ' |
---|
| 61 | {if $OSMJS} |
---|
| 62 | <div id="map-info" class="imageInfo"> |
---|
| 63 | <dt {$OSMNAMECSS}>{$OSMNAME}</dt> |
---|
| 64 | <dd> |
---|
| 65 | <div id="map"></div> |
---|
| 66 | <script type="text/javascript">{$OSMJS}</script> |
---|
| 67 | {if $SHOWOSM} |
---|
| 68 | View on <a href="{$OSMLINK}" target="_blank">OpenStreetMap</a> |
---|
| 69 | {/if} |
---|
| 70 | </dd> |
---|
| 71 | </div> |
---|
| 72 | {/if} |
---|
| 73 | <div id="'. $conf['osm_conf']['right_panel']['add_before'] .'" class="imageInfo">'; |
---|
| 74 | |
---|
| 75 | return preg_replace($search, $replacement, $content); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | function osm_render_element_content() |
---|
| 79 | { |
---|
| 80 | global $template, $picture, $page, $conf; |
---|
| 81 | load_language('plugin.lang', OSM_PATH); |
---|
| 82 | |
---|
| 83 | if (empty($page['image_id'])) |
---|
| 84 | { |
---|
| 85 | return; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | // Load coordinates from picture |
---|
| 89 | $query = 'SELECT lat,lon FROM '.IMAGES_TABLE.' WHERE id = \''.$page['image_id'].'\' ;'; |
---|
| 90 | $result = pwg_query($query); |
---|
| 91 | $row = pwg_db_fetch_assoc($result); |
---|
| 92 | if (!$row or !$row['lat'] or empty($row['lat'])) { return; } |
---|
| 93 | $lat = $row['lat']; |
---|
| 94 | $lon = $row['lon']; |
---|
| 95 | |
---|
| 96 | // Load parameter, fallback to default if unset |
---|
| 97 | $height = isset($conf['osm_conf']['right_panel']['height']) ? $conf['osm_conf']['right_panel']['height'] : '200'; |
---|
| 98 | $zoom = isset($conf['osm_conf']['right_panel']['zoom']) ? $conf['osm_conf']['right_panel']['zoom'] : '12'; |
---|
| 99 | $osmname = isset($conf['osm_conf']['right_panel']['link']) ? $conf['osm_conf']['right_panel']['link'] : 'Location'; |
---|
| 100 | $osmnamecss = isset($conf['osm_conf']['right_panel']['linkcss']) ? $conf['osm_conf']['right_panel']['linkcss'] : ''; |
---|
| 101 | $showosm = isset($conf['osm_conf']['right_panel']['showosm']) ? $conf['osm_conf']['right_panel']['showosm'] : 'true'; |
---|
| 102 | $baselayer = isset($conf['osm_conf']['map']['baselayer']) ? $conf['osm_conf']['map']['baselayer'] : 'mapnik'; |
---|
| 103 | $custombaselayer = isset($conf['osm_conf']['map']['custombaselayer']) ? $conf['osm_conf']['map']['custombaselayer'] : ''; |
---|
| 104 | $custombaselayerurl = isset($conf['osm_conf']['map']['custombaselayerurl']) ? $conf['osm_conf']['map']['custombaselayerurl'] : ''; |
---|
| 105 | $noworldwarp = isset($conf['osm_conf']['map']['noworldwarp']) ? $conf['osm_conf']['map']['noworldwarp'] : 'false'; |
---|
| 106 | $attrleaflet = isset($conf['osm_conf']['map']['attrleaflet']) ? $conf['osm_conf']['map']['attrleaflet'] : 'false'; |
---|
| 107 | $attrimagery = isset($conf['osm_conf']['map']['attrimagery']) ? $conf['osm_conf']['map']['attrimagery'] : 'false'; |
---|
| 108 | $attrmodule = isset($conf['osm_conf']['map']['attrplugin']) ? $conf['osm_conf']['map']['attrplugin'] : 'false'; |
---|
| 109 | |
---|
| 110 | if (strlen($osmnamecss) != 0) |
---|
| 111 | { |
---|
| 112 | $osmnamecss = "style='".$osmnamecss."'"; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | $OSMCOPYRIGHT='Map data © <a href="http://www.openstreetmap.org" target="_blank">OpenStreetMap</a> (<a href="http://www.openstreetmap.org/copyright" target="_blank">ODbL</a>)'; |
---|
| 116 | |
---|
| 117 | $osmlink="http://openstreetmap.org/?mlat=".$lat."&mlon=".$lon."&zoom=12&layers=M"; |
---|
| 118 | |
---|
| 119 | // Load baselayerURL |
---|
| 120 | // Key1 BC9A493B41014CAABB98F0471D759707 |
---|
| 121 | if ($baselayer == 'mapnik') $baselayerurl = 'http://tile.openstreetmap.org/{z}/{x}/{y}.png'; |
---|
| 122 | else if($baselayer == 'mapquest') $baselayerurl = 'http://otile1.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png'; |
---|
| 123 | else if($baselayer == 'cloudmade') $baselayerurl = 'http://{s}.tile.cloudmade.com/7807cc60c1354628aab5156cfc1d4b3b/997/256/{z}/{x}/{y}.png'; |
---|
| 124 | else if($baselayer == 'mapnikde') $baselayerurl = 'http://www.toolserver.org/tiles/germany/{z}/{x}/{y}.png'; |
---|
| 125 | else if($baselayer == 'mapnikfr') $baselayerurl = 'http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png'; |
---|
| 126 | else if($baselayer == 'custom') $baselayerurl = $custombaselayerurl; |
---|
| 127 | |
---|
| 128 | // Generate Javascript |
---|
| 129 | // ---------------------------------------- |
---|
| 130 | // no worldWarp (no world copies, restrict the view to one world) |
---|
| 131 | if($noworldwarp) |
---|
| 132 | { |
---|
| 133 | $nowarp = "noWrap: true, "; |
---|
| 134 | $worldcopyjump = "worldCopyJump: false, maxBounds: [ [82, -180], [-82, 180] ]"; |
---|
| 135 | } |
---|
| 136 | else |
---|
| 137 | { |
---|
| 138 | $nowarp = "noWrap: false, "; |
---|
| 139 | $worldcopyjump = "worldCopyJump: true"; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | /* |
---|
| 143 | // Icons |
---|
| 144 | $js = "\n |
---|
| 145 | var LeafIcon = L.Icon.extend({ |
---|
| 146 | options: { |
---|
| 147 | shadowUrl: 'plugins/piwigo-openstreetmap/leaflet/images/leaf-shadow.png', |
---|
| 148 | iconSize: [38, 95], |
---|
| 149 | shadowSize: [50, 64], |
---|
| 150 | iconAnchor: [22, 94], |
---|
| 151 | shadowAnchor: [4, 62], |
---|
| 152 | popupAnchor: [-3, -76] |
---|
| 153 | } |
---|
| 154 | }); |
---|
| 155 | |
---|
| 156 | var mapIcon = L.Icon.extend({ |
---|
| 157 | options: { |
---|
| 158 | shadowUrl: 'plugins/piwigo-openstreetmap/leaflet/images/mapicons-shadow.png', |
---|
| 159 | iconSize: [32, 37], |
---|
| 160 | shadowSize: [51, 37], |
---|
| 161 | iconAnchor: [19, 38], |
---|
| 162 | shadowAnchor: [-20, 33], |
---|
| 163 | popupAnchor: [-2, -10] |
---|
| 164 | } |
---|
| 165 | }); |
---|
| 166 | |
---|
| 167 | var greenIcon = new LeafIcon({iconUrl: 'plugins/piwigo-openstreetmap/leaflet/images/leaf-green.png'}), |
---|
| 168 | redIcon = new LeafIcon({iconUrl: 'plugins/piwigo-openstreetmap/leaflet/images/leaf-red.png'}), |
---|
| 169 | orangeIcon = new LeafIcon({iconUrl: 'plugins/piwigo-openstreetmap/leaflet/images/leaf-orange.png'}); |
---|
| 170 | |
---|
| 171 | var bluemapicons = new mapIcon({iconUrl: 'plugins/piwigo-openstreetmap/leaflet/images/mapicons-blue.png'}), |
---|
| 172 | greenmapicons = new mapIcon({iconUrl: 'plugins/piwigo-openstreetmap/leaflet/images/mapicons-green.png'}); |
---|
| 173 | "; |
---|
| 174 | */ |
---|
| 175 | // Create the map and get a new map instance attached and element with id="tile-map" |
---|
| 176 | $js = "\nvar map = new L.Map('map', {".$worldcopyjump."});\n"; |
---|
| 177 | $js .= "map.attributionControl.setPrefix('');\n"; |
---|
| 178 | $js .= "var baselayer = new L.TileLayer('".$baselayerurl."', {maxZoom: 18, ".$nowarp."attribution: '".$OSMCOPYRIGHT."'});\n"; |
---|
| 179 | $js .= "var coord = new L.LatLng(".$lat.", ".$lon.");\n"; |
---|
| 180 | $js .= "var marker = new L.Marker(coord);\n"; |
---|
| 181 | //$js .= "var marker = new L.Marker(coord, {icon: bluemapicons});\n"; |
---|
| 182 | $js .= "map.addLayer(marker);\n"; |
---|
| 183 | |
---|
| 184 | // Attribution Credit and Copyright |
---|
| 185 | if($attrleaflet){ $js .= "map.attributionControl.addAttribution('".l10n('POWERBY')." <a href=\"http://leafletjs.com/\" target=\"_blank\">Leaflet</a>');\n"; } |
---|
| 186 | if($attrimagery){ $js .= "map.attributionControl.addAttribution('".l10n('IMAGERYBY')." ". imagery($baselayer, $custombaselayer)."');\n"; } |
---|
| 187 | if($attrmodule){ $js .= "map.attributionControl.addAttribution('".l10n('PLUGINBY')." <a href=\"https://github.com/xbgmsharp/piwigo-openstreetmap\" target=\"_blank\">xbgmsharp</a>');\n"; } |
---|
| 188 | |
---|
| 189 | // set map view |
---|
| 190 | $js .= "map.setView(coord, ".$zoom.").addLayer(baselayer);\n"; |
---|
| 191 | |
---|
| 192 | // Select the template |
---|
| 193 | $template->set_filenames( |
---|
| 194 | array('osm_content' => dirname(__FILE__)."/template/osm-picture.tpl") |
---|
| 195 | ); |
---|
| 196 | |
---|
| 197 | // Assign the template variables |
---|
| 198 | $template->assign( |
---|
| 199 | array( |
---|
| 200 | 'HEIGHT' => $height, |
---|
| 201 | 'OSMJS' => $js, |
---|
| 202 | 'OSM_PATH' => OSM_PATH, |
---|
| 203 | 'OSMNAME' => $osmname, |
---|
| 204 | 'OSMNAMECSS' => $osmnamecss, |
---|
| 205 | 'SHOWOSM' => $showosm, |
---|
| 206 | 'OSMLINK' => $osmlink, |
---|
| 207 | ) |
---|
| 208 | ); |
---|
| 209 | |
---|
| 210 | // Return the rendered html |
---|
| 211 | $osm_content = $template->parse('osm_content', true); |
---|
| 212 | return $osm_content; |
---|
| 213 | } |
---|