';
return preg_replace($search, $replacement, $content);
}
function osm_render_element_content()
{
global $template, $picture, $page, $conf;
load_language('plugin.lang', OSM_PATH);
if (empty($page['image_id']))
{
return;
}
// Load coordinates from picture
$query = 'SELECT lat,lon FROM '.IMAGES_TABLE.' WHERE id = \''.$page['image_id'].'\' ;';
$result = pwg_query($query);
$row = pwg_db_fetch_assoc($result);
if (!$row or !$row['lat'] or empty($row['lat'])) { return; }
$lat = $row['lat'];
$lon = $row['lon'];
// Load parameter, fallback to default if unset
$height = isset($conf['osm_conf']['right_panel']['height']) ? $conf['osm_conf']['right_panel']['height'] : '200';
$zoom = isset($conf['osm_conf']['right_panel']['zoom']) ? $conf['osm_conf']['right_panel']['zoom'] : '12';
$osmname = isset($conf['osm_conf']['right_panel']['link']) ? $conf['osm_conf']['right_panel']['link'] : 'Location';
$osmnamecss = isset($conf['osm_conf']['right_panel']['linkcss']) ? $conf['osm_conf']['right_panel']['linkcss'] : '';
$showosm = isset($conf['osm_conf']['right_panel']['showosm']) ? $conf['osm_conf']['right_panel']['showosm'] : 'true';
$baselayer = isset($conf['osm_conf']['map']['baselayer']) ? $conf['osm_conf']['map']['baselayer'] : 'mapnik';
$custombaselayer = isset($conf['osm_conf']['map']['custombaselayer']) ? $conf['osm_conf']['map']['custombaselayer'] : '';
$custombaselayerurl = isset($conf['osm_conf']['map']['custombaselayerurl']) ? $conf['osm_conf']['map']['custombaselayerurl'] : '';
$noworldwarp = isset($conf['osm_conf']['map']['noworldwarp']) ? $conf['osm_conf']['map']['noworldwarp'] : 'false';
$attrleaflet = isset($conf['osm_conf']['map']['attrleaflet']) ? $conf['osm_conf']['map']['attrleaflet'] : 'false';
$attrimagery = isset($conf['osm_conf']['map']['attrimagery']) ? $conf['osm_conf']['map']['attrimagery'] : 'false';
$attrmodule = isset($conf['osm_conf']['map']['attrplugin']) ? $conf['osm_conf']['map']['attrplugin'] : 'false';
if (strlen($osmnamecss) != 0)
{
$osmnamecss = "style='".$osmnamecss."'";
}
$OSMCOPYRIGHT='Map data ©
OpenStreetMap (
ODbL)';
$osmlink="http://openstreetmap.org/?mlat=".$lat."&mlon=".$lon."&zoom=12&layers=M";
// Load baselayerURL
// Key1 BC9A493B41014CAABB98F0471D759707
if ($baselayer == 'mapnik') $baselayerurl = 'http://tile.openstreetmap.org/{z}/{x}/{y}.png';
else if($baselayer == 'mapquest') $baselayerurl = 'http://otile1.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png';
else if($baselayer == 'cloudmade') $baselayerurl = 'http://{s}.tile.cloudmade.com/7807cc60c1354628aab5156cfc1d4b3b/997/256/{z}/{x}/{y}.png';
else if($baselayer == 'mapnikde') $baselayerurl = 'http://www.toolserver.org/tiles/germany/{z}/{x}/{y}.png';
else if($baselayer == 'mapnikfr') $baselayerurl = 'http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png';
else if($baselayer == 'custom') $baselayerurl = $custombaselayerurl;
// Generate Javascript
// ----------------------------------------
// no worldWarp (no world copies, restrict the view to one world)
if($noworldwarp)
{
$nowarp = "noWrap: true, ";
$worldcopyjump = "worldCopyJump: false, maxBounds: [ [82, -180], [-82, 180] ]";
}
else
{
$nowarp = "noWrap: false, ";
$worldcopyjump = "worldCopyJump: true";
}
/*
// Icons
$js = "\n
var LeafIcon = L.Icon.extend({
options: {
shadowUrl: 'plugins/piwigo-openstreetmap/leaflet/images/leaf-shadow.png',
iconSize: [38, 95],
shadowSize: [50, 64],
iconAnchor: [22, 94],
shadowAnchor: [4, 62],
popupAnchor: [-3, -76]
}
});
var mapIcon = L.Icon.extend({
options: {
shadowUrl: 'plugins/piwigo-openstreetmap/leaflet/images/mapicons-shadow.png',
iconSize: [32, 37],
shadowSize: [51, 37],
iconAnchor: [19, 38],
shadowAnchor: [-20, 33],
popupAnchor: [-2, -10]
}
});
var greenIcon = new LeafIcon({iconUrl: 'plugins/piwigo-openstreetmap/leaflet/images/leaf-green.png'}),
redIcon = new LeafIcon({iconUrl: 'plugins/piwigo-openstreetmap/leaflet/images/leaf-red.png'}),
orangeIcon = new LeafIcon({iconUrl: 'plugins/piwigo-openstreetmap/leaflet/images/leaf-orange.png'});
var bluemapicons = new mapIcon({iconUrl: 'plugins/piwigo-openstreetmap/leaflet/images/mapicons-blue.png'}),
greenmapicons = new mapIcon({iconUrl: 'plugins/piwigo-openstreetmap/leaflet/images/mapicons-green.png'});
";
*/
// Create the map and get a new map instance attached and element with id="tile-map"
$js = "\nvar map = new L.Map('map', {".$worldcopyjump."});\n";
$js .= "map.attributionControl.setPrefix('');\n";
$js .= "var baselayer = new L.TileLayer('".$baselayerurl."', {maxZoom: 18, ".$nowarp."attribution: '".$OSMCOPYRIGHT."'});\n";
$js .= "var coord = new L.LatLng(".$lat.", ".$lon.");\n";
$js .= "var marker = new L.Marker(coord);\n";
//$js .= "var marker = new L.Marker(coord, {icon: bluemapicons});\n";
$js .= "map.addLayer(marker);\n";
// Attribution Credit and Copyright
if($attrleaflet){ $js .= "map.attributionControl.addAttribution('".l10n('POWERBY')."
Leaflet');\n"; }
if($attrimagery){ $js .= "map.attributionControl.addAttribution('".l10n('IMAGERYBY')." ". imagery($baselayer, $custombaselayer)."');\n"; }
if($attrmodule){ $js .= "map.attributionControl.addAttribution('".l10n('PLUGINBY')."
xbgmsharp');\n"; }
// set map view
$js .= "map.setView(coord, ".$zoom.").addLayer(baselayer);\n";
// Select the template
$template->set_filenames(
array('osm_content' => dirname(__FILE__)."/template/osm-picture.tpl")
);
// Assign the template variables
$template->assign(
array(
'HEIGHT' => $height,
'OSMJS' => $js,
'OSM_PATH' => OSM_PATH,
'OSMNAME' => $osmname,
'OSMNAMECSS' => $osmnamecss,
'SHOWOSM' => $showosm,
'OSMLINK' => $osmlink,
)
);
// Return the rendered html
$osm_content = $template->parse('osm_content', true);
return $osm_content;
}