From 5dc30229d433e1f0b11648b6813a5b1c2f9c2e94 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 30 Jun 2015 07:31:27 +0200 Subject: [PATCH] New plugin GoogleMaps, changed map format for OSM --- googlemaps/googlemaps.php | 41 +++++++++++++++++++++++++++++++++ openstreetmap/openstreetmap.php | 38 +++++++++++++----------------- 2 files changed, 57 insertions(+), 22 deletions(-) create mode 100644 googlemaps/googlemaps.php diff --git a/googlemaps/googlemaps.php b/googlemaps/googlemaps.php new file mode 100644 index 00000000..0b031f4d --- /dev/null +++ b/googlemaps/googlemaps.php @@ -0,0 +1,41 @@ + + * + */ + +require_once('include/cache.php'); + + +function googlemaps_install() { + register_hook('render_location', 'addon/googlemaps/googlemaps.php', 'googlemaps_location'); + + logger("installed googlemaps"); +} + +function googlemaps_uninstall() { + unregister_hook('render_location', 'addon/googlemaps/googlemaps.php', 'googlemaps_location'); + + logger("removed googlemaps"); +} + +function googlemaps_location($a, &$item) { + + if(! (strlen($item['location']) || strlen($item['coord']))) + return; + + if ($item['coord'] != "") + $target = "http://maps.google.com/?q=".urlencode($item['coord']); + else + $target = "http://maps.google.com/?q=".urlencode($item['location']); + + if ($item['location'] != "") + $title = $item['location']; + else + $title = $item['coord']; + + $item['html'] = ''.$title.''; +} diff --git a/openstreetmap/openstreetmap.php b/openstreetmap/openstreetmap.php index e805632a..13545169 100644 --- a/openstreetmap/openstreetmap.php +++ b/openstreetmap/openstreetmap.php @@ -51,7 +51,7 @@ function openstreetmap_location($a, &$item) { /* * Get the configuration variables from the config. - * @todo Separate the tile map server from the text-string to map tile server + * @todo Separate the tile map server from the text-string to map tile server * since they apparently use different URL conventions. * We use OSM's current convention of "#map=zoom/lat/lon" and optional * ?mlat=lat&mlon=lon for markers. @@ -73,31 +73,27 @@ function openstreetmap_location($a, &$item) { if(! $marker) $marker = 0; - $location = ''; - $coord = ''; - - $location = $item['location']; - - $location = (($location && (! $item['coord'])) ? '' . $item['location'] . '' : $location); - - if($item['coord']) { + if ($item['coord'] != "") { $coords = explode(' ', $item['coord']); if(count($coords) > 1) { $lat = urlencode(round($coords[0], 5)); $lon = urlencode(round($coords[1], 5)); - $coord = 'Map'; + $target .= '?mlat='.$lat.'&mlon='.$lon; + $target .= '#map='.intval($zoom).'/'.$lat.'/'.$lon; } } - if(strlen($coord)) { - if($location) - $location .= ' (' . $coord . ')'; - else - $location = '' . $coord . ''; - } - $item['html'] = $location; + + if ($target == "") + $target = $nomserver.'?q='.urlencode($item['location']); + + if ($item['location'] != "") + $title = $item['location']; + else + $title = $item['coord']; + + $item['html'] = ''.$title.''; } @@ -112,15 +108,13 @@ function openstreetmap_generate_named_map(&$a,&$b) { $x = z_fetch_url($nomserver . $args); if($x['success']) { $j = json_decode($x['body'],true); - + if($j && is_array($j) && $j[0]['lat'] && $j[0]['lon']) { $arr = array('lat' => $j[0]['lat'],'lon' => $j[0]['lon'],'location' => $b['location'], 'html' => ''); openstreetmap_generate_map($a,$arr); $b['html'] = $arr['html']; } } - - } function openstreetmap_generate_map(&$a,&$b) {