From ecfdb0ab23b04660bba3f22f66749e3e489c2871 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sun, 19 Feb 2012 14:28:43 +0100 Subject: [PATCH] Make OSM tile server configurable. This patch makes it possible to configure the tile server used for serving the OpenStreetMap maps. Add README with hints about the Tile Usage Policy (http://wiki.openstreetmap.org/wiki/Tile_usage_policy). A list of public available tile servers can be found here: http://wiki.openstreetmap.org/wiki/TMS You can also configure the default zoom level. --- openstreetmap/README | 30 +++++++++++++++++++++++++ openstreetmap/admin.tpl | 3 +++ openstreetmap/openstreetmap.php | 40 +++++++++++++++++++++++---------- 3 files changed, 61 insertions(+), 12 deletions(-) create mode 100644 openstreetmap/README create mode 100644 openstreetmap/admin.tpl diff --git a/openstreetmap/README b/openstreetmap/README new file mode 100644 index 000000000..41fc842c6 --- /dev/null +++ b/openstreetmap/README @@ -0,0 +1,30 @@ + ____ OpenStreetMap Plugin ____ +by Mike Macgirvin + Klaus Weidenbach + +This addon allows you to use OpenStreetMap for displaying locations. + +___ Requirements ___ + +To use this plugin you need a tile Server that provides the maps. +OpenStreetMap data is free for everyone to use. Their tile servers are not. +Please take a look at their "Tile Usage Policy": +http://wiki.openstreetmap.org/wiki/Tile_usage_policy +You can run your own tile server or choose one from their list of public +tile servers: http://wiki.openstreetmap.org/wiki/TMS +Support the OpenStreetMap community and share the load. + +___ Configuration ___ + +Open the .htconfig.php file and add "openstreetmap" to the list of activated +addons. + $a->config['system']['addon'] = "openstreetmap, ..." + +You have to add two configuration variables for the addon: + $a->config['openstreetmap']['tmsserver'] = 'http://www.openstreetmap.org/'; + $a->config['openstreetmap']['zoom'] = '18'; + +The *tmsserver* points to the tile server you want to use. Use the full URL, +with protocol (http/s) and trailing slash. You can configure the default zoom +level on the map with *zoom*. 1 will show the whole world and 18 is the highest +zoom level available. diff --git a/openstreetmap/admin.tpl b/openstreetmap/admin.tpl new file mode 100644 index 000000000..75db9cd7b --- /dev/null +++ b/openstreetmap/admin.tpl @@ -0,0 +1,3 @@ +{{ inc field_input.tpl with $field=$tmsserver }}{{ endinc }} +{{ inc field_input.tpl with $field=$zoom }}{{ endinc }} +
diff --git a/openstreetmap/openstreetmap.php b/openstreetmap/openstreetmap.php index ef5d6befb..ebe609785 100755 --- a/openstreetmap/openstreetmap.php +++ b/openstreetmap/openstreetmap.php @@ -1,45 +1,45 @@ - * + * Author: Klaus Weidenbach * */ - function openstreetmap_install() { - register_hook('render_location', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_location'); logger("installed openstreetmap"); } - function openstreetmap_uninstall() { - unregister_hook('render_location', 'addon/openstreetmap/openstreetmap.php', 'openstreetmap_location'); logger("removed openstreetmap"); } - function openstreetmap_location($a, &$item) { - if(! (strlen($item['location']) || strlen($item['coord']))) return; + /* + * Get the configuration variables from the .htconfig file. + */ + $tmsserver = get_config('openstreetmap','tmsserver'); + $zoom = get_config('openstreetmap','zoom'); + $location = ''; $coord = ''; - $location = (($item['location']) ? '' . $item['location'] . '' : ''); + $location = (($item['location']) ? '' . $item['location'] . '' : ''); if($item['coord']) { $coords = explode(' ', $item['coord']); if(count($coords) > 1) { - $coord = '' . $item['coord'] . '' ; + $coord = '' . $item['coord'] . '' ; } } if(strlen($coord)) { @@ -52,3 +52,19 @@ function openstreetmap_location($a, &$item) { return; } + +function openstreetmap_plugin_admin (&$a, &$o) { + $t = file_get_contents( dirname(__file__)."/admin.tpl"); + $o = replace_macros( $t, array( + '$submit' => t('Submit'), + '$tmsserver' => array('tmsserver', t('Tile Server URL'), get_config('openstreetmap','tmsserver' ), t('A list of public tile servers')), + '$zoom' => array('zoom', t('Default zoom'), get_config('openstreetmap','zoom' ), t('The default zoom level. (1:world, 18:highest)')), + )); +} +function openstreetmap_plugin_admin_post (&$a) { + $url = ((x($_POST, 'tmsserver')) ? notags(trim($_POST['tmsserver'])) : ''); + $zoom = ((x($_POST, 'zoom')) ? intval(trim($_POST['zoom'])) : '17'); + set_config('openstreetmap', 'tmsserver', $url); + set_config('openstreetmap', 'zoom', $zoom); + info( t('Settings updated.'). EOL); +}