Merge pull request #270 from annando/1506-googlemaps

New addon GoogleMaps, changed map format for OSM
This commit is contained in:
fabrixxm 2015-06-30 08:33:16 +02:00
commit 9ea1e6184b
2 changed files with 57 additions and 22 deletions

41
googlemaps/googlemaps.php Normal file
View File

@ -0,0 +1,41 @@
<?php
/**
* Name: Google Maps
* Description: Use Google Maps for displaying locations. After activation the post location just beneath your avatar in your posts will link to Google Maps.
* Version: 0.1
* Author: Michael Vogel <https://pirati.ca/profile/heluecht>
*
*/
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'] = '<a target="map" title="'.$title.'" href= "'.$target.'">'.$title.'</a>';
}

View File

@ -51,7 +51,7 @@ function openstreetmap_location($a, &$item) {
/* /*
* Get the configuration variables from the config. * 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. * since they apparently use different URL conventions.
* We use OSM's current convention of "#map=zoom/lat/lon" and optional * We use OSM's current convention of "#map=zoom/lat/lon" and optional
* ?mlat=lat&mlon=lon for markers. * ?mlat=lat&mlon=lon for markers.
@ -73,31 +73,27 @@ function openstreetmap_location($a, &$item) {
if(! $marker) if(! $marker)
$marker = 0; $marker = 0;
$location = ''; if ($item['coord'] != "") {
$coord = '';
$location = $item['location'];
$location = (($location && (! $item['coord'])) ? '<a target="map" title="' . $item['location'] . '" href="'.$nomserver . '?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : $location);
if($item['coord']) {
$coords = explode(' ', $item['coord']); $coords = explode(' ', $item['coord']);
if(count($coords) > 1) { if(count($coords) > 1) {
$lat = urlencode(round($coords[0], 5)); $lat = urlencode(round($coords[0], 5));
$lon = urlencode(round($coords[1], 5)); $lon = urlencode(round($coords[1], 5));
$coord = '<a target="map" class="OSMMapLink" title="' . $item['coord'] . '" href="'. $tmsserver; $target = $tmsserver;
if($marker > 0) if($marker > 0)
$coord .= '?mlat=' . $lat . '&mlon=' . $lon; $target .= '?mlat='.$lat.'&mlon='.$lon;
$coord .= '#map=' . intval($zoom) . '/' . $lat . '/' . $lon .'">Map</a>'; $target .= '#map='.intval($zoom).'/'.$lat.'/'.$lon;
} }
} }
if(strlen($coord)) {
if($location) if ($target == "")
$location .= '&nbsp;<span class="smalltext">(' . $coord . ')</span>'; $target = $nomserver.'?q='.urlencode($item['location']);
else
$location = '<span class="smalltext">' . $coord . '</span>'; if ($item['location'] != "")
} $title = $item['location'];
$item['html'] = $location; else
$title = $item['coord'];
$item['html'] = '<a target="map" title="'.$title.'" href= "'.$target.'">'.$title.'</a>';
} }
@ -112,15 +108,13 @@ function openstreetmap_generate_named_map(&$a,&$b) {
$x = z_fetch_url($nomserver . $args); $x = z_fetch_url($nomserver . $args);
if($x['success']) { if($x['success']) {
$j = json_decode($x['body'],true); $j = json_decode($x['body'],true);
if($j && is_array($j) && $j[0]['lat'] && $j[0]['lon']) { 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' => ''); $arr = array('lat' => $j[0]['lat'],'lon' => $j[0]['lon'],'location' => $b['location'], 'html' => '');
openstreetmap_generate_map($a,$arr); openstreetmap_generate_map($a,$arr);
$b['html'] = $arr['html']; $b['html'] = $arr['html'];
} }
} }
} }
function openstreetmap_generate_map(&$a,&$b) { function openstreetmap_generate_map(&$a,&$b) {