@@ -24,98 +24,98 @@ |
||
| 24 | 24 | * @author Mark Prins |
| 25 | 25 | */ |
| 26 | 26 | class admin_plugin_openlayersmap_purge extends DokuWiki_Admin_Plugin { |
| 27 | - /** |
|
| 28 | - * (non-PHPdoc) |
|
| 29 | - * @see DokuWiki_Admin_Plugin::getMenuSort() |
|
| 30 | - */ |
|
| 31 | - public function getMenuSort(): int { |
|
| 32 | - return 800; |
|
| 33 | - } |
|
| 27 | + /** |
|
| 28 | + * (non-PHPdoc) |
|
| 29 | + * @see DokuWiki_Admin_Plugin::getMenuSort() |
|
| 30 | + */ |
|
| 31 | + public function getMenuSort(): int { |
|
| 32 | + return 800; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * (non-PHPdoc) |
|
| 37 | - * @see DokuWiki_Admin_Plugin::forAdminOnly() |
|
| 38 | - */ |
|
| 39 | - public function forAdminOnly(): bool { |
|
| 40 | - return true; |
|
| 41 | - } |
|
| 35 | + /** |
|
| 36 | + * (non-PHPdoc) |
|
| 37 | + * @see DokuWiki_Admin_Plugin::forAdminOnly() |
|
| 38 | + */ |
|
| 39 | + public function forAdminOnly(): bool { |
|
| 40 | + return true; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * (non-PHPdoc) |
|
| 45 | - * @see DokuWiki_Admin_Plugin::handle() |
|
| 46 | - */ |
|
| 47 | - public function handle() { |
|
| 48 | - global $conf; |
|
| 49 | - if(!isset($_REQUEST['continue']) || !checkSecurityToken()) return; |
|
| 50 | - if(isset($_REQUEST['purgetiles'])) { |
|
| 51 | - $path = $conf['cachedir'] . '/olmaptiles'; |
|
| 52 | - if($this->rrmdir($path)) msg($this->getLang('admin_purged_tiles'), 0); |
|
| 53 | - } |
|
| 54 | - if(isset($_REQUEST['purgemaps'])) { |
|
| 55 | - $path = $conf['mediadir'] . '/olmapmaps'; |
|
| 56 | - if($this->rrmdir($path)) msg($this->getLang('admin_purged_maps'), 0); |
|
| 57 | - } |
|
| 58 | - } |
|
| 43 | + /** |
|
| 44 | + * (non-PHPdoc) |
|
| 45 | + * @see DokuWiki_Admin_Plugin::handle() |
|
| 46 | + */ |
|
| 47 | + public function handle() { |
|
| 48 | + global $conf; |
|
| 49 | + if(!isset($_REQUEST['continue']) || !checkSecurityToken()) return; |
|
| 50 | + if(isset($_REQUEST['purgetiles'])) { |
|
| 51 | + $path = $conf['cachedir'] . '/olmaptiles'; |
|
| 52 | + if($this->rrmdir($path)) msg($this->getLang('admin_purged_tiles'), 0); |
|
| 53 | + } |
|
| 54 | + if(isset($_REQUEST['purgemaps'])) { |
|
| 55 | + $path = $conf['mediadir'] . '/olmapmaps'; |
|
| 56 | + if($this->rrmdir($path)) msg($this->getLang('admin_purged_maps'), 0); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Recursively delete the directory. |
|
| 62 | - * @param string $sDir directory path |
|
| 63 | - * @return boolean true when succesful |
|
| 64 | - */ |
|
| 65 | - private function rrmdir($sDir): bool { |
|
| 66 | - if(is_dir($sDir)) { |
|
| 67 | - dbglog($sDir, 'admin_plugin_openlayersmap_purge::rrmdir: recursively removing path: '); |
|
| 68 | - $sDir = rtrim($sDir, '/'); |
|
| 69 | - $oDir = dir($sDir); |
|
| 70 | - while(($sFile = $oDir->read()) !== false) { |
|
| 71 | - if($sFile != '.' && $sFile != '..') { |
|
| 72 | - (!is_link("$sDir/$sFile") && is_dir("$sDir/$sFile")) ? |
|
| 73 | - $this->rrmdir("$sDir/$sFile") : unlink("$sDir/$sFile"); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - $oDir->close(); |
|
| 77 | - rmdir($sDir); |
|
| 78 | - return true; |
|
| 79 | - } |
|
| 80 | - return false; |
|
| 81 | - } |
|
| 60 | + /** |
|
| 61 | + * Recursively delete the directory. |
|
| 62 | + * @param string $sDir directory path |
|
| 63 | + * @return boolean true when succesful |
|
| 64 | + */ |
|
| 65 | + private function rrmdir($sDir): bool { |
|
| 66 | + if(is_dir($sDir)) { |
|
| 67 | + dbglog($sDir, 'admin_plugin_openlayersmap_purge::rrmdir: recursively removing path: '); |
|
| 68 | + $sDir = rtrim($sDir, '/'); |
|
| 69 | + $oDir = dir($sDir); |
|
| 70 | + while(($sFile = $oDir->read()) !== false) { |
|
| 71 | + if($sFile != '.' && $sFile != '..') { |
|
| 72 | + (!is_link("$sDir/$sFile") && is_dir("$sDir/$sFile")) ? |
|
| 73 | + $this->rrmdir("$sDir/$sFile") : unlink("$sDir/$sFile"); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + $oDir->close(); |
|
| 77 | + rmdir($sDir); |
|
| 78 | + return true; |
|
| 79 | + } |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * (non-PHPdoc) |
|
| 85 | - * @see DokuWiki_Admin_Plugin::html() |
|
| 86 | - */ |
|
| 87 | - public function html() { |
|
| 88 | - echo $this->locale_xhtml('admin_intro'); |
|
| 89 | - $form = new Doku_Form(array('id' => 'olmap_purgeform', 'method' => 'post')); |
|
| 90 | - $form->addHidden('continue', 'go'); |
|
| 83 | + /** |
|
| 84 | + * (non-PHPdoc) |
|
| 85 | + * @see DokuWiki_Admin_Plugin::html() |
|
| 86 | + */ |
|
| 87 | + public function html() { |
|
| 88 | + echo $this->locale_xhtml('admin_intro'); |
|
| 89 | + $form = new Doku_Form(array('id' => 'olmap_purgeform', 'method' => 'post')); |
|
| 90 | + $form->addHidden('continue', 'go'); |
|
| 91 | 91 | |
| 92 | - $form->startFieldset($this->getLang('admin_tiles')); |
|
| 93 | - $form->addElement('<p>'); |
|
| 94 | - $form->addElement( |
|
| 95 | - '<input id="purgetiles" name="purgetiles" type="checkbox" value="1" class="checkbox" />' |
|
| 96 | - ); |
|
| 97 | - $form->addElement( |
|
| 98 | - '<label for="purgetiles" class="label">' . $this->getLang('admin_purge_tiles') |
|
| 99 | - . '</label>' |
|
| 100 | - ); |
|
| 101 | - $form->addElement('</p>'); |
|
| 102 | - $form->endFieldset(); |
|
| 92 | + $form->startFieldset($this->getLang('admin_tiles')); |
|
| 93 | + $form->addElement('<p>'); |
|
| 94 | + $form->addElement( |
|
| 95 | + '<input id="purgetiles" name="purgetiles" type="checkbox" value="1" class="checkbox" />' |
|
| 96 | + ); |
|
| 97 | + $form->addElement( |
|
| 98 | + '<label for="purgetiles" class="label">' . $this->getLang('admin_purge_tiles') |
|
| 99 | + . '</label>' |
|
| 100 | + ); |
|
| 101 | + $form->addElement('</p>'); |
|
| 102 | + $form->endFieldset(); |
|
| 103 | 103 | |
| 104 | - $form->startFieldset($this->getLang('admin_maps')); |
|
| 105 | - $form->addElement('<p>'); |
|
| 106 | - $form->addElement('<input id="purgemaps" name="purgemaps" type="checkbox" value="1" class="checkbox" />'); |
|
| 107 | - $form->addElement( |
|
| 108 | - '<label for="purgemaps" class="label">' . $this->getLang('admin_purge_maps') . '</label>' |
|
| 109 | - ); |
|
| 110 | - $form->addElement('</p>'); |
|
| 111 | - $form->endFieldset(); |
|
| 104 | + $form->startFieldset($this->getLang('admin_maps')); |
|
| 105 | + $form->addElement('<p>'); |
|
| 106 | + $form->addElement('<input id="purgemaps" name="purgemaps" type="checkbox" value="1" class="checkbox" />'); |
|
| 107 | + $form->addElement( |
|
| 108 | + '<label for="purgemaps" class="label">' . $this->getLang('admin_purge_maps') . '</label>' |
|
| 109 | + ); |
|
| 110 | + $form->addElement('</p>'); |
|
| 111 | + $form->endFieldset(); |
|
| 112 | 112 | |
| 113 | - $form->addElement( |
|
| 114 | - form_makeButton( |
|
| 115 | - 'submit', 'admin', $this->getLang('admin_submit'), |
|
| 116 | - array('accesskey' => 'p', 'title' => $this->getLang('admin_submit')) |
|
| 117 | - ) |
|
| 118 | - ); |
|
| 119 | - $form->printForm(); |
|
| 120 | - } |
|
| 113 | + $form->addElement( |
|
| 114 | + form_makeButton( |
|
| 115 | + 'submit', 'admin', $this->getLang('admin_submit'), |
|
| 116 | + array('accesskey' => 'p', 'title' => $this->getLang('admin_submit')) |
|
| 117 | + ) |
|
| 118 | + ); |
|
| 119 | + $form->printForm(); |
|
| 120 | + } |
|
| 121 | 121 | } |
@@ -46,14 +46,14 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function handle() { |
| 48 | 48 | global $conf; |
| 49 | - if(!isset($_REQUEST['continue']) || !checkSecurityToken()) return; |
|
| 50 | - if(isset($_REQUEST['purgetiles'])) { |
|
| 51 | - $path = $conf['cachedir'] . '/olmaptiles'; |
|
| 52 | - if($this->rrmdir($path)) msg($this->getLang('admin_purged_tiles'), 0); |
|
| 49 | + if (!isset($_REQUEST['continue']) || !checkSecurityToken()) return; |
|
| 50 | + if (isset($_REQUEST['purgetiles'])) { |
|
| 51 | + $path = $conf['cachedir'].'/olmaptiles'; |
|
| 52 | + if ($this->rrmdir($path)) msg($this->getLang('admin_purged_tiles'), 0); |
|
| 53 | 53 | } |
| 54 | - if(isset($_REQUEST['purgemaps'])) { |
|
| 55 | - $path = $conf['mediadir'] . '/olmapmaps'; |
|
| 56 | - if($this->rrmdir($path)) msg($this->getLang('admin_purged_maps'), 0); |
|
| 54 | + if (isset($_REQUEST['purgemaps'])) { |
|
| 55 | + $path = $conf['mediadir'].'/olmapmaps'; |
|
| 56 | + if ($this->rrmdir($path)) msg($this->getLang('admin_purged_maps'), 0); |
|
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | |
@@ -63,12 +63,12 @@ discard block |
||
| 63 | 63 | * @return boolean true when succesful |
| 64 | 64 | */ |
| 65 | 65 | private function rrmdir($sDir): bool { |
| 66 | - if(is_dir($sDir)) { |
|
| 66 | + if (is_dir($sDir)) { |
|
| 67 | 67 | dbglog($sDir, 'admin_plugin_openlayersmap_purge::rrmdir: recursively removing path: '); |
| 68 | 68 | $sDir = rtrim($sDir, '/'); |
| 69 | 69 | $oDir = dir($sDir); |
| 70 | - while(($sFile = $oDir->read()) !== false) { |
|
| 71 | - if($sFile != '.' && $sFile != '..') { |
|
| 70 | + while (($sFile = $oDir->read()) !== false) { |
|
| 71 | + if ($sFile != '.' && $sFile != '..') { |
|
| 72 | 72 | (!is_link("$sDir/$sFile") && is_dir("$sDir/$sFile")) ? |
| 73 | 73 | $this->rrmdir("$sDir/$sFile") : unlink("$sDir/$sFile"); |
| 74 | 74 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | '<input id="purgetiles" name="purgetiles" type="checkbox" value="1" class="checkbox" />' |
| 96 | 96 | ); |
| 97 | 97 | $form->addElement( |
| 98 | - '<label for="purgetiles" class="label">' . $this->getLang('admin_purge_tiles') |
|
| 98 | + '<label for="purgetiles" class="label">'.$this->getLang('admin_purge_tiles') |
|
| 99 | 99 | . '</label>' |
| 100 | 100 | ); |
| 101 | 101 | $form->addElement('</p>'); |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | $form->addElement('<p>'); |
| 106 | 106 | $form->addElement('<input id="purgemaps" name="purgemaps" type="checkbox" value="1" class="checkbox" />'); |
| 107 | 107 | $form->addElement( |
| 108 | - '<label for="purgemaps" class="label">' . $this->getLang('admin_purge_maps') . '</label>' |
|
| 108 | + '<label for="purgemaps" class="label">'.$this->getLang('admin_purge_maps').'</label>' |
|
| 109 | 109 | ); |
| 110 | 110 | $form->addElement('</p>'); |
| 111 | 111 | $form->endFieldset(); |
@@ -46,14 +46,20 @@ |
||
| 46 | 46 | */ |
| 47 | 47 | public function handle() { |
| 48 | 48 | global $conf; |
| 49 | - if(!isset($_REQUEST['continue']) || !checkSecurityToken()) return; |
|
| 49 | + if(!isset($_REQUEST['continue']) || !checkSecurityToken()) { |
|
| 50 | + return; |
|
| 51 | + } |
|
| 50 | 52 | if(isset($_REQUEST['purgetiles'])) { |
| 51 | 53 | $path = $conf['cachedir'] . '/olmaptiles'; |
| 52 | - if($this->rrmdir($path)) msg($this->getLang('admin_purged_tiles'), 0); |
|
| 54 | + if($this->rrmdir($path)) { |
|
| 55 | + msg($this->getLang('admin_purged_tiles'), 0); |
|
| 56 | + } |
|
| 53 | 57 | } |
| 54 | 58 | if(isset($_REQUEST['purgemaps'])) { |
| 55 | 59 | $path = $conf['mediadir'] . '/olmapmaps'; |
| 56 | - if($this->rrmdir($path)) msg($this->getLang('admin_purged_maps'), 0); |
|
| 60 | + if($this->rrmdir($path)) { |
|
| 61 | + msg($this->getLang('admin_purged_maps'), 0); |
|
| 62 | + } |
|
| 57 | 63 | } |
| 58 | 64 | } |
| 59 | 65 | |
@@ -22,72 +22,72 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | |
| 24 | 24 | $meta['enableOSM'] = array( |
| 25 | - 'onoff' |
|
| 25 | + 'onoff' |
|
| 26 | 26 | ); |
| 27 | 27 | $meta['enableStamen'] = array( |
| 28 | - 'onoff' |
|
| 28 | + 'onoff' |
|
| 29 | 29 | ); |
| 30 | 30 | $meta['enableGoogle'] = array( |
| 31 | - 'onoff' |
|
| 31 | + 'onoff' |
|
| 32 | 32 | ); |
| 33 | 33 | $meta['googleAPIkey'] = array( |
| 34 | - 'string' |
|
| 34 | + 'string' |
|
| 35 | 35 | ); |
| 36 | 36 | $meta['enableBing'] = array( |
| 37 | - 'onoff' |
|
| 37 | + 'onoff' |
|
| 38 | 38 | ); |
| 39 | 39 | $meta['bingAPIKey'] = array( |
| 40 | - 'string' |
|
| 40 | + 'string' |
|
| 41 | 41 | ); |
| 42 | 42 | $meta['tfApiKey'] = array( |
| 43 | - 'string' |
|
| 43 | + 'string' |
|
| 44 | 44 | ); |
| 45 | 45 | $meta['iconUrlOverload'] = array( |
| 46 | - 'string' |
|
| 46 | + 'string' |
|
| 47 | 47 | ); |
| 48 | 48 | $meta['enableA11y'] = array( |
| 49 | - 'onoff' |
|
| 49 | + 'onoff' |
|
| 50 | 50 | ); |
| 51 | 51 | $meta['optionStaticMapGenerator'] = array( |
| 52 | - 'multichoice', '_choices' => array('local', 'remote') |
|
| 52 | + 'multichoice', '_choices' => array('local', 'remote') |
|
| 53 | 53 | ); |
| 54 | 54 | $meta['autoZoomMap'] = array( |
| 55 | - 'onoff' |
|
| 55 | + 'onoff' |
|
| 56 | 56 | ); |
| 57 | 57 | $meta ['displayformat'] = array( |
| 58 | - 'multichoice', '_choices' => array('DD', 'DMS') |
|
| 58 | + 'multichoice', '_choices' => array('DD', 'DMS') |
|
| 59 | 59 | ); |
| 60 | 60 | |
| 61 | 61 | $meta ['default_width'] = array( |
| 62 | - 'string' |
|
| 62 | + 'string' |
|
| 63 | 63 | ); |
| 64 | 64 | $meta ['default_height'] = array( |
| 65 | - 'string' |
|
| 65 | + 'string' |
|
| 66 | 66 | ); |
| 67 | 67 | $meta ['default_zoom'] = array( |
| 68 | - 'string' |
|
| 68 | + 'string' |
|
| 69 | 69 | ); |
| 70 | 70 | $meta ['default_autozoom'] = array( |
| 71 | - 'onoff' |
|
| 71 | + 'onoff' |
|
| 72 | 72 | ); |
| 73 | 73 | $meta ['default_statusbar'] = array( |
| 74 | - 'onoff' |
|
| 74 | + 'onoff' |
|
| 75 | 75 | ); |
| 76 | 76 | $meta ['default_toolbar'] = array( |
| 77 | - 'onoff' |
|
| 77 | + 'onoff' |
|
| 78 | 78 | ); |
| 79 | 79 | $meta ['default_controls'] = array( |
| 80 | - 'onoff' |
|
| 80 | + 'onoff' |
|
| 81 | 81 | ); |
| 82 | 82 | $meta ['default_poihoverstyle'] = array( |
| 83 | - 'onoff' |
|
| 83 | + 'onoff' |
|
| 84 | 84 | ); |
| 85 | 85 | $meta ['default_kmlfile'] = array( |
| 86 | - 'string' |
|
| 86 | + 'string' |
|
| 87 | 87 | ); |
| 88 | 88 | $meta ['default_gpxfile'] = array( |
| 89 | - 'string' |
|
| 89 | + 'string' |
|
| 90 | 90 | ); |
| 91 | 91 | $meta ['default_geojsonfile'] = array( |
| 92 | - 'string' |
|
| 92 | + 'string' |
|
| 93 | 93 | ); |
@@ -27,703 +27,703 @@ |
||
| 27 | 27 | * |
| 28 | 28 | */ |
| 29 | 29 | class StaticMap { |
| 30 | - // this should probably not be changed |
|
| 31 | - var $doc = ''; |
|
| 32 | - |
|
| 33 | - // the final output |
|
| 34 | - protected $tileSize = 256; |
|
| 35 | - protected $tileInfo = array( |
|
| 36 | - // OSM sources |
|
| 37 | - 'openstreetmap' => array( |
|
| 38 | - 'txt' => '(c) OpenStreetMap CC-BY-SA', |
|
| 39 | - 'logo' => 'osm_logo.png', |
|
| 40 | - 'url' => 'https://tile.openstreetmap.org/{Z}/{X}/{Y}.png' |
|
| 41 | - ), |
|
| 42 | - // OCM sources |
|
| 43 | - 'cycle' => array( |
|
| 44 | - 'txt' => 'OpenCycleMap tiles', |
|
| 45 | - 'logo' => 'cycle_logo.png', |
|
| 46 | - 'url' => 'https://tile.thunderforest.com/cycle/{Z}/{X}/{Y}.png?apikey=' |
|
| 47 | - ), |
|
| 48 | - 'transport' => array( |
|
| 49 | - 'txt' => 'OpenCycleMap tiles', |
|
| 50 | - 'logo' => 'cycle_logo.png', |
|
| 51 | - 'url' => 'https://tile.thunderforest.com/transport/{Z}/{X}/{Y}.png?apikey=' |
|
| 52 | - ), |
|
| 53 | - 'landscape' => array( |
|
| 54 | - 'txt' => 'OpenCycleMap tiles', |
|
| 55 | - 'logo' => 'cycle_logo.png', |
|
| 56 | - 'url' => 'https://tile.thunderforest.com/landscape/{Z}/{X}/{Y}.png?apikey=' |
|
| 57 | - ), |
|
| 58 | - 'outdoors' => array( |
|
| 59 | - 'txt' => 'OpenCycleMap tiles', |
|
| 60 | - 'logo' => 'cycle_logo.png', |
|
| 61 | - 'url' => 'https://tile.thunderforest.com/outdoors/{Z}/{X}/{Y}.png?apikey=' |
|
| 62 | - ), |
|
| 63 | - 'toner-lite' => array( |
|
| 64 | - 'txt' => 'Stamen tiles', |
|
| 65 | - 'logo' => 'stamen.png', |
|
| 66 | - 'url' => 'http://tile.stamen.com/toner-lite/{Z}/{X}/{Y}.png' |
|
| 67 | - ), |
|
| 68 | - 'terrain' => array( |
|
| 69 | - 'txt' => 'Stamen tiles', |
|
| 70 | - 'logo' => 'stamen.png', |
|
| 71 | - 'url' => 'http://tile.stamen.com/terrain/{Z}/{X}/{Y}.png' |
|
| 72 | - ) |
|
| 73 | - //, |
|
| 74 | - // 'piste'=>array( |
|
| 75 | - // 'txt'=>'OpenPisteMap tiles', |
|
| 76 | - // 'logo'=>'piste_logo.png', |
|
| 77 | - // 'url'=>''), |
|
| 78 | - // 'sea'=>array( |
|
| 79 | - // 'txt'=>'OpenSeaMap tiles', |
|
| 80 | - // 'logo'=>'sea_logo.png', |
|
| 81 | - // 'url'=>''), |
|
| 82 | - // H&B sources |
|
| 83 | - // 'hikeandbike' => array ( |
|
| 84 | - // 'txt' => 'Hike & Bike Map', |
|
| 85 | - // 'logo' => 'hnb_logo.png', |
|
| 86 | - // //'url' => 'http://toolserver.org/tiles/hikebike/{Z}/{X}/{Y}.png' |
|
| 87 | - // //moved to: https://www.toolserver.org/tiles/hikebike/12/2105/1388.png |
|
| 88 | - // 'url' => 'http://c.tiles.wmflabs.org/hikebike/{Z}/{X}/{Y}.png' |
|
| 89 | - // ) |
|
| 90 | - ); |
|
| 91 | - protected $tileDefaultSrc = 'openstreetmap'; |
|
| 92 | - |
|
| 93 | - // set up markers |
|
| 94 | - protected $markerPrototypes = array( |
|
| 95 | - // found at http://www.mapito.net/map-marker-icons.html |
|
| 96 | - // these are 17x19 px with a pointer at the bottom left |
|
| 97 | - 'lightblue' => array( |
|
| 98 | - 'regex' => '/^lightblue([0-9]+)$/', |
|
| 99 | - 'extension' => '.png', |
|
| 100 | - 'shadow' => false, |
|
| 101 | - 'offsetImage' => '0,-19', |
|
| 102 | - 'offsetShadow' => false |
|
| 103 | - ), |
|
| 104 | - // openlayers std markers are 21x25px with shadow |
|
| 105 | - 'ol-marker' => array( |
|
| 106 | - 'regex' => '/^marker(|-blue|-gold|-green|-red)+$/', |
|
| 107 | - 'extension' => '.png', |
|
| 108 | - 'shadow' => 'marker_shadow.png', |
|
| 109 | - 'offsetImage' => '-10,-25', |
|
| 110 | - 'offsetShadow' => '-1,-13' |
|
| 111 | - ), |
|
| 112 | - // these are 16x16 px |
|
| 113 | - 'ww_icon' => array( |
|
| 114 | - 'regex' => '/ww_\S+$/', |
|
| 115 | - 'extension' => '.png', |
|
| 116 | - 'shadow' => false, |
|
| 117 | - 'offsetImage' => '-8,-8', |
|
| 118 | - 'offsetShadow' => false |
|
| 119 | - ), |
|
| 120 | - // assume these are 16x16 px |
|
| 121 | - 'rest' => array( |
|
| 122 | - 'regex' => '/^(?!lightblue([0-9]+)$)(?!(ww_\S+$))(?!marker(|-blue|-gold|-green|-red)+$)(.*)/', |
|
| 123 | - 'extension' => '.png', |
|
| 124 | - 'shadow' => 'marker_shadow.png', |
|
| 125 | - 'offsetImage' => '-8,-8', |
|
| 126 | - 'offsetShadow' => '-1,-1' |
|
| 127 | - ) |
|
| 128 | - ); |
|
| 129 | - protected $centerX, $centerY, $offsetX, $offsetY, $image; |
|
| 130 | - protected $zoom, $lat, $lon, $width, $height, $markers, $maptype, $kmlFileName, $gpxFileName, $geojsonFileName, |
|
| 131 | - $autoZoomExtent, $apikey; |
|
| 132 | - protected $tileCacheBaseDir, $mapCacheBaseDir, $mediaBaseDir; |
|
| 133 | - protected $useTileCache = true; |
|
| 134 | - protected $mapCacheID = ''; |
|
| 135 | - protected $mapCacheFile = ''; |
|
| 136 | - protected $mapCacheExtension = 'png'; |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Constructor. |
|
| 140 | - * |
|
| 141 | - * @param float $lat |
|
| 142 | - * Latitude (x) of center of map |
|
| 143 | - * @param float $lon |
|
| 144 | - * Longitude (y) of center of map |
|
| 145 | - * @param int $zoom |
|
| 146 | - * Zoomlevel |
|
| 147 | - * @param int $width |
|
| 148 | - * Width in pixels |
|
| 149 | - * @param int $height |
|
| 150 | - * Height in pixels |
|
| 151 | - * @param string $maptype |
|
| 152 | - * Name of the map |
|
| 153 | - * @param mixed $markers |
|
| 154 | - * array of markers |
|
| 155 | - * @param string $gpx |
|
| 156 | - * GPX filename |
|
| 157 | - * @param string $kml |
|
| 158 | - * KML filename |
|
| 159 | - * @param string $mediaDir |
|
| 160 | - * Directory to store/cache maps |
|
| 161 | - * @param string $tileCacheBaseDir |
|
| 162 | - * Directory to cache map tiles |
|
| 163 | - * @param boolean $autoZoomExtent |
|
| 164 | - * Wheter or not to override zoom/lat/lon and zoom to the extent of gpx/kml and markers |
|
| 165 | - * @param apikey |
|
| 166 | - * Some service require a key to access |
|
| 167 | - */ |
|
| 168 | - public function __construct($lat, $lon, $zoom, $width, $height, $maptype, $markers, $gpx, $kml, $geojson, |
|
| 169 | - $mediaDir, $tileCacheBaseDir, $autoZoomExtent = true, $apikey = '') { |
|
| 170 | - $this->zoom = $zoom; |
|
| 171 | - $this->lat = $lat; |
|
| 172 | - $this->lon = $lon; |
|
| 173 | - $this->width = $width; |
|
| 174 | - $this->height = $height; |
|
| 175 | - // validate + set maptype |
|
| 176 | - $this->maptype = $this->tileDefaultSrc; |
|
| 177 | - if(array_key_exists($maptype, $this->tileInfo)) { |
|
| 178 | - $this->maptype = $maptype; |
|
| 179 | - } |
|
| 180 | - $this->markers = $markers; |
|
| 181 | - $this->kmlFileName = $kml; |
|
| 182 | - $this->gpxFileName = $gpx; |
|
| 183 | - $this->geojsonFileName = $geojson; |
|
| 184 | - $this->mediaBaseDir = $mediaDir; |
|
| 185 | - $this->tileCacheBaseDir = $tileCacheBaseDir . '/olmaptiles'; |
|
| 186 | - $this->useTileCache = $this->tileCacheBaseDir !== ''; |
|
| 187 | - $this->mapCacheBaseDir = $mediaDir . '/olmapmaps'; |
|
| 188 | - $this->autoZoomExtent = $autoZoomExtent; |
|
| 189 | - $this->apikey = $apikey; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * get the map, this may return a reference to a cached copy. |
|
| 194 | - * |
|
| 195 | - * @return string url relative to media dir |
|
| 196 | - */ |
|
| 197 | - public function getMap() { |
|
| 198 | - try { |
|
| 199 | - if($this->autoZoomExtent) { |
|
| 200 | - $this->autoZoom(); |
|
| 201 | - } |
|
| 202 | - } catch(Exception $e) { |
|
| 203 | - dbglog($e); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - // use map cache, so check cache for map |
|
| 207 | - if(!$this->checkMapCache()) { |
|
| 208 | - // map is not in cache, needs to be build |
|
| 209 | - $this->makeMap(); |
|
| 210 | - $this->mkdir_recursive(dirname($this->mapCacheIDToFilename()), 0777); |
|
| 211 | - imagepng($this->image, $this->mapCacheIDToFilename(), 9); |
|
| 212 | - } |
|
| 213 | - $this->doc = $this->mapCacheIDToFilename(); |
|
| 214 | - // make url relative to media dir |
|
| 215 | - return str_replace($this->mediaBaseDir, '', $this->doc); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Calculate the lat/lon/zoom values to make sure that all of the markers and gpx/kml are on the map. |
|
| 220 | - * can throw an error like |
|
| 221 | - * "Fatal error: Uncaught Exception: Cannot create a collection with non-geometries in |
|
| 222 | - * D:\www\wild-water.nl\www\dokuwiki\lib\plugins\geophp\geoPHP\lib\geometry\Collection.class.php:29" |
|
| 223 | - * |
|
| 224 | - * @param float $paddingFactor |
|
| 225 | - * buffer constant to enlarge (>1.0) the zoom level |
|
| 226 | - */ |
|
| 227 | - private function autoZoom($paddingFactor = 1.0) { |
|
| 228 | - $geoms = array(); |
|
| 229 | - $geoms [] = new Point ($this->lon, $this->lat); |
|
| 230 | - if(!empty ($this->markers)) { |
|
| 231 | - foreach($this->markers as $marker) { |
|
| 232 | - $geoms [] = new Point ($marker ['lon'], $marker ['lat']); |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - $g = false; |
|
| 236 | - if(file_exists($this->kmlFileName)) { |
|
| 237 | - $g = geoPHP::load(file_get_contents($this->kmlFileName), 'kml'); |
|
| 238 | - if($g !== false) { |
|
| 239 | - $geoms [] = $g; |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - if(file_exists($this->gpxFileName)) { |
|
| 243 | - $g = geoPHP::load(file_get_contents($this->gpxFileName), 'gpx'); |
|
| 244 | - if($g !== false) { |
|
| 245 | - $geoms [] = $g; |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - if(file_exists($this->geojsonFileName)) { |
|
| 249 | - $g = geoPHP::load(file_get_contents($this->geojsonFileName), 'geojson'); |
|
| 250 | - if($g !== false) { |
|
| 251 | - $geoms [] = $g; |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - if(count($geoms) <= 1) { |
|
| 256 | - dbglog($geoms, "StaticMap::autoZoom: Skip setting autozoom options"); |
|
| 257 | - return; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - $geom = new GeometryCollection ($geoms); |
|
| 261 | - $centroid = $geom->centroid(); |
|
| 262 | - $bbox = $geom->getBBox(); |
|
| 263 | - |
|
| 264 | - // determine vertical resolution, this depends on the distance from the equator |
|
| 265 | - // $vy00 = log(tan(M_PI*(0.25 + $centroid->getY()/360))); |
|
| 266 | - $vy0 = log(tan(M_PI * (0.25 + $bbox ['miny'] / 360))); |
|
| 267 | - $vy1 = log(tan(M_PI * (0.25 + $bbox ['maxy'] / 360))); |
|
| 268 | - dbglog("StaticMap::autoZoom: vertical resolution: $vy0, $vy1"); |
|
| 269 | - $zoomFactorPowered = ($this->height / 2) / (40.7436654315252 * ($vy1 - $vy0)); |
|
| 270 | - $resolutionVertical = 360 / ($zoomFactorPowered * $this->tileSize); |
|
| 271 | - // determine horizontal resolution |
|
| 272 | - $resolutionHorizontal = ($bbox ['maxx'] - $bbox ['minx']) / $this->width; |
|
| 273 | - $resolution = max($resolutionHorizontal, $resolutionVertical) * $paddingFactor; |
|
| 274 | - $zoom = log(360 / ($resolution * $this->tileSize), 2); |
|
| 275 | - |
|
| 276 | - if(is_finite($zoom) && $zoom < 15 && $zoom > 2) { |
|
| 277 | - $this->zoom = floor($zoom); |
|
| 278 | - } |
|
| 279 | - $this->lon = $centroid->getX(); |
|
| 280 | - $this->lat = $centroid->getY(); |
|
| 281 | - dbglog("StaticMap::autoZoom: Set autozoom options to: z: $this->zoom, lon: $this->lon, lat: $this->lat"); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - public function checkMapCache() { |
|
| 285 | - $this->mapCacheID = md5($this->serializeParams()); |
|
| 286 | - $filename = $this->mapCacheIDToFilename(); |
|
| 287 | - if(file_exists($filename)) |
|
| 288 | - return true; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - public function serializeParams() { |
|
| 292 | - return join( |
|
| 293 | - "&", array( |
|
| 294 | - $this->zoom, |
|
| 295 | - $this->lat, |
|
| 296 | - $this->lon, |
|
| 297 | - $this->width, |
|
| 298 | - $this->height, |
|
| 299 | - serialize($this->markers), |
|
| 300 | - $this->maptype, |
|
| 301 | - $this->kmlFileName, |
|
| 302 | - $this->gpxFileName, |
|
| 303 | - $this->geojsonFileName |
|
| 304 | - ) |
|
| 305 | - ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - public function mapCacheIDToFilename() { |
|
| 309 | - if(!$this->mapCacheFile) { |
|
| 310 | - $this->mapCacheFile = $this->mapCacheBaseDir . "/" . $this->maptype . "/" . $this->zoom . "/cache_" |
|
| 311 | - . substr($this->mapCacheID, 0, 2) . "/" . substr($this->mapCacheID, 2, 2) |
|
| 312 | - . "/" . substr($this->mapCacheID, 4); |
|
| 313 | - } |
|
| 314 | - return $this->mapCacheFile . "." . $this->mapCacheExtension; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * make the map. |
|
| 319 | - */ |
|
| 320 | - public function makeMap() { |
|
| 321 | - $this->initCoords(); |
|
| 322 | - $this->createBaseMap(); |
|
| 323 | - if(!empty ($this->markers)) |
|
| 324 | - $this->placeMarkers(); |
|
| 325 | - if(file_exists($this->kmlFileName)) |
|
| 326 | - $this->drawKML(); |
|
| 327 | - if(file_exists($this->gpxFileName)) |
|
| 328 | - $this->drawGPX(); |
|
| 329 | - if(file_exists($this->geojsonFileName)) |
|
| 330 | - $this->drawGeojson(); |
|
| 331 | - |
|
| 332 | - $this->drawCopyright(); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - */ |
|
| 337 | - public function initCoords() { |
|
| 338 | - $this->centerX = $this->lonToTile($this->lon, $this->zoom); |
|
| 339 | - $this->centerY = $this->latToTile($this->lat, $this->zoom); |
|
| 340 | - $this->offsetX = floor((floor($this->centerX) - $this->centerX) * $this->tileSize); |
|
| 341 | - $this->offsetY = floor((floor($this->centerY) - $this->centerY) * $this->tileSize); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * |
|
| 346 | - * @param number $long |
|
| 347 | - * @param number $zoom |
|
| 348 | - * @return number |
|
| 349 | - */ |
|
| 350 | - public function lonToTile($long, $zoom) { |
|
| 351 | - return (($long + 180) / 360) * pow(2, $zoom); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * |
|
| 356 | - * @param number $lat |
|
| 357 | - * @param number $zoom |
|
| 358 | - * @return float|int |
|
| 359 | - */ |
|
| 360 | - public function latToTile($lat, $zoom) { |
|
| 361 | - return (1 - log(tan($lat * pi() / 180) + 1 / cos($lat * M_PI / 180)) / M_PI) / 2 * pow(2, $zoom); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * make basemap image. |
|
| 366 | - */ |
|
| 367 | - public function createBaseMap() { |
|
| 368 | - $this->image = imagecreatetruecolor($this->width, $this->height); |
|
| 369 | - $startX = floor($this->centerX - ($this->width / $this->tileSize) / 2); |
|
| 370 | - $startY = floor($this->centerY - ($this->height / $this->tileSize) / 2); |
|
| 371 | - $endX = ceil($this->centerX + ($this->width / $this->tileSize) / 2); |
|
| 372 | - $endY = ceil($this->centerY + ($this->height / $this->tileSize) / 2); |
|
| 373 | - $this->offsetX = -floor(($this->centerX - floor($this->centerX)) * $this->tileSize); |
|
| 374 | - $this->offsetY = -floor(($this->centerY - floor($this->centerY)) * $this->tileSize); |
|
| 375 | - $this->offsetX += floor($this->width / 2); |
|
| 376 | - $this->offsetY += floor($this->height / 2); |
|
| 377 | - $this->offsetX += floor($startX - floor($this->centerX)) * $this->tileSize; |
|
| 378 | - $this->offsetY += floor($startY - floor($this->centerY)) * $this->tileSize; |
|
| 379 | - |
|
| 380 | - for($x = $startX; $x <= $endX; $x++) { |
|
| 381 | - for($y = $startY; $y <= $endY; $y++) { |
|
| 382 | - $url = str_replace( |
|
| 383 | - array( |
|
| 384 | - '{Z}', |
|
| 385 | - '{X}', |
|
| 386 | - '{Y}' |
|
| 387 | - ), array( |
|
| 388 | - $this->zoom, |
|
| 389 | - $x, |
|
| 390 | - $y |
|
| 391 | - ), $this->tileInfo [$this->maptype] ['url'] |
|
| 392 | - ); |
|
| 393 | - $url .= $this->apikey; |
|
| 394 | - |
|
| 395 | - $tileData = $this->fetchTile($url); |
|
| 396 | - if($tileData) { |
|
| 397 | - $tileImage = imagecreatefromstring($tileData); |
|
| 398 | - } else { |
|
| 399 | - $tileImage = imagecreate($this->tileSize, $this->tileSize); |
|
| 400 | - $color = imagecolorallocate($tileImage, 255, 255, 255); |
|
| 401 | - @imagestring($tileImage, 1, 127, 127, 'err', $color); |
|
| 402 | - } |
|
| 403 | - $destX = ($x - $startX) * $this->tileSize + $this->offsetX; |
|
| 404 | - $destY = ($y - $startY) * $this->tileSize + $this->offsetY; |
|
| 405 | - dbglog($this->tileSize, "imagecopy tile into image: $destX, $destY"); |
|
| 406 | - imagecopy( |
|
| 407 | - $this->image, $tileImage, $destX, $destY, 0, 0, $this->tileSize, |
|
| 408 | - $this->tileSize |
|
| 409 | - ); |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * Fetch a tile and (if configured) store it in the cache. |
|
| 416 | - * |
|
| 417 | - * @param string $url |
|
| 418 | - */ |
|
| 419 | - public function fetchTile($url) { |
|
| 420 | - if($this->useTileCache && ($cached = $this->checkTileCache($url))) |
|
| 421 | - return $cached; |
|
| 422 | - |
|
| 423 | - $_UA = 'Mozilla/4.0 (compatible; DokuWikiSpatial HTTP Client; ' . PHP_OS . ')'; |
|
| 424 | - if(function_exists("curl_init")) { |
|
| 425 | - // use cUrl |
|
| 426 | - $ch = curl_init(); |
|
| 427 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 428 | - curl_setopt($ch, CURLOPT_USERAGENT, $_UA); |
|
| 429 | - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); |
|
| 430 | - curl_setopt($ch, CURLOPT_URL, $url); |
|
| 431 | - $tile = curl_exec($ch); |
|
| 432 | - curl_close($ch); |
|
| 433 | - } else { |
|
| 434 | - // use file_get_contents |
|
| 435 | - global $conf; |
|
| 436 | - $opts = array( |
|
| 437 | - 'http' => array( |
|
| 438 | - 'method' => "GET", |
|
| 439 | - 'header' => "Accept-language: en\r\n" . "User-Agent: $_UA\r\n" . "accept: image/png\r\n", |
|
| 440 | - 'proxy' => "tcp://" . $conf ['proxy'] ['host'] . ":" . $conf ['proxy'] ['port'], |
|
| 441 | - 'request_fulluri' => true |
|
| 442 | - ) |
|
| 443 | - ); |
|
| 444 | - $context = stream_context_create($opts); |
|
| 445 | - $tile = file_get_contents($url, false, $context); |
|
| 446 | - } |
|
| 447 | - if($tile && $this->useTileCache) { |
|
| 448 | - $this->writeTileToCache($url, $tile); |
|
| 449 | - } |
|
| 450 | - return $tile; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * |
|
| 455 | - * @param string $url |
|
| 456 | - */ |
|
| 457 | - public function checkTileCache($url) { |
|
| 458 | - $filename = $this->tileUrlToFilename($url); |
|
| 459 | - if(file_exists($filename)) { |
|
| 460 | - return file_get_contents($filename); |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - /** |
|
| 465 | - * |
|
| 466 | - * @param string $url |
|
| 467 | - * @return string |
|
| 468 | - */ |
|
| 469 | - public function tileUrlToFilename($url) { |
|
| 470 | - return $this->tileCacheBaseDir . "/" . str_replace( |
|
| 471 | - array( |
|
| 472 | - 'http://' |
|
| 473 | - ), '', $url |
|
| 474 | - ); |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * Write a tile into the cache. |
|
| 479 | - * |
|
| 480 | - * @param string $url |
|
| 481 | - * @param mixed $data |
|
| 482 | - */ |
|
| 483 | - public function writeTileToCache($url, $data) { |
|
| 484 | - $filename = $this->tileUrlToFilename($url); |
|
| 485 | - $this->mkdir_recursive(dirname($filename), 0777); |
|
| 486 | - file_put_contents($filename, $data); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * Recursively create the directory. |
|
| 491 | - * |
|
| 492 | - * @param string $pathname |
|
| 493 | - * The directory path. |
|
| 494 | - * @param int $mode |
|
| 495 | - * File access mode. For more information on modes, read the details on the chmod manpage. |
|
| 496 | - */ |
|
| 497 | - public function mkdir_recursive($pathname, $mode) { |
|
| 498 | - is_dir(dirname($pathname)) || $this->mkdir_recursive(dirname($pathname), $mode); |
|
| 499 | - return is_dir($pathname) || @mkdir($pathname, $mode); |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * Place markers on the map and number them in the same order as they are listed in the html. |
|
| 504 | - */ |
|
| 505 | - public function placeMarkers() { |
|
| 506 | - $count = 0; |
|
| 507 | - $color = imagecolorallocate($this->image, 0, 0, 0); |
|
| 508 | - $bgcolor = imagecolorallocate($this->image, 200, 200, 200); |
|
| 509 | - $markerBaseDir = dirname(__FILE__) . '/icons'; |
|
| 510 | - // loop thru marker array |
|
| 511 | - foreach($this->markers as $marker) { |
|
| 512 | - // set some local variables |
|
| 513 | - $markerLat = $marker ['lat']; |
|
| 514 | - $markerLon = $marker ['lon']; |
|
| 515 | - $markerType = $marker ['type']; |
|
| 516 | - // clear variables from previous loops |
|
| 517 | - $markerFilename = ''; |
|
| 518 | - $markerShadow = ''; |
|
| 519 | - $matches = false; |
|
| 520 | - // check for marker type, get settings from markerPrototypes |
|
| 521 | - if($markerType) { |
|
| 522 | - foreach($this->markerPrototypes as $markerPrototype) { |
|
| 523 | - if(preg_match($markerPrototype ['regex'], $markerType, $matches)) { |
|
| 524 | - $markerFilename = $matches [0] . $markerPrototype ['extension']; |
|
| 525 | - if($markerPrototype ['offsetImage']) { |
|
| 526 | - list ($markerImageOffsetX, $markerImageOffsetY) = explode( |
|
| 527 | - ",", |
|
| 528 | - $markerPrototype ['offsetImage'] |
|
| 529 | - ); |
|
| 530 | - } |
|
| 531 | - $markerShadow = $markerPrototype ['shadow']; |
|
| 532 | - if($markerShadow) { |
|
| 533 | - list ($markerShadowOffsetX, $markerShadowOffsetY) = explode( |
|
| 534 | - ",", |
|
| 535 | - $markerPrototype ['offsetShadow'] |
|
| 536 | - ); |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - } |
|
| 540 | - } |
|
| 541 | - // create img resource |
|
| 542 | - if(file_exists($markerBaseDir . '/' . $markerFilename)) { |
|
| 543 | - $markerImg = imagecreatefrompng($markerBaseDir . '/' . $markerFilename); |
|
| 544 | - } else { |
|
| 545 | - $markerImg = imagecreatefrompng($markerBaseDir . '/marker.png'); |
|
| 546 | - } |
|
| 547 | - // check for shadow + create shadow recource |
|
| 548 | - if($markerShadow && file_exists($markerBaseDir . '/' . $markerShadow)) { |
|
| 549 | - $markerShadowImg = imagecreatefrompng($markerBaseDir . '/' . $markerShadow); |
|
| 550 | - } |
|
| 551 | - // calc position |
|
| 552 | - $destX = floor(($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($markerLon, $this->zoom))); |
|
| 553 | - $destY = floor(($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($markerLat, $this->zoom))); |
|
| 554 | - // copy shadow on basemap |
|
| 555 | - if($markerShadow && $markerShadowImg) { |
|
| 556 | - imagecopy($this->image, $markerShadowImg, $destX + intval($markerShadowOffsetX), $destY + intval($markerShadowOffsetY), 0, 0, imagesx($markerShadowImg), imagesy($markerShadowImg)); |
|
| 557 | - } |
|
| 558 | - // copy marker on basemap above shadow |
|
| 559 | - imagecopy($this->image, $markerImg, $destX + intval($markerImageOffsetX), $destY + intval($markerImageOffsetY), 0, 0, imagesx($markerImg), imagesy($markerImg)); |
|
| 560 | - // add label |
|
| 561 | - imagestring($this->image, 3, $destX - imagesx($markerImg) + 1, $destY + intval($markerImageOffsetY) + 1, ++$count, $bgcolor); |
|
| 562 | - imagestring($this->image, 3, $destX - imagesx($markerImg), $destY + intval($markerImageOffsetY), $count, $color); |
|
| 563 | - } |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Draw kml trace on the map. |
|
| 568 | - */ |
|
| 569 | - public function drawKML() { |
|
| 570 | - // TODO get colour from kml node (not currently supported in geoPHP) |
|
| 571 | - $col = imagecolorallocatealpha($this->image, 255, 0, 0, .4 * 127); |
|
| 572 | - $kmlgeom = geoPHP::load(file_get_contents($this->kmlFileName), 'kml'); |
|
| 573 | - $this->drawGeometry($kmlgeom, $col); |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - /** |
|
| 577 | - * Draw geometry or geometry collection on the map. |
|
| 578 | - * |
|
| 579 | - * @param Geometry $geom |
|
| 580 | - * @param int $colour |
|
| 581 | - * drawing colour |
|
| 582 | - */ |
|
| 583 | - private function drawGeometry($geom, $colour) { |
|
| 584 | - if(empty($geom)) return; |
|
| 585 | - |
|
| 586 | - switch($geom->geometryType()) { |
|
| 587 | - case 'GeometryCollection' : |
|
| 588 | - // recursively draw part of the collection |
|
| 589 | - for($i = 1; $i < $geom->numGeometries() + 1; $i++) { |
|
| 590 | - $_geom = $geom->geometryN($i); |
|
| 591 | - $this->drawGeometry($_geom, $colour); |
|
| 592 | - } |
|
| 593 | - break; |
|
| 594 | - case 'MultiPolygon' : |
|
| 595 | - case 'MultiLineString' : |
|
| 596 | - case 'MultiPoint' : |
|
| 597 | - // TODO implement / do nothing |
|
| 598 | - break; |
|
| 599 | - case 'Polygon' : |
|
| 600 | - $this->drawPolygon($geom, $colour); |
|
| 601 | - break; |
|
| 602 | - case 'LineString' : |
|
| 603 | - $this->drawLineString($geom, $colour); |
|
| 604 | - break; |
|
| 605 | - case 'Point' : |
|
| 606 | - $this->drawPoint($geom, $colour); |
|
| 607 | - break; |
|
| 608 | - default : |
|
| 609 | - // draw nothing |
|
| 610 | - break; |
|
| 611 | - } |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * Draw a polygon on the map. |
|
| 616 | - * |
|
| 617 | - * @param Polygon $polygon |
|
| 618 | - * @param int $colour |
|
| 619 | - * drawing colour |
|
| 620 | - */ |
|
| 621 | - private function drawPolygon($polygon, $colour) { |
|
| 622 | - // TODO implementation of drawing holes, |
|
| 623 | - // maybe draw the polygon to an in-memory image and use imagecopy, draw polygon in col., draw holes in bgcol? |
|
| 624 | - |
|
| 625 | - // print_r('Polygon:<br />'); |
|
| 626 | - // print_r($polygon); |
|
| 627 | - $extPoints = array(); |
|
| 628 | - // extring is a linestring actually.. |
|
| 629 | - $extRing = $polygon->exteriorRing(); |
|
| 630 | - |
|
| 631 | - for($i = 1; $i < $extRing->numGeometries(); $i++) { |
|
| 632 | - $p1 = $extRing->geometryN($i); |
|
| 633 | - $x = floor(($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))); |
|
| 634 | - $y = floor(($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p1->y(), $this->zoom))); |
|
| 635 | - $extPoints [] = $x; |
|
| 636 | - $extPoints [] = $y; |
|
| 637 | - } |
|
| 638 | - // print_r('points:('.($i-1).')<br />'); |
|
| 639 | - // print_r($extPoints); |
|
| 640 | - // imagepolygon ($this->image, $extPoints, $i-1, $colour ); |
|
| 641 | - imagefilledpolygon($this->image, $extPoints, $i - 1, $colour); |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - /** |
|
| 645 | - * Draw a line on the map. |
|
| 646 | - * |
|
| 647 | - * @param LineString $line |
|
| 648 | - * @param int $colour |
|
| 649 | - * drawing colour |
|
| 650 | - */ |
|
| 651 | - private function drawLineString($line, $colour) { |
|
| 652 | - imagesetthickness($this->image, 2); |
|
| 653 | - for($p = 1; $p < $line->numGeometries(); $p++) { |
|
| 654 | - // get first pair of points |
|
| 655 | - $p1 = $line->geometryN($p); |
|
| 656 | - $p2 = $line->geometryN($p + 1); |
|
| 657 | - // translate to paper space |
|
| 658 | - $x1 = floor(($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))); |
|
| 659 | - $y1 = floor(($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p1->y(), $this->zoom))); |
|
| 660 | - $x2 = floor(($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p2->x(), $this->zoom))); |
|
| 661 | - $y2 = floor(($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p2->y(), $this->zoom))); |
|
| 662 | - // draw to image |
|
| 663 | - imageline($this->image, $x1, $y1, $x2, $y2, $colour); |
|
| 664 | - } |
|
| 665 | - imagesetthickness($this->image, 1); |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - /** |
|
| 669 | - * Draw a point on the map. |
|
| 670 | - * |
|
| 671 | - * @param Point $point |
|
| 672 | - * @param int $colour |
|
| 673 | - * drawing colour |
|
| 674 | - */ |
|
| 675 | - private function drawPoint($point, $colour) { |
|
| 676 | - imagesetthickness($this->image, 2); |
|
| 677 | - // translate to paper space |
|
| 678 | - $cx = floor(($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($point->x(), $this->zoom))); |
|
| 679 | - $cy = floor(($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($point->y(), $this->zoom))); |
|
| 680 | - $r = 5; |
|
| 681 | - // draw to image |
|
| 682 | - // imageellipse($this->image, $cx, $cy,$r, $r, $colour); |
|
| 683 | - imagefilledellipse($this->image, $cx, $cy, $r, $r, $colour); |
|
| 684 | - // don't use imageellipse because the imagesetthickness function has |
|
| 685 | - // no effect. So the better workaround is to use imagearc. |
|
| 686 | - imagearc($this->image, $cx, $cy, $r, $r, 0, 359, $colour); |
|
| 687 | - imagesetthickness($this->image, 1); |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - /** |
|
| 691 | - * Draw gpx trace on the map. |
|
| 692 | - */ |
|
| 693 | - public function drawGPX() { |
|
| 694 | - $col = imagecolorallocatealpha($this->image, 0, 0, 255, .4 * 127); |
|
| 695 | - $gpxgeom = geoPHP::load(file_get_contents($this->gpxFileName), 'gpx'); |
|
| 696 | - $this->drawGeometry($gpxgeom, $col); |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - /** |
|
| 700 | - * Draw geojson on the map. |
|
| 701 | - */ |
|
| 702 | - public function drawGeojson() { |
|
| 703 | - $col = imagecolorallocatealpha($this->image, 255, 0, 255, .4 * 127); |
|
| 704 | - $gpxgeom = geoPHP::load(file_get_contents($this->geojsonFileName), 'json'); |
|
| 705 | - $this->drawGeometry($gpxgeom, $col); |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - /** |
|
| 709 | - * add copyright and origin notice and icons to the map. |
|
| 710 | - */ |
|
| 711 | - public function drawCopyright() { |
|
| 712 | - $logoBaseDir = dirname(__FILE__) . '/' . 'logo/'; |
|
| 713 | - $logoImg = imagecreatefrompng($logoBaseDir . $this->tileInfo ['openstreetmap'] ['logo']); |
|
| 714 | - $textcolor = imagecolorallocate($this->image, 0, 0, 0); |
|
| 715 | - $bgcolor = imagecolorallocate($this->image, 200, 200, 200); |
|
| 716 | - |
|
| 717 | - imagecopy($this->image, $logoImg, 0, imagesy($this->image) - imagesy($logoImg), 0, 0, imagesx($logoImg), imagesy($logoImg)); |
|
| 718 | - imagestring($this->image, 1, imagesx($logoImg) + 2, imagesy($this->image) - imagesy($logoImg) + 1, $this->tileInfo ['openstreetmap'] ['txt'], $bgcolor); |
|
| 719 | - imagestring($this->image, 1, imagesx($logoImg) + 1, imagesy($this->image) - imagesy($logoImg), $this->tileInfo ['openstreetmap'] ['txt'], $textcolor); |
|
| 720 | - |
|
| 721 | - // additional tile source info, ie. who created/hosted the tiles |
|
| 722 | - if($this->maptype != 'openstreetmap') { |
|
| 723 | - $iconImg = imagecreatefrompng($logoBaseDir . $this->tileInfo [$this->maptype] ['logo']); |
|
| 724 | - imagecopy($this->image, $iconImg, imagesx($logoImg) + 1, imagesy($this->image) - imagesy($iconImg), 0, 0, imagesx($iconImg), imagesy($iconImg)); |
|
| 725 | - imagestring($this->image, 1, imagesx($logoImg) + imagesx($iconImg) + 4, imagesy($this->image) - ceil(imagesy($logoImg) / 2) + 1, $this->tileInfo [$this->maptype] ['txt'], $bgcolor); |
|
| 726 | - imagestring($this->image, 1, imagesx($logoImg) + imagesx($iconImg) + 3, imagesy($this->image) - ceil(imagesy($logoImg) / 2), $this->tileInfo [$this->maptype] ['txt'], $textcolor); |
|
| 727 | - } |
|
| 728 | - } |
|
| 30 | + // this should probably not be changed |
|
| 31 | + var $doc = ''; |
|
| 32 | + |
|
| 33 | + // the final output |
|
| 34 | + protected $tileSize = 256; |
|
| 35 | + protected $tileInfo = array( |
|
| 36 | + // OSM sources |
|
| 37 | + 'openstreetmap' => array( |
|
| 38 | + 'txt' => '(c) OpenStreetMap CC-BY-SA', |
|
| 39 | + 'logo' => 'osm_logo.png', |
|
| 40 | + 'url' => 'https://tile.openstreetmap.org/{Z}/{X}/{Y}.png' |
|
| 41 | + ), |
|
| 42 | + // OCM sources |
|
| 43 | + 'cycle' => array( |
|
| 44 | + 'txt' => 'OpenCycleMap tiles', |
|
| 45 | + 'logo' => 'cycle_logo.png', |
|
| 46 | + 'url' => 'https://tile.thunderforest.com/cycle/{Z}/{X}/{Y}.png?apikey=' |
|
| 47 | + ), |
|
| 48 | + 'transport' => array( |
|
| 49 | + 'txt' => 'OpenCycleMap tiles', |
|
| 50 | + 'logo' => 'cycle_logo.png', |
|
| 51 | + 'url' => 'https://tile.thunderforest.com/transport/{Z}/{X}/{Y}.png?apikey=' |
|
| 52 | + ), |
|
| 53 | + 'landscape' => array( |
|
| 54 | + 'txt' => 'OpenCycleMap tiles', |
|
| 55 | + 'logo' => 'cycle_logo.png', |
|
| 56 | + 'url' => 'https://tile.thunderforest.com/landscape/{Z}/{X}/{Y}.png?apikey=' |
|
| 57 | + ), |
|
| 58 | + 'outdoors' => array( |
|
| 59 | + 'txt' => 'OpenCycleMap tiles', |
|
| 60 | + 'logo' => 'cycle_logo.png', |
|
| 61 | + 'url' => 'https://tile.thunderforest.com/outdoors/{Z}/{X}/{Y}.png?apikey=' |
|
| 62 | + ), |
|
| 63 | + 'toner-lite' => array( |
|
| 64 | + 'txt' => 'Stamen tiles', |
|
| 65 | + 'logo' => 'stamen.png', |
|
| 66 | + 'url' => 'http://tile.stamen.com/toner-lite/{Z}/{X}/{Y}.png' |
|
| 67 | + ), |
|
| 68 | + 'terrain' => array( |
|
| 69 | + 'txt' => 'Stamen tiles', |
|
| 70 | + 'logo' => 'stamen.png', |
|
| 71 | + 'url' => 'http://tile.stamen.com/terrain/{Z}/{X}/{Y}.png' |
|
| 72 | + ) |
|
| 73 | + //, |
|
| 74 | + // 'piste'=>array( |
|
| 75 | + // 'txt'=>'OpenPisteMap tiles', |
|
| 76 | + // 'logo'=>'piste_logo.png', |
|
| 77 | + // 'url'=>''), |
|
| 78 | + // 'sea'=>array( |
|
| 79 | + // 'txt'=>'OpenSeaMap tiles', |
|
| 80 | + // 'logo'=>'sea_logo.png', |
|
| 81 | + // 'url'=>''), |
|
| 82 | + // H&B sources |
|
| 83 | + // 'hikeandbike' => array ( |
|
| 84 | + // 'txt' => 'Hike & Bike Map', |
|
| 85 | + // 'logo' => 'hnb_logo.png', |
|
| 86 | + // //'url' => 'http://toolserver.org/tiles/hikebike/{Z}/{X}/{Y}.png' |
|
| 87 | + // //moved to: https://www.toolserver.org/tiles/hikebike/12/2105/1388.png |
|
| 88 | + // 'url' => 'http://c.tiles.wmflabs.org/hikebike/{Z}/{X}/{Y}.png' |
|
| 89 | + // ) |
|
| 90 | + ); |
|
| 91 | + protected $tileDefaultSrc = 'openstreetmap'; |
|
| 92 | + |
|
| 93 | + // set up markers |
|
| 94 | + protected $markerPrototypes = array( |
|
| 95 | + // found at http://www.mapito.net/map-marker-icons.html |
|
| 96 | + // these are 17x19 px with a pointer at the bottom left |
|
| 97 | + 'lightblue' => array( |
|
| 98 | + 'regex' => '/^lightblue([0-9]+)$/', |
|
| 99 | + 'extension' => '.png', |
|
| 100 | + 'shadow' => false, |
|
| 101 | + 'offsetImage' => '0,-19', |
|
| 102 | + 'offsetShadow' => false |
|
| 103 | + ), |
|
| 104 | + // openlayers std markers are 21x25px with shadow |
|
| 105 | + 'ol-marker' => array( |
|
| 106 | + 'regex' => '/^marker(|-blue|-gold|-green|-red)+$/', |
|
| 107 | + 'extension' => '.png', |
|
| 108 | + 'shadow' => 'marker_shadow.png', |
|
| 109 | + 'offsetImage' => '-10,-25', |
|
| 110 | + 'offsetShadow' => '-1,-13' |
|
| 111 | + ), |
|
| 112 | + // these are 16x16 px |
|
| 113 | + 'ww_icon' => array( |
|
| 114 | + 'regex' => '/ww_\S+$/', |
|
| 115 | + 'extension' => '.png', |
|
| 116 | + 'shadow' => false, |
|
| 117 | + 'offsetImage' => '-8,-8', |
|
| 118 | + 'offsetShadow' => false |
|
| 119 | + ), |
|
| 120 | + // assume these are 16x16 px |
|
| 121 | + 'rest' => array( |
|
| 122 | + 'regex' => '/^(?!lightblue([0-9]+)$)(?!(ww_\S+$))(?!marker(|-blue|-gold|-green|-red)+$)(.*)/', |
|
| 123 | + 'extension' => '.png', |
|
| 124 | + 'shadow' => 'marker_shadow.png', |
|
| 125 | + 'offsetImage' => '-8,-8', |
|
| 126 | + 'offsetShadow' => '-1,-1' |
|
| 127 | + ) |
|
| 128 | + ); |
|
| 129 | + protected $centerX, $centerY, $offsetX, $offsetY, $image; |
|
| 130 | + protected $zoom, $lat, $lon, $width, $height, $markers, $maptype, $kmlFileName, $gpxFileName, $geojsonFileName, |
|
| 131 | + $autoZoomExtent, $apikey; |
|
| 132 | + protected $tileCacheBaseDir, $mapCacheBaseDir, $mediaBaseDir; |
|
| 133 | + protected $useTileCache = true; |
|
| 134 | + protected $mapCacheID = ''; |
|
| 135 | + protected $mapCacheFile = ''; |
|
| 136 | + protected $mapCacheExtension = 'png'; |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Constructor. |
|
| 140 | + * |
|
| 141 | + * @param float $lat |
|
| 142 | + * Latitude (x) of center of map |
|
| 143 | + * @param float $lon |
|
| 144 | + * Longitude (y) of center of map |
|
| 145 | + * @param int $zoom |
|
| 146 | + * Zoomlevel |
|
| 147 | + * @param int $width |
|
| 148 | + * Width in pixels |
|
| 149 | + * @param int $height |
|
| 150 | + * Height in pixels |
|
| 151 | + * @param string $maptype |
|
| 152 | + * Name of the map |
|
| 153 | + * @param mixed $markers |
|
| 154 | + * array of markers |
|
| 155 | + * @param string $gpx |
|
| 156 | + * GPX filename |
|
| 157 | + * @param string $kml |
|
| 158 | + * KML filename |
|
| 159 | + * @param string $mediaDir |
|
| 160 | + * Directory to store/cache maps |
|
| 161 | + * @param string $tileCacheBaseDir |
|
| 162 | + * Directory to cache map tiles |
|
| 163 | + * @param boolean $autoZoomExtent |
|
| 164 | + * Wheter or not to override zoom/lat/lon and zoom to the extent of gpx/kml and markers |
|
| 165 | + * @param apikey |
|
| 166 | + * Some service require a key to access |
|
| 167 | + */ |
|
| 168 | + public function __construct($lat, $lon, $zoom, $width, $height, $maptype, $markers, $gpx, $kml, $geojson, |
|
| 169 | + $mediaDir, $tileCacheBaseDir, $autoZoomExtent = true, $apikey = '') { |
|
| 170 | + $this->zoom = $zoom; |
|
| 171 | + $this->lat = $lat; |
|
| 172 | + $this->lon = $lon; |
|
| 173 | + $this->width = $width; |
|
| 174 | + $this->height = $height; |
|
| 175 | + // validate + set maptype |
|
| 176 | + $this->maptype = $this->tileDefaultSrc; |
|
| 177 | + if(array_key_exists($maptype, $this->tileInfo)) { |
|
| 178 | + $this->maptype = $maptype; |
|
| 179 | + } |
|
| 180 | + $this->markers = $markers; |
|
| 181 | + $this->kmlFileName = $kml; |
|
| 182 | + $this->gpxFileName = $gpx; |
|
| 183 | + $this->geojsonFileName = $geojson; |
|
| 184 | + $this->mediaBaseDir = $mediaDir; |
|
| 185 | + $this->tileCacheBaseDir = $tileCacheBaseDir . '/olmaptiles'; |
|
| 186 | + $this->useTileCache = $this->tileCacheBaseDir !== ''; |
|
| 187 | + $this->mapCacheBaseDir = $mediaDir . '/olmapmaps'; |
|
| 188 | + $this->autoZoomExtent = $autoZoomExtent; |
|
| 189 | + $this->apikey = $apikey; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * get the map, this may return a reference to a cached copy. |
|
| 194 | + * |
|
| 195 | + * @return string url relative to media dir |
|
| 196 | + */ |
|
| 197 | + public function getMap() { |
|
| 198 | + try { |
|
| 199 | + if($this->autoZoomExtent) { |
|
| 200 | + $this->autoZoom(); |
|
| 201 | + } |
|
| 202 | + } catch(Exception $e) { |
|
| 203 | + dbglog($e); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + // use map cache, so check cache for map |
|
| 207 | + if(!$this->checkMapCache()) { |
|
| 208 | + // map is not in cache, needs to be build |
|
| 209 | + $this->makeMap(); |
|
| 210 | + $this->mkdir_recursive(dirname($this->mapCacheIDToFilename()), 0777); |
|
| 211 | + imagepng($this->image, $this->mapCacheIDToFilename(), 9); |
|
| 212 | + } |
|
| 213 | + $this->doc = $this->mapCacheIDToFilename(); |
|
| 214 | + // make url relative to media dir |
|
| 215 | + return str_replace($this->mediaBaseDir, '', $this->doc); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Calculate the lat/lon/zoom values to make sure that all of the markers and gpx/kml are on the map. |
|
| 220 | + * can throw an error like |
|
| 221 | + * "Fatal error: Uncaught Exception: Cannot create a collection with non-geometries in |
|
| 222 | + * D:\www\wild-water.nl\www\dokuwiki\lib\plugins\geophp\geoPHP\lib\geometry\Collection.class.php:29" |
|
| 223 | + * |
|
| 224 | + * @param float $paddingFactor |
|
| 225 | + * buffer constant to enlarge (>1.0) the zoom level |
|
| 226 | + */ |
|
| 227 | + private function autoZoom($paddingFactor = 1.0) { |
|
| 228 | + $geoms = array(); |
|
| 229 | + $geoms [] = new Point ($this->lon, $this->lat); |
|
| 230 | + if(!empty ($this->markers)) { |
|
| 231 | + foreach($this->markers as $marker) { |
|
| 232 | + $geoms [] = new Point ($marker ['lon'], $marker ['lat']); |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + $g = false; |
|
| 236 | + if(file_exists($this->kmlFileName)) { |
|
| 237 | + $g = geoPHP::load(file_get_contents($this->kmlFileName), 'kml'); |
|
| 238 | + if($g !== false) { |
|
| 239 | + $geoms [] = $g; |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + if(file_exists($this->gpxFileName)) { |
|
| 243 | + $g = geoPHP::load(file_get_contents($this->gpxFileName), 'gpx'); |
|
| 244 | + if($g !== false) { |
|
| 245 | + $geoms [] = $g; |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + if(file_exists($this->geojsonFileName)) { |
|
| 249 | + $g = geoPHP::load(file_get_contents($this->geojsonFileName), 'geojson'); |
|
| 250 | + if($g !== false) { |
|
| 251 | + $geoms [] = $g; |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + if(count($geoms) <= 1) { |
|
| 256 | + dbglog($geoms, "StaticMap::autoZoom: Skip setting autozoom options"); |
|
| 257 | + return; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + $geom = new GeometryCollection ($geoms); |
|
| 261 | + $centroid = $geom->centroid(); |
|
| 262 | + $bbox = $geom->getBBox(); |
|
| 263 | + |
|
| 264 | + // determine vertical resolution, this depends on the distance from the equator |
|
| 265 | + // $vy00 = log(tan(M_PI*(0.25 + $centroid->getY()/360))); |
|
| 266 | + $vy0 = log(tan(M_PI * (0.25 + $bbox ['miny'] / 360))); |
|
| 267 | + $vy1 = log(tan(M_PI * (0.25 + $bbox ['maxy'] / 360))); |
|
| 268 | + dbglog("StaticMap::autoZoom: vertical resolution: $vy0, $vy1"); |
|
| 269 | + $zoomFactorPowered = ($this->height / 2) / (40.7436654315252 * ($vy1 - $vy0)); |
|
| 270 | + $resolutionVertical = 360 / ($zoomFactorPowered * $this->tileSize); |
|
| 271 | + // determine horizontal resolution |
|
| 272 | + $resolutionHorizontal = ($bbox ['maxx'] - $bbox ['minx']) / $this->width; |
|
| 273 | + $resolution = max($resolutionHorizontal, $resolutionVertical) * $paddingFactor; |
|
| 274 | + $zoom = log(360 / ($resolution * $this->tileSize), 2); |
|
| 275 | + |
|
| 276 | + if(is_finite($zoom) && $zoom < 15 && $zoom > 2) { |
|
| 277 | + $this->zoom = floor($zoom); |
|
| 278 | + } |
|
| 279 | + $this->lon = $centroid->getX(); |
|
| 280 | + $this->lat = $centroid->getY(); |
|
| 281 | + dbglog("StaticMap::autoZoom: Set autozoom options to: z: $this->zoom, lon: $this->lon, lat: $this->lat"); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + public function checkMapCache() { |
|
| 285 | + $this->mapCacheID = md5($this->serializeParams()); |
|
| 286 | + $filename = $this->mapCacheIDToFilename(); |
|
| 287 | + if(file_exists($filename)) |
|
| 288 | + return true; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + public function serializeParams() { |
|
| 292 | + return join( |
|
| 293 | + "&", array( |
|
| 294 | + $this->zoom, |
|
| 295 | + $this->lat, |
|
| 296 | + $this->lon, |
|
| 297 | + $this->width, |
|
| 298 | + $this->height, |
|
| 299 | + serialize($this->markers), |
|
| 300 | + $this->maptype, |
|
| 301 | + $this->kmlFileName, |
|
| 302 | + $this->gpxFileName, |
|
| 303 | + $this->geojsonFileName |
|
| 304 | + ) |
|
| 305 | + ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + public function mapCacheIDToFilename() { |
|
| 309 | + if(!$this->mapCacheFile) { |
|
| 310 | + $this->mapCacheFile = $this->mapCacheBaseDir . "/" . $this->maptype . "/" . $this->zoom . "/cache_" |
|
| 311 | + . substr($this->mapCacheID, 0, 2) . "/" . substr($this->mapCacheID, 2, 2) |
|
| 312 | + . "/" . substr($this->mapCacheID, 4); |
|
| 313 | + } |
|
| 314 | + return $this->mapCacheFile . "." . $this->mapCacheExtension; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * make the map. |
|
| 319 | + */ |
|
| 320 | + public function makeMap() { |
|
| 321 | + $this->initCoords(); |
|
| 322 | + $this->createBaseMap(); |
|
| 323 | + if(!empty ($this->markers)) |
|
| 324 | + $this->placeMarkers(); |
|
| 325 | + if(file_exists($this->kmlFileName)) |
|
| 326 | + $this->drawKML(); |
|
| 327 | + if(file_exists($this->gpxFileName)) |
|
| 328 | + $this->drawGPX(); |
|
| 329 | + if(file_exists($this->geojsonFileName)) |
|
| 330 | + $this->drawGeojson(); |
|
| 331 | + |
|
| 332 | + $this->drawCopyright(); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + */ |
|
| 337 | + public function initCoords() { |
|
| 338 | + $this->centerX = $this->lonToTile($this->lon, $this->zoom); |
|
| 339 | + $this->centerY = $this->latToTile($this->lat, $this->zoom); |
|
| 340 | + $this->offsetX = floor((floor($this->centerX) - $this->centerX) * $this->tileSize); |
|
| 341 | + $this->offsetY = floor((floor($this->centerY) - $this->centerY) * $this->tileSize); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * |
|
| 346 | + * @param number $long |
|
| 347 | + * @param number $zoom |
|
| 348 | + * @return number |
|
| 349 | + */ |
|
| 350 | + public function lonToTile($long, $zoom) { |
|
| 351 | + return (($long + 180) / 360) * pow(2, $zoom); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * |
|
| 356 | + * @param number $lat |
|
| 357 | + * @param number $zoom |
|
| 358 | + * @return float|int |
|
| 359 | + */ |
|
| 360 | + public function latToTile($lat, $zoom) { |
|
| 361 | + return (1 - log(tan($lat * pi() / 180) + 1 / cos($lat * M_PI / 180)) / M_PI) / 2 * pow(2, $zoom); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * make basemap image. |
|
| 366 | + */ |
|
| 367 | + public function createBaseMap() { |
|
| 368 | + $this->image = imagecreatetruecolor($this->width, $this->height); |
|
| 369 | + $startX = floor($this->centerX - ($this->width / $this->tileSize) / 2); |
|
| 370 | + $startY = floor($this->centerY - ($this->height / $this->tileSize) / 2); |
|
| 371 | + $endX = ceil($this->centerX + ($this->width / $this->tileSize) / 2); |
|
| 372 | + $endY = ceil($this->centerY + ($this->height / $this->tileSize) / 2); |
|
| 373 | + $this->offsetX = -floor(($this->centerX - floor($this->centerX)) * $this->tileSize); |
|
| 374 | + $this->offsetY = -floor(($this->centerY - floor($this->centerY)) * $this->tileSize); |
|
| 375 | + $this->offsetX += floor($this->width / 2); |
|
| 376 | + $this->offsetY += floor($this->height / 2); |
|
| 377 | + $this->offsetX += floor($startX - floor($this->centerX)) * $this->tileSize; |
|
| 378 | + $this->offsetY += floor($startY - floor($this->centerY)) * $this->tileSize; |
|
| 379 | + |
|
| 380 | + for($x = $startX; $x <= $endX; $x++) { |
|
| 381 | + for($y = $startY; $y <= $endY; $y++) { |
|
| 382 | + $url = str_replace( |
|
| 383 | + array( |
|
| 384 | + '{Z}', |
|
| 385 | + '{X}', |
|
| 386 | + '{Y}' |
|
| 387 | + ), array( |
|
| 388 | + $this->zoom, |
|
| 389 | + $x, |
|
| 390 | + $y |
|
| 391 | + ), $this->tileInfo [$this->maptype] ['url'] |
|
| 392 | + ); |
|
| 393 | + $url .= $this->apikey; |
|
| 394 | + |
|
| 395 | + $tileData = $this->fetchTile($url); |
|
| 396 | + if($tileData) { |
|
| 397 | + $tileImage = imagecreatefromstring($tileData); |
|
| 398 | + } else { |
|
| 399 | + $tileImage = imagecreate($this->tileSize, $this->tileSize); |
|
| 400 | + $color = imagecolorallocate($tileImage, 255, 255, 255); |
|
| 401 | + @imagestring($tileImage, 1, 127, 127, 'err', $color); |
|
| 402 | + } |
|
| 403 | + $destX = ($x - $startX) * $this->tileSize + $this->offsetX; |
|
| 404 | + $destY = ($y - $startY) * $this->tileSize + $this->offsetY; |
|
| 405 | + dbglog($this->tileSize, "imagecopy tile into image: $destX, $destY"); |
|
| 406 | + imagecopy( |
|
| 407 | + $this->image, $tileImage, $destX, $destY, 0, 0, $this->tileSize, |
|
| 408 | + $this->tileSize |
|
| 409 | + ); |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * Fetch a tile and (if configured) store it in the cache. |
|
| 416 | + * |
|
| 417 | + * @param string $url |
|
| 418 | + */ |
|
| 419 | + public function fetchTile($url) { |
|
| 420 | + if($this->useTileCache && ($cached = $this->checkTileCache($url))) |
|
| 421 | + return $cached; |
|
| 422 | + |
|
| 423 | + $_UA = 'Mozilla/4.0 (compatible; DokuWikiSpatial HTTP Client; ' . PHP_OS . ')'; |
|
| 424 | + if(function_exists("curl_init")) { |
|
| 425 | + // use cUrl |
|
| 426 | + $ch = curl_init(); |
|
| 427 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
| 428 | + curl_setopt($ch, CURLOPT_USERAGENT, $_UA); |
|
| 429 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); |
|
| 430 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
| 431 | + $tile = curl_exec($ch); |
|
| 432 | + curl_close($ch); |
|
| 433 | + } else { |
|
| 434 | + // use file_get_contents |
|
| 435 | + global $conf; |
|
| 436 | + $opts = array( |
|
| 437 | + 'http' => array( |
|
| 438 | + 'method' => "GET", |
|
| 439 | + 'header' => "Accept-language: en\r\n" . "User-Agent: $_UA\r\n" . "accept: image/png\r\n", |
|
| 440 | + 'proxy' => "tcp://" . $conf ['proxy'] ['host'] . ":" . $conf ['proxy'] ['port'], |
|
| 441 | + 'request_fulluri' => true |
|
| 442 | + ) |
|
| 443 | + ); |
|
| 444 | + $context = stream_context_create($opts); |
|
| 445 | + $tile = file_get_contents($url, false, $context); |
|
| 446 | + } |
|
| 447 | + if($tile && $this->useTileCache) { |
|
| 448 | + $this->writeTileToCache($url, $tile); |
|
| 449 | + } |
|
| 450 | + return $tile; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * |
|
| 455 | + * @param string $url |
|
| 456 | + */ |
|
| 457 | + public function checkTileCache($url) { |
|
| 458 | + $filename = $this->tileUrlToFilename($url); |
|
| 459 | + if(file_exists($filename)) { |
|
| 460 | + return file_get_contents($filename); |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + /** |
|
| 465 | + * |
|
| 466 | + * @param string $url |
|
| 467 | + * @return string |
|
| 468 | + */ |
|
| 469 | + public function tileUrlToFilename($url) { |
|
| 470 | + return $this->tileCacheBaseDir . "/" . str_replace( |
|
| 471 | + array( |
|
| 472 | + 'http://' |
|
| 473 | + ), '', $url |
|
| 474 | + ); |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * Write a tile into the cache. |
|
| 479 | + * |
|
| 480 | + * @param string $url |
|
| 481 | + * @param mixed $data |
|
| 482 | + */ |
|
| 483 | + public function writeTileToCache($url, $data) { |
|
| 484 | + $filename = $this->tileUrlToFilename($url); |
|
| 485 | + $this->mkdir_recursive(dirname($filename), 0777); |
|
| 486 | + file_put_contents($filename, $data); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * Recursively create the directory. |
|
| 491 | + * |
|
| 492 | + * @param string $pathname |
|
| 493 | + * The directory path. |
|
| 494 | + * @param int $mode |
|
| 495 | + * File access mode. For more information on modes, read the details on the chmod manpage. |
|
| 496 | + */ |
|
| 497 | + public function mkdir_recursive($pathname, $mode) { |
|
| 498 | + is_dir(dirname($pathname)) || $this->mkdir_recursive(dirname($pathname), $mode); |
|
| 499 | + return is_dir($pathname) || @mkdir($pathname, $mode); |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * Place markers on the map and number them in the same order as they are listed in the html. |
|
| 504 | + */ |
|
| 505 | + public function placeMarkers() { |
|
| 506 | + $count = 0; |
|
| 507 | + $color = imagecolorallocate($this->image, 0, 0, 0); |
|
| 508 | + $bgcolor = imagecolorallocate($this->image, 200, 200, 200); |
|
| 509 | + $markerBaseDir = dirname(__FILE__) . '/icons'; |
|
| 510 | + // loop thru marker array |
|
| 511 | + foreach($this->markers as $marker) { |
|
| 512 | + // set some local variables |
|
| 513 | + $markerLat = $marker ['lat']; |
|
| 514 | + $markerLon = $marker ['lon']; |
|
| 515 | + $markerType = $marker ['type']; |
|
| 516 | + // clear variables from previous loops |
|
| 517 | + $markerFilename = ''; |
|
| 518 | + $markerShadow = ''; |
|
| 519 | + $matches = false; |
|
| 520 | + // check for marker type, get settings from markerPrototypes |
|
| 521 | + if($markerType) { |
|
| 522 | + foreach($this->markerPrototypes as $markerPrototype) { |
|
| 523 | + if(preg_match($markerPrototype ['regex'], $markerType, $matches)) { |
|
| 524 | + $markerFilename = $matches [0] . $markerPrototype ['extension']; |
|
| 525 | + if($markerPrototype ['offsetImage']) { |
|
| 526 | + list ($markerImageOffsetX, $markerImageOffsetY) = explode( |
|
| 527 | + ",", |
|
| 528 | + $markerPrototype ['offsetImage'] |
|
| 529 | + ); |
|
| 530 | + } |
|
| 531 | + $markerShadow = $markerPrototype ['shadow']; |
|
| 532 | + if($markerShadow) { |
|
| 533 | + list ($markerShadowOffsetX, $markerShadowOffsetY) = explode( |
|
| 534 | + ",", |
|
| 535 | + $markerPrototype ['offsetShadow'] |
|
| 536 | + ); |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + } |
|
| 540 | + } |
|
| 541 | + // create img resource |
|
| 542 | + if(file_exists($markerBaseDir . '/' . $markerFilename)) { |
|
| 543 | + $markerImg = imagecreatefrompng($markerBaseDir . '/' . $markerFilename); |
|
| 544 | + } else { |
|
| 545 | + $markerImg = imagecreatefrompng($markerBaseDir . '/marker.png'); |
|
| 546 | + } |
|
| 547 | + // check for shadow + create shadow recource |
|
| 548 | + if($markerShadow && file_exists($markerBaseDir . '/' . $markerShadow)) { |
|
| 549 | + $markerShadowImg = imagecreatefrompng($markerBaseDir . '/' . $markerShadow); |
|
| 550 | + } |
|
| 551 | + // calc position |
|
| 552 | + $destX = floor(($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($markerLon, $this->zoom))); |
|
| 553 | + $destY = floor(($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($markerLat, $this->zoom))); |
|
| 554 | + // copy shadow on basemap |
|
| 555 | + if($markerShadow && $markerShadowImg) { |
|
| 556 | + imagecopy($this->image, $markerShadowImg, $destX + intval($markerShadowOffsetX), $destY + intval($markerShadowOffsetY), 0, 0, imagesx($markerShadowImg), imagesy($markerShadowImg)); |
|
| 557 | + } |
|
| 558 | + // copy marker on basemap above shadow |
|
| 559 | + imagecopy($this->image, $markerImg, $destX + intval($markerImageOffsetX), $destY + intval($markerImageOffsetY), 0, 0, imagesx($markerImg), imagesy($markerImg)); |
|
| 560 | + // add label |
|
| 561 | + imagestring($this->image, 3, $destX - imagesx($markerImg) + 1, $destY + intval($markerImageOffsetY) + 1, ++$count, $bgcolor); |
|
| 562 | + imagestring($this->image, 3, $destX - imagesx($markerImg), $destY + intval($markerImageOffsetY), $count, $color); |
|
| 563 | + } |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Draw kml trace on the map. |
|
| 568 | + */ |
|
| 569 | + public function drawKML() { |
|
| 570 | + // TODO get colour from kml node (not currently supported in geoPHP) |
|
| 571 | + $col = imagecolorallocatealpha($this->image, 255, 0, 0, .4 * 127); |
|
| 572 | + $kmlgeom = geoPHP::load(file_get_contents($this->kmlFileName), 'kml'); |
|
| 573 | + $this->drawGeometry($kmlgeom, $col); |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | + * Draw geometry or geometry collection on the map. |
|
| 578 | + * |
|
| 579 | + * @param Geometry $geom |
|
| 580 | + * @param int $colour |
|
| 581 | + * drawing colour |
|
| 582 | + */ |
|
| 583 | + private function drawGeometry($geom, $colour) { |
|
| 584 | + if(empty($geom)) return; |
|
| 585 | + |
|
| 586 | + switch($geom->geometryType()) { |
|
| 587 | + case 'GeometryCollection' : |
|
| 588 | + // recursively draw part of the collection |
|
| 589 | + for($i = 1; $i < $geom->numGeometries() + 1; $i++) { |
|
| 590 | + $_geom = $geom->geometryN($i); |
|
| 591 | + $this->drawGeometry($_geom, $colour); |
|
| 592 | + } |
|
| 593 | + break; |
|
| 594 | + case 'MultiPolygon' : |
|
| 595 | + case 'MultiLineString' : |
|
| 596 | + case 'MultiPoint' : |
|
| 597 | + // TODO implement / do nothing |
|
| 598 | + break; |
|
| 599 | + case 'Polygon' : |
|
| 600 | + $this->drawPolygon($geom, $colour); |
|
| 601 | + break; |
|
| 602 | + case 'LineString' : |
|
| 603 | + $this->drawLineString($geom, $colour); |
|
| 604 | + break; |
|
| 605 | + case 'Point' : |
|
| 606 | + $this->drawPoint($geom, $colour); |
|
| 607 | + break; |
|
| 608 | + default : |
|
| 609 | + // draw nothing |
|
| 610 | + break; |
|
| 611 | + } |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * Draw a polygon on the map. |
|
| 616 | + * |
|
| 617 | + * @param Polygon $polygon |
|
| 618 | + * @param int $colour |
|
| 619 | + * drawing colour |
|
| 620 | + */ |
|
| 621 | + private function drawPolygon($polygon, $colour) { |
|
| 622 | + // TODO implementation of drawing holes, |
|
| 623 | + // maybe draw the polygon to an in-memory image and use imagecopy, draw polygon in col., draw holes in bgcol? |
|
| 624 | + |
|
| 625 | + // print_r('Polygon:<br />'); |
|
| 626 | + // print_r($polygon); |
|
| 627 | + $extPoints = array(); |
|
| 628 | + // extring is a linestring actually.. |
|
| 629 | + $extRing = $polygon->exteriorRing(); |
|
| 630 | + |
|
| 631 | + for($i = 1; $i < $extRing->numGeometries(); $i++) { |
|
| 632 | + $p1 = $extRing->geometryN($i); |
|
| 633 | + $x = floor(($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))); |
|
| 634 | + $y = floor(($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p1->y(), $this->zoom))); |
|
| 635 | + $extPoints [] = $x; |
|
| 636 | + $extPoints [] = $y; |
|
| 637 | + } |
|
| 638 | + // print_r('points:('.($i-1).')<br />'); |
|
| 639 | + // print_r($extPoints); |
|
| 640 | + // imagepolygon ($this->image, $extPoints, $i-1, $colour ); |
|
| 641 | + imagefilledpolygon($this->image, $extPoints, $i - 1, $colour); |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + /** |
|
| 645 | + * Draw a line on the map. |
|
| 646 | + * |
|
| 647 | + * @param LineString $line |
|
| 648 | + * @param int $colour |
|
| 649 | + * drawing colour |
|
| 650 | + */ |
|
| 651 | + private function drawLineString($line, $colour) { |
|
| 652 | + imagesetthickness($this->image, 2); |
|
| 653 | + for($p = 1; $p < $line->numGeometries(); $p++) { |
|
| 654 | + // get first pair of points |
|
| 655 | + $p1 = $line->geometryN($p); |
|
| 656 | + $p2 = $line->geometryN($p + 1); |
|
| 657 | + // translate to paper space |
|
| 658 | + $x1 = floor(($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))); |
|
| 659 | + $y1 = floor(($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p1->y(), $this->zoom))); |
|
| 660 | + $x2 = floor(($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p2->x(), $this->zoom))); |
|
| 661 | + $y2 = floor(($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p2->y(), $this->zoom))); |
|
| 662 | + // draw to image |
|
| 663 | + imageline($this->image, $x1, $y1, $x2, $y2, $colour); |
|
| 664 | + } |
|
| 665 | + imagesetthickness($this->image, 1); |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + /** |
|
| 669 | + * Draw a point on the map. |
|
| 670 | + * |
|
| 671 | + * @param Point $point |
|
| 672 | + * @param int $colour |
|
| 673 | + * drawing colour |
|
| 674 | + */ |
|
| 675 | + private function drawPoint($point, $colour) { |
|
| 676 | + imagesetthickness($this->image, 2); |
|
| 677 | + // translate to paper space |
|
| 678 | + $cx = floor(($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($point->x(), $this->zoom))); |
|
| 679 | + $cy = floor(($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($point->y(), $this->zoom))); |
|
| 680 | + $r = 5; |
|
| 681 | + // draw to image |
|
| 682 | + // imageellipse($this->image, $cx, $cy,$r, $r, $colour); |
|
| 683 | + imagefilledellipse($this->image, $cx, $cy, $r, $r, $colour); |
|
| 684 | + // don't use imageellipse because the imagesetthickness function has |
|
| 685 | + // no effect. So the better workaround is to use imagearc. |
|
| 686 | + imagearc($this->image, $cx, $cy, $r, $r, 0, 359, $colour); |
|
| 687 | + imagesetthickness($this->image, 1); |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + /** |
|
| 691 | + * Draw gpx trace on the map. |
|
| 692 | + */ |
|
| 693 | + public function drawGPX() { |
|
| 694 | + $col = imagecolorallocatealpha($this->image, 0, 0, 255, .4 * 127); |
|
| 695 | + $gpxgeom = geoPHP::load(file_get_contents($this->gpxFileName), 'gpx'); |
|
| 696 | + $this->drawGeometry($gpxgeom, $col); |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + /** |
|
| 700 | + * Draw geojson on the map. |
|
| 701 | + */ |
|
| 702 | + public function drawGeojson() { |
|
| 703 | + $col = imagecolorallocatealpha($this->image, 255, 0, 255, .4 * 127); |
|
| 704 | + $gpxgeom = geoPHP::load(file_get_contents($this->geojsonFileName), 'json'); |
|
| 705 | + $this->drawGeometry($gpxgeom, $col); |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + /** |
|
| 709 | + * add copyright and origin notice and icons to the map. |
|
| 710 | + */ |
|
| 711 | + public function drawCopyright() { |
|
| 712 | + $logoBaseDir = dirname(__FILE__) . '/' . 'logo/'; |
|
| 713 | + $logoImg = imagecreatefrompng($logoBaseDir . $this->tileInfo ['openstreetmap'] ['logo']); |
|
| 714 | + $textcolor = imagecolorallocate($this->image, 0, 0, 0); |
|
| 715 | + $bgcolor = imagecolorallocate($this->image, 200, 200, 200); |
|
| 716 | + |
|
| 717 | + imagecopy($this->image, $logoImg, 0, imagesy($this->image) - imagesy($logoImg), 0, 0, imagesx($logoImg), imagesy($logoImg)); |
|
| 718 | + imagestring($this->image, 1, imagesx($logoImg) + 2, imagesy($this->image) - imagesy($logoImg) + 1, $this->tileInfo ['openstreetmap'] ['txt'], $bgcolor); |
|
| 719 | + imagestring($this->image, 1, imagesx($logoImg) + 1, imagesy($this->image) - imagesy($logoImg), $this->tileInfo ['openstreetmap'] ['txt'], $textcolor); |
|
| 720 | + |
|
| 721 | + // additional tile source info, ie. who created/hosted the tiles |
|
| 722 | + if($this->maptype != 'openstreetmap') { |
|
| 723 | + $iconImg = imagecreatefrompng($logoBaseDir . $this->tileInfo [$this->maptype] ['logo']); |
|
| 724 | + imagecopy($this->image, $iconImg, imagesx($logoImg) + 1, imagesy($this->image) - imagesy($iconImg), 0, 0, imagesx($iconImg), imagesy($iconImg)); |
|
| 725 | + imagestring($this->image, 1, imagesx($logoImg) + imagesx($iconImg) + 4, imagesy($this->image) - ceil(imagesy($logoImg) / 2) + 1, $this->tileInfo [$this->maptype] ['txt'], $bgcolor); |
|
| 726 | + imagestring($this->image, 1, imagesx($logoImg) + imagesx($iconImg) + 3, imagesy($this->image) - ceil(imagesy($logoImg) / 2), $this->tileInfo [$this->maptype] ['txt'], $textcolor); |
|
| 727 | + } |
|
| 728 | + } |
|
| 729 | 729 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * See the License for the specific language governing permissions and |
| 19 | 19 | * limitations under the License. |
| 20 | 20 | */ |
| 21 | -include_once(realpath(dirname(__FILE__)) . '/../geophp/geoPHP/geoPHP.inc'); |
|
| 21 | +include_once(realpath(dirname(__FILE__)).'/../geophp/geoPHP/geoPHP.inc'); |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | $this->height = $height; |
| 175 | 175 | // validate + set maptype |
| 176 | 176 | $this->maptype = $this->tileDefaultSrc; |
| 177 | - if(array_key_exists($maptype, $this->tileInfo)) { |
|
| 177 | + if (array_key_exists($maptype, $this->tileInfo)) { |
|
| 178 | 178 | $this->maptype = $maptype; |
| 179 | 179 | } |
| 180 | 180 | $this->markers = $markers; |
@@ -182,9 +182,9 @@ discard block |
||
| 182 | 182 | $this->gpxFileName = $gpx; |
| 183 | 183 | $this->geojsonFileName = $geojson; |
| 184 | 184 | $this->mediaBaseDir = $mediaDir; |
| 185 | - $this->tileCacheBaseDir = $tileCacheBaseDir . '/olmaptiles'; |
|
| 185 | + $this->tileCacheBaseDir = $tileCacheBaseDir.'/olmaptiles'; |
|
| 186 | 186 | $this->useTileCache = $this->tileCacheBaseDir !== ''; |
| 187 | - $this->mapCacheBaseDir = $mediaDir . '/olmapmaps'; |
|
| 187 | + $this->mapCacheBaseDir = $mediaDir.'/olmapmaps'; |
|
| 188 | 188 | $this->autoZoomExtent = $autoZoomExtent; |
| 189 | 189 | $this->apikey = $apikey; |
| 190 | 190 | } |
@@ -196,15 +196,15 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | public function getMap() { |
| 198 | 198 | try { |
| 199 | - if($this->autoZoomExtent) { |
|
| 199 | + if ($this->autoZoomExtent) { |
|
| 200 | 200 | $this->autoZoom(); |
| 201 | 201 | } |
| 202 | - } catch(Exception $e) { |
|
| 202 | + } catch (Exception $e) { |
|
| 203 | 203 | dbglog($e); |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | // use map cache, so check cache for map |
| 207 | - if(!$this->checkMapCache()) { |
|
| 207 | + if (!$this->checkMapCache()) { |
|
| 208 | 208 | // map is not in cache, needs to be build |
| 209 | 209 | $this->makeMap(); |
| 210 | 210 | $this->mkdir_recursive(dirname($this->mapCacheIDToFilename()), 0777); |
@@ -226,38 +226,38 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | private function autoZoom($paddingFactor = 1.0) { |
| 228 | 228 | $geoms = array(); |
| 229 | - $geoms [] = new Point ($this->lon, $this->lat); |
|
| 230 | - if(!empty ($this->markers)) { |
|
| 231 | - foreach($this->markers as $marker) { |
|
| 232 | - $geoms [] = new Point ($marker ['lon'], $marker ['lat']); |
|
| 229 | + $geoms [] = new Point($this->lon, $this->lat); |
|
| 230 | + if (!empty ($this->markers)) { |
|
| 231 | + foreach ($this->markers as $marker) { |
|
| 232 | + $geoms [] = new Point($marker ['lon'], $marker ['lat']); |
|
| 233 | 233 | } |
| 234 | 234 | } |
| 235 | 235 | $g = false; |
| 236 | - if(file_exists($this->kmlFileName)) { |
|
| 236 | + if (file_exists($this->kmlFileName)) { |
|
| 237 | 237 | $g = geoPHP::load(file_get_contents($this->kmlFileName), 'kml'); |
| 238 | - if($g !== false) { |
|
| 238 | + if ($g !== false) { |
|
| 239 | 239 | $geoms [] = $g; |
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | - if(file_exists($this->gpxFileName)) { |
|
| 242 | + if (file_exists($this->gpxFileName)) { |
|
| 243 | 243 | $g = geoPHP::load(file_get_contents($this->gpxFileName), 'gpx'); |
| 244 | - if($g !== false) { |
|
| 244 | + if ($g !== false) { |
|
| 245 | 245 | $geoms [] = $g; |
| 246 | 246 | } |
| 247 | 247 | } |
| 248 | - if(file_exists($this->geojsonFileName)) { |
|
| 248 | + if (file_exists($this->geojsonFileName)) { |
|
| 249 | 249 | $g = geoPHP::load(file_get_contents($this->geojsonFileName), 'geojson'); |
| 250 | - if($g !== false) { |
|
| 250 | + if ($g !== false) { |
|
| 251 | 251 | $geoms [] = $g; |
| 252 | 252 | } |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - if(count($geoms) <= 1) { |
|
| 255 | + if (count($geoms) <= 1) { |
|
| 256 | 256 | dbglog($geoms, "StaticMap::autoZoom: Skip setting autozoom options"); |
| 257 | 257 | return; |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - $geom = new GeometryCollection ($geoms); |
|
| 260 | + $geom = new GeometryCollection($geoms); |
|
| 261 | 261 | $centroid = $geom->centroid(); |
| 262 | 262 | $bbox = $geom->getBBox(); |
| 263 | 263 | |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | $resolution = max($resolutionHorizontal, $resolutionVertical) * $paddingFactor; |
| 274 | 274 | $zoom = log(360 / ($resolution * $this->tileSize), 2); |
| 275 | 275 | |
| 276 | - if(is_finite($zoom) && $zoom < 15 && $zoom > 2) { |
|
| 276 | + if (is_finite($zoom) && $zoom < 15 && $zoom > 2) { |
|
| 277 | 277 | $this->zoom = floor($zoom); |
| 278 | 278 | } |
| 279 | 279 | $this->lon = $centroid->getX(); |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | public function checkMapCache() { |
| 285 | 285 | $this->mapCacheID = md5($this->serializeParams()); |
| 286 | 286 | $filename = $this->mapCacheIDToFilename(); |
| 287 | - if(file_exists($filename)) |
|
| 287 | + if (file_exists($filename)) |
|
| 288 | 288 | return true; |
| 289 | 289 | } |
| 290 | 290 | |
@@ -306,12 +306,12 @@ discard block |
||
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | public function mapCacheIDToFilename() { |
| 309 | - if(!$this->mapCacheFile) { |
|
| 310 | - $this->mapCacheFile = $this->mapCacheBaseDir . "/" . $this->maptype . "/" . $this->zoom . "/cache_" |
|
| 311 | - . substr($this->mapCacheID, 0, 2) . "/" . substr($this->mapCacheID, 2, 2) |
|
| 312 | - . "/" . substr($this->mapCacheID, 4); |
|
| 309 | + if (!$this->mapCacheFile) { |
|
| 310 | + $this->mapCacheFile = $this->mapCacheBaseDir."/".$this->maptype."/".$this->zoom."/cache_" |
|
| 311 | + . substr($this->mapCacheID, 0, 2)."/".substr($this->mapCacheID, 2, 2) |
|
| 312 | + . "/".substr($this->mapCacheID, 4); |
|
| 313 | 313 | } |
| 314 | - return $this->mapCacheFile . "." . $this->mapCacheExtension; |
|
| 314 | + return $this->mapCacheFile.".".$this->mapCacheExtension; |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
@@ -320,13 +320,13 @@ discard block |
||
| 320 | 320 | public function makeMap() { |
| 321 | 321 | $this->initCoords(); |
| 322 | 322 | $this->createBaseMap(); |
| 323 | - if(!empty ($this->markers)) |
|
| 323 | + if (!empty ($this->markers)) |
|
| 324 | 324 | $this->placeMarkers(); |
| 325 | - if(file_exists($this->kmlFileName)) |
|
| 325 | + if (file_exists($this->kmlFileName)) |
|
| 326 | 326 | $this->drawKML(); |
| 327 | - if(file_exists($this->gpxFileName)) |
|
| 327 | + if (file_exists($this->gpxFileName)) |
|
| 328 | 328 | $this->drawGPX(); |
| 329 | - if(file_exists($this->geojsonFileName)) |
|
| 329 | + if (file_exists($this->geojsonFileName)) |
|
| 330 | 330 | $this->drawGeojson(); |
| 331 | 331 | |
| 332 | 332 | $this->drawCopyright(); |
@@ -377,8 +377,8 @@ discard block |
||
| 377 | 377 | $this->offsetX += floor($startX - floor($this->centerX)) * $this->tileSize; |
| 378 | 378 | $this->offsetY += floor($startY - floor($this->centerY)) * $this->tileSize; |
| 379 | 379 | |
| 380 | - for($x = $startX; $x <= $endX; $x++) { |
|
| 381 | - for($y = $startY; $y <= $endY; $y++) { |
|
| 380 | + for ($x = $startX; $x <= $endX; $x++) { |
|
| 381 | + for ($y = $startY; $y <= $endY; $y++) { |
|
| 382 | 382 | $url = str_replace( |
| 383 | 383 | array( |
| 384 | 384 | '{Z}', |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | $url .= $this->apikey; |
| 394 | 394 | |
| 395 | 395 | $tileData = $this->fetchTile($url); |
| 396 | - if($tileData) { |
|
| 396 | + if ($tileData) { |
|
| 397 | 397 | $tileImage = imagecreatefromstring($tileData); |
| 398 | 398 | } else { |
| 399 | 399 | $tileImage = imagecreate($this->tileSize, $this->tileSize); |
@@ -417,11 +417,11 @@ discard block |
||
| 417 | 417 | * @param string $url |
| 418 | 418 | */ |
| 419 | 419 | public function fetchTile($url) { |
| 420 | - if($this->useTileCache && ($cached = $this->checkTileCache($url))) |
|
| 420 | + if ($this->useTileCache && ($cached = $this->checkTileCache($url))) |
|
| 421 | 421 | return $cached; |
| 422 | 422 | |
| 423 | - $_UA = 'Mozilla/4.0 (compatible; DokuWikiSpatial HTTP Client; ' . PHP_OS . ')'; |
|
| 424 | - if(function_exists("curl_init")) { |
|
| 423 | + $_UA = 'Mozilla/4.0 (compatible; DokuWikiSpatial HTTP Client; '.PHP_OS.')'; |
|
| 424 | + if (function_exists("curl_init")) { |
|
| 425 | 425 | // use cUrl |
| 426 | 426 | $ch = curl_init(); |
| 427 | 427 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
@@ -433,18 +433,18 @@ discard block |
||
| 433 | 433 | } else { |
| 434 | 434 | // use file_get_contents |
| 435 | 435 | global $conf; |
| 436 | - $opts = array( |
|
| 436 | + $opts = array( |
|
| 437 | 437 | 'http' => array( |
| 438 | 438 | 'method' => "GET", |
| 439 | - 'header' => "Accept-language: en\r\n" . "User-Agent: $_UA\r\n" . "accept: image/png\r\n", |
|
| 440 | - 'proxy' => "tcp://" . $conf ['proxy'] ['host'] . ":" . $conf ['proxy'] ['port'], |
|
| 439 | + 'header' => "Accept-language: en\r\n"."User-Agent: $_UA\r\n"."accept: image/png\r\n", |
|
| 440 | + 'proxy' => "tcp://".$conf ['proxy'] ['host'].":".$conf ['proxy'] ['port'], |
|
| 441 | 441 | 'request_fulluri' => true |
| 442 | 442 | ) |
| 443 | 443 | ); |
| 444 | 444 | $context = stream_context_create($opts); |
| 445 | 445 | $tile = file_get_contents($url, false, $context); |
| 446 | 446 | } |
| 447 | - if($tile && $this->useTileCache) { |
|
| 447 | + if ($tile && $this->useTileCache) { |
|
| 448 | 448 | $this->writeTileToCache($url, $tile); |
| 449 | 449 | } |
| 450 | 450 | return $tile; |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | */ |
| 457 | 457 | public function checkTileCache($url) { |
| 458 | 458 | $filename = $this->tileUrlToFilename($url); |
| 459 | - if(file_exists($filename)) { |
|
| 459 | + if (file_exists($filename)) { |
|
| 460 | 460 | return file_get_contents($filename); |
| 461 | 461 | } |
| 462 | 462 | } |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | * @return string |
| 468 | 468 | */ |
| 469 | 469 | public function tileUrlToFilename($url) { |
| 470 | - return $this->tileCacheBaseDir . "/" . str_replace( |
|
| 470 | + return $this->tileCacheBaseDir."/".str_replace( |
|
| 471 | 471 | array( |
| 472 | 472 | 'http://' |
| 473 | 473 | ), '', $url |
@@ -506,9 +506,9 @@ discard block |
||
| 506 | 506 | $count = 0; |
| 507 | 507 | $color = imagecolorallocate($this->image, 0, 0, 0); |
| 508 | 508 | $bgcolor = imagecolorallocate($this->image, 200, 200, 200); |
| 509 | - $markerBaseDir = dirname(__FILE__) . '/icons'; |
|
| 509 | + $markerBaseDir = dirname(__FILE__).'/icons'; |
|
| 510 | 510 | // loop thru marker array |
| 511 | - foreach($this->markers as $marker) { |
|
| 511 | + foreach ($this->markers as $marker) { |
|
| 512 | 512 | // set some local variables |
| 513 | 513 | $markerLat = $marker ['lat']; |
| 514 | 514 | $markerLon = $marker ['lon']; |
@@ -518,18 +518,18 @@ discard block |
||
| 518 | 518 | $markerShadow = ''; |
| 519 | 519 | $matches = false; |
| 520 | 520 | // check for marker type, get settings from markerPrototypes |
| 521 | - if($markerType) { |
|
| 522 | - foreach($this->markerPrototypes as $markerPrototype) { |
|
| 523 | - if(preg_match($markerPrototype ['regex'], $markerType, $matches)) { |
|
| 524 | - $markerFilename = $matches [0] . $markerPrototype ['extension']; |
|
| 525 | - if($markerPrototype ['offsetImage']) { |
|
| 521 | + if ($markerType) { |
|
| 522 | + foreach ($this->markerPrototypes as $markerPrototype) { |
|
| 523 | + if (preg_match($markerPrototype ['regex'], $markerType, $matches)) { |
|
| 524 | + $markerFilename = $matches [0].$markerPrototype ['extension']; |
|
| 525 | + if ($markerPrototype ['offsetImage']) { |
|
| 526 | 526 | list ($markerImageOffsetX, $markerImageOffsetY) = explode( |
| 527 | 527 | ",", |
| 528 | 528 | $markerPrototype ['offsetImage'] |
| 529 | 529 | ); |
| 530 | 530 | } |
| 531 | 531 | $markerShadow = $markerPrototype ['shadow']; |
| 532 | - if($markerShadow) { |
|
| 532 | + if ($markerShadow) { |
|
| 533 | 533 | list ($markerShadowOffsetX, $markerShadowOffsetY) = explode( |
| 534 | 534 | ",", |
| 535 | 535 | $markerPrototype ['offsetShadow'] |
@@ -539,20 +539,20 @@ discard block |
||
| 539 | 539 | } |
| 540 | 540 | } |
| 541 | 541 | // create img resource |
| 542 | - if(file_exists($markerBaseDir . '/' . $markerFilename)) { |
|
| 543 | - $markerImg = imagecreatefrompng($markerBaseDir . '/' . $markerFilename); |
|
| 542 | + if (file_exists($markerBaseDir.'/'.$markerFilename)) { |
|
| 543 | + $markerImg = imagecreatefrompng($markerBaseDir.'/'.$markerFilename); |
|
| 544 | 544 | } else { |
| 545 | - $markerImg = imagecreatefrompng($markerBaseDir . '/marker.png'); |
|
| 545 | + $markerImg = imagecreatefrompng($markerBaseDir.'/marker.png'); |
|
| 546 | 546 | } |
| 547 | 547 | // check for shadow + create shadow recource |
| 548 | - if($markerShadow && file_exists($markerBaseDir . '/' . $markerShadow)) { |
|
| 549 | - $markerShadowImg = imagecreatefrompng($markerBaseDir . '/' . $markerShadow); |
|
| 548 | + if ($markerShadow && file_exists($markerBaseDir.'/'.$markerShadow)) { |
|
| 549 | + $markerShadowImg = imagecreatefrompng($markerBaseDir.'/'.$markerShadow); |
|
| 550 | 550 | } |
| 551 | 551 | // calc position |
| 552 | 552 | $destX = floor(($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($markerLon, $this->zoom))); |
| 553 | 553 | $destY = floor(($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($markerLat, $this->zoom))); |
| 554 | 554 | // copy shadow on basemap |
| 555 | - if($markerShadow && $markerShadowImg) { |
|
| 555 | + if ($markerShadow && $markerShadowImg) { |
|
| 556 | 556 | imagecopy($this->image, $markerShadowImg, $destX + intval($markerShadowOffsetX), $destY + intval($markerShadowOffsetY), 0, 0, imagesx($markerShadowImg), imagesy($markerShadowImg)); |
| 557 | 557 | } |
| 558 | 558 | // copy marker on basemap above shadow |
@@ -581,12 +581,12 @@ discard block |
||
| 581 | 581 | * drawing colour |
| 582 | 582 | */ |
| 583 | 583 | private function drawGeometry($geom, $colour) { |
| 584 | - if(empty($geom)) return; |
|
| 584 | + if (empty($geom)) return; |
|
| 585 | 585 | |
| 586 | - switch($geom->geometryType()) { |
|
| 586 | + switch ($geom->geometryType()) { |
|
| 587 | 587 | case 'GeometryCollection' : |
| 588 | 588 | // recursively draw part of the collection |
| 589 | - for($i = 1; $i < $geom->numGeometries() + 1; $i++) { |
|
| 589 | + for ($i = 1; $i < $geom->numGeometries() + 1; $i++) { |
|
| 590 | 590 | $_geom = $geom->geometryN($i); |
| 591 | 591 | $this->drawGeometry($_geom, $colour); |
| 592 | 592 | } |
@@ -628,7 +628,7 @@ discard block |
||
| 628 | 628 | // extring is a linestring actually.. |
| 629 | 629 | $extRing = $polygon->exteriorRing(); |
| 630 | 630 | |
| 631 | - for($i = 1; $i < $extRing->numGeometries(); $i++) { |
|
| 631 | + for ($i = 1; $i < $extRing->numGeometries(); $i++) { |
|
| 632 | 632 | $p1 = $extRing->geometryN($i); |
| 633 | 633 | $x = floor(($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))); |
| 634 | 634 | $y = floor(($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p1->y(), $this->zoom))); |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | */ |
| 651 | 651 | private function drawLineString($line, $colour) { |
| 652 | 652 | imagesetthickness($this->image, 2); |
| 653 | - for($p = 1; $p < $line->numGeometries(); $p++) { |
|
| 653 | + for ($p = 1; $p < $line->numGeometries(); $p++) { |
|
| 654 | 654 | // get first pair of points |
| 655 | 655 | $p1 = $line->geometryN($p); |
| 656 | 656 | $p2 = $line->geometryN($p + 1); |
@@ -709,8 +709,8 @@ discard block |
||
| 709 | 709 | * add copyright and origin notice and icons to the map. |
| 710 | 710 | */ |
| 711 | 711 | public function drawCopyright() { |
| 712 | - $logoBaseDir = dirname(__FILE__) . '/' . 'logo/'; |
|
| 713 | - $logoImg = imagecreatefrompng($logoBaseDir . $this->tileInfo ['openstreetmap'] ['logo']); |
|
| 712 | + $logoBaseDir = dirname(__FILE__).'/'.'logo/'; |
|
| 713 | + $logoImg = imagecreatefrompng($logoBaseDir.$this->tileInfo ['openstreetmap'] ['logo']); |
|
| 714 | 714 | $textcolor = imagecolorallocate($this->image, 0, 0, 0); |
| 715 | 715 | $bgcolor = imagecolorallocate($this->image, 200, 200, 200); |
| 716 | 716 | |
@@ -719,8 +719,8 @@ discard block |
||
| 719 | 719 | imagestring($this->image, 1, imagesx($logoImg) + 1, imagesy($this->image) - imagesy($logoImg), $this->tileInfo ['openstreetmap'] ['txt'], $textcolor); |
| 720 | 720 | |
| 721 | 721 | // additional tile source info, ie. who created/hosted the tiles |
| 722 | - if($this->maptype != 'openstreetmap') { |
|
| 723 | - $iconImg = imagecreatefrompng($logoBaseDir . $this->tileInfo [$this->maptype] ['logo']); |
|
| 722 | + if ($this->maptype != 'openstreetmap') { |
|
| 723 | + $iconImg = imagecreatefrompng($logoBaseDir.$this->tileInfo [$this->maptype] ['logo']); |
|
| 724 | 724 | imagecopy($this->image, $iconImg, imagesx($logoImg) + 1, imagesy($this->image) - imagesy($iconImg), 0, 0, imagesx($iconImg), imagesy($iconImg)); |
| 725 | 725 | imagestring($this->image, 1, imagesx($logoImg) + imagesx($iconImg) + 4, imagesy($this->image) - ceil(imagesy($logoImg) / 2) + 1, $this->tileInfo [$this->maptype] ['txt'], $bgcolor); |
| 726 | 726 | imagestring($this->image, 1, imagesx($logoImg) + imagesx($iconImg) + 3, imagesy($this->image) - ceil(imagesy($logoImg) / 2), $this->tileInfo [$this->maptype] ['txt'], $textcolor); |
@@ -284,8 +284,9 @@ discard block |
||
| 284 | 284 | public function checkMapCache() { |
| 285 | 285 | $this->mapCacheID = md5($this->serializeParams()); |
| 286 | 286 | $filename = $this->mapCacheIDToFilename(); |
| 287 | - if(file_exists($filename)) |
|
| 288 | - return true; |
|
| 287 | + if(file_exists($filename)) { |
|
| 288 | + return true; |
|
| 289 | + } |
|
| 289 | 290 | } |
| 290 | 291 | |
| 291 | 292 | public function serializeParams() { |
@@ -320,14 +321,18 @@ discard block |
||
| 320 | 321 | public function makeMap() { |
| 321 | 322 | $this->initCoords(); |
| 322 | 323 | $this->createBaseMap(); |
| 323 | - if(!empty ($this->markers)) |
|
| 324 | - $this->placeMarkers(); |
|
| 325 | - if(file_exists($this->kmlFileName)) |
|
| 326 | - $this->drawKML(); |
|
| 327 | - if(file_exists($this->gpxFileName)) |
|
| 328 | - $this->drawGPX(); |
|
| 329 | - if(file_exists($this->geojsonFileName)) |
|
| 330 | - $this->drawGeojson(); |
|
| 324 | + if(!empty ($this->markers)) { |
|
| 325 | + $this->placeMarkers(); |
|
| 326 | + } |
|
| 327 | + if(file_exists($this->kmlFileName)) { |
|
| 328 | + $this->drawKML(); |
|
| 329 | + } |
|
| 330 | + if(file_exists($this->gpxFileName)) { |
|
| 331 | + $this->drawGPX(); |
|
| 332 | + } |
|
| 333 | + if(file_exists($this->geojsonFileName)) { |
|
| 334 | + $this->drawGeojson(); |
|
| 335 | + } |
|
| 331 | 336 | |
| 332 | 337 | $this->drawCopyright(); |
| 333 | 338 | } |
@@ -417,8 +422,9 @@ discard block |
||
| 417 | 422 | * @param string $url |
| 418 | 423 | */ |
| 419 | 424 | public function fetchTile($url) { |
| 420 | - if($this->useTileCache && ($cached = $this->checkTileCache($url))) |
|
| 421 | - return $cached; |
|
| 425 | + if($this->useTileCache && ($cached = $this->checkTileCache($url))) { |
|
| 426 | + return $cached; |
|
| 427 | + } |
|
| 422 | 428 | |
| 423 | 429 | $_UA = 'Mozilla/4.0 (compatible; DokuWikiSpatial HTTP Client; ' . PHP_OS . ')'; |
| 424 | 430 | if(function_exists("curl_init")) { |
@@ -581,7 +587,9 @@ discard block |
||
| 581 | 587 | * drawing colour |
| 582 | 588 | */ |
| 583 | 589 | private function drawGeometry($geom, $colour) { |
| 584 | - if(empty($geom)) return; |
|
| 590 | + if(empty($geom)) { |
|
| 591 | + return; |
|
| 592 | + } |
|
| 585 | 593 | |
| 586 | 594 | switch($geom->geometryType()) { |
| 587 | 595 | case 'GeometryCollection' : |
@@ -24,44 +24,44 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class general_plugin_openlayersmap_test extends DokuWikiTest { |
| 26 | 26 | |
| 27 | - protected $pluginsEnabled = array('openlayersmap', 'geophp'); |
|
| 27 | + protected $pluginsEnabled = array('openlayersmap', 'geophp'); |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Simple test to make sure the plugin.info.txt is in correct format |
|
| 31 | - */ |
|
| 32 | - public function test_plugininfo() { |
|
| 33 | - $file = __DIR__ . '/../plugin.info.txt'; |
|
| 34 | - $this->assertFileExists($file); |
|
| 29 | + /** |
|
| 30 | + * Simple test to make sure the plugin.info.txt is in correct format |
|
| 31 | + */ |
|
| 32 | + public function test_plugininfo() { |
|
| 33 | + $file = __DIR__ . '/../plugin.info.txt'; |
|
| 34 | + $this->assertFileExists($file); |
|
| 35 | 35 | |
| 36 | - $info = confToHash($file); |
|
| 36 | + $info = confToHash($file); |
|
| 37 | 37 | |
| 38 | - $this->assertArrayHasKey('base', $info); |
|
| 39 | - $this->assertArrayHasKey('author', $info); |
|
| 40 | - $this->assertArrayHasKey('email', $info); |
|
| 41 | - $this->assertArrayHasKey('date', $info); |
|
| 42 | - $this->assertArrayHasKey('name', $info); |
|
| 43 | - $this->assertArrayHasKey('desc', $info); |
|
| 44 | - $this->assertArrayHasKey('url', $info); |
|
| 38 | + $this->assertArrayHasKey('base', $info); |
|
| 39 | + $this->assertArrayHasKey('author', $info); |
|
| 40 | + $this->assertArrayHasKey('email', $info); |
|
| 41 | + $this->assertArrayHasKey('date', $info); |
|
| 42 | + $this->assertArrayHasKey('name', $info); |
|
| 43 | + $this->assertArrayHasKey('desc', $info); |
|
| 44 | + $this->assertArrayHasKey('url', $info); |
|
| 45 | 45 | |
| 46 | - $this->assertEquals('openlayersmap', $info['base']); |
|
| 47 | - $this->assertRegExp('/^https?:\/\//', $info['url']); |
|
| 48 | - $this->assertTrue(mail_isvalid($info['email'])); |
|
| 49 | - $this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']); |
|
| 50 | - $this->assertTrue(false !== strtotime($info['date'])); |
|
| 51 | - } |
|
| 46 | + $this->assertEquals('openlayersmap', $info['base']); |
|
| 47 | + $this->assertRegExp('/^https?:\/\//', $info['url']); |
|
| 48 | + $this->assertTrue(mail_isvalid($info['email'])); |
|
| 49 | + $this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']); |
|
| 50 | + $this->assertTrue(false !== strtotime($info['date'])); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * test if plugin is loaded. |
|
| 55 | - */ |
|
| 56 | - public function test_plugin_openlayersmap_isloaded() { |
|
| 57 | - global $plugin_controller; |
|
| 58 | - $this->assertTrue( |
|
| 59 | - in_array('geophp', $plugin_controller->getList()), |
|
| 60 | - "geophp plugin is loaded" |
|
| 61 | - ); |
|
| 62 | - $this->assertTrue( |
|
| 63 | - in_array('openlayersmap', $plugin_controller->getList()), |
|
| 64 | - "openlayersmap plugin is loaded" |
|
| 65 | - ); |
|
| 66 | - } |
|
| 53 | + /** |
|
| 54 | + * test if plugin is loaded. |
|
| 55 | + */ |
|
| 56 | + public function test_plugin_openlayersmap_isloaded() { |
|
| 57 | + global $plugin_controller; |
|
| 58 | + $this->assertTrue( |
|
| 59 | + in_array('geophp', $plugin_controller->getList()), |
|
| 60 | + "geophp plugin is loaded" |
|
| 61 | + ); |
|
| 62 | + $this->assertTrue( |
|
| 63 | + in_array('openlayersmap', $plugin_controller->getList()), |
|
| 64 | + "openlayersmap plugin is loaded" |
|
| 65 | + ); |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -30,7 +30,7 @@ |
||
| 30 | 30 | * Simple test to make sure the plugin.info.txt is in correct format |
| 31 | 31 | */ |
| 32 | 32 | public function test_plugininfo() { |
| 33 | - $file = __DIR__ . '/../plugin.info.txt'; |
|
| 33 | + $file = __DIR__.'/../plugin.info.txt'; |
|
| 34 | 34 | $this->assertFileExists($file); |
| 35 | 35 | |
| 36 | 36 | $info = confToHash($file); |
@@ -24,113 +24,113 @@ |
||
| 24 | 24 | * @author Mark Prins |
| 25 | 25 | */ |
| 26 | 26 | class helper_plugin_openlayersmap_staticmap extends DokuWiki_Plugin { |
| 27 | - /** maximum width of the resulting image. */ |
|
| 28 | - private $maxWidth = 1024; |
|
| 29 | - /** maximum heigth of the resulting image. */ |
|
| 30 | - private $maxHeight = 1024; |
|
| 27 | + /** maximum width of the resulting image. */ |
|
| 28 | + private $maxWidth = 1024; |
|
| 29 | + /** maximum heigth of the resulting image. */ |
|
| 30 | + private $maxHeight = 1024; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Provide metadata of the public methods of this class. |
|
| 34 | - * |
|
| 35 | - * @return array Information to all provided methods. |
|
| 36 | - */ |
|
| 37 | - public function getMethods(): array { |
|
| 38 | - $result = array(); |
|
| 39 | - $result[] = array( |
|
| 40 | - 'name' => 'getMap', |
|
| 41 | - 'desc' => 'returns url to the image', |
|
| 42 | - 'params' => array( |
|
| 43 | - 'lat' => 'float', |
|
| 44 | - 'lon' => 'float', |
|
| 45 | - 'zoom' => 'integer', |
|
| 46 | - 'size' => 'string', |
|
| 47 | - 'maptype' => 'string', |
|
| 48 | - 'markers' => 'string', |
|
| 49 | - 'gpx' => 'string', |
|
| 50 | - 'kml' => 'string', |
|
| 51 | - 'geojson' => 'string', |
|
| 52 | - 'apikey' => 'string' |
|
| 53 | - ), |
|
| 54 | - 'return' => array('image' => 'string'), |
|
| 55 | - ); |
|
| 56 | - return $result; |
|
| 57 | - } |
|
| 32 | + /** |
|
| 33 | + * Provide metadata of the public methods of this class. |
|
| 34 | + * |
|
| 35 | + * @return array Information to all provided methods. |
|
| 36 | + */ |
|
| 37 | + public function getMethods(): array { |
|
| 38 | + $result = array(); |
|
| 39 | + $result[] = array( |
|
| 40 | + 'name' => 'getMap', |
|
| 41 | + 'desc' => 'returns url to the image', |
|
| 42 | + 'params' => array( |
|
| 43 | + 'lat' => 'float', |
|
| 44 | + 'lon' => 'float', |
|
| 45 | + 'zoom' => 'integer', |
|
| 46 | + 'size' => 'string', |
|
| 47 | + 'maptype' => 'string', |
|
| 48 | + 'markers' => 'string', |
|
| 49 | + 'gpx' => 'string', |
|
| 50 | + 'kml' => 'string', |
|
| 51 | + 'geojson' => 'string', |
|
| 52 | + 'apikey' => 'string' |
|
| 53 | + ), |
|
| 54 | + 'return' => array('image' => 'string'), |
|
| 55 | + ); |
|
| 56 | + return $result; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Create the map. |
|
| 61 | - * |
|
| 62 | - * @param number lat the latitude of the map's center, eg. 40.714728 |
|
| 63 | - * @param number lon the longitude of the map's center, eg -73.998672 |
|
| 64 | - * @param number zoom the zoom level in the tile cache, eg. 14 |
|
| 65 | - * @param mixed size the size in WxH px, eg. 512x512 |
|
| 66 | - * @param string maptype the maptype, eg. cycle |
|
| 67 | - * @param mixed markers associative array of markers, array('lat'=>$lat,'lon'=>$lon,'type'=>$iconStyle), |
|
| 68 | - * eg. array('lat'=>40.702147,'lon'=>-74.015794,'type'=>lightblue1); |
|
| 69 | - * @param string gpx media link |
|
| 70 | - * @param string kml media link |
|
| 71 | - * @param string geojson media link |
|
| 72 | - * @param string optional API key eg. for Thunderforest maps |
|
| 73 | - * |
|
| 74 | - * @returns string media id url |
|
| 75 | - */ |
|
| 76 | - public function getMap($lat, $lon, $zoom, $size, $maptype, $markers, $gpx, $kml, $geojson, $apikey = ''): string { |
|
| 77 | - global $conf; |
|
| 78 | - // dbglog($markers,'helper_plugin_openlayersmap_staticmap::getMap: markers :'); |
|
| 59 | + /** |
|
| 60 | + * Create the map. |
|
| 61 | + * |
|
| 62 | + * @param number lat the latitude of the map's center, eg. 40.714728 |
|
| 63 | + * @param number lon the longitude of the map's center, eg -73.998672 |
|
| 64 | + * @param number zoom the zoom level in the tile cache, eg. 14 |
|
| 65 | + * @param mixed size the size in WxH px, eg. 512x512 |
|
| 66 | + * @param string maptype the maptype, eg. cycle |
|
| 67 | + * @param mixed markers associative array of markers, array('lat'=>$lat,'lon'=>$lon,'type'=>$iconStyle), |
|
| 68 | + * eg. array('lat'=>40.702147,'lon'=>-74.015794,'type'=>lightblue1); |
|
| 69 | + * @param string gpx media link |
|
| 70 | + * @param string kml media link |
|
| 71 | + * @param string geojson media link |
|
| 72 | + * @param string optional API key eg. for Thunderforest maps |
|
| 73 | + * |
|
| 74 | + * @returns string media id url |
|
| 75 | + */ |
|
| 76 | + public function getMap($lat, $lon, $zoom, $size, $maptype, $markers, $gpx, $kml, $geojson, $apikey = ''): string { |
|
| 77 | + global $conf; |
|
| 78 | + // dbglog($markers,'helper_plugin_openlayersmap_staticmap::getMap: markers :'); |
|
| 79 | 79 | |
| 80 | - // normalize zoom |
|
| 81 | - $zoom = $zoom ? intval($zoom) : 0; |
|
| 82 | - if($zoom > 18) $zoom = 18; |
|
| 83 | - // normalize WxH |
|
| 84 | - list($width, $height) = explode('x', $size); |
|
| 85 | - $width = intval($width); |
|
| 86 | - if($width > $this->maxWidth) $width = $this->maxWidth; |
|
| 87 | - $height = intval($height); |
|
| 88 | - if($height > $this->maxHeight) $height = $this->maxHeight; |
|
| 80 | + // normalize zoom |
|
| 81 | + $zoom = $zoom ? intval($zoom) : 0; |
|
| 82 | + if($zoom > 18) $zoom = 18; |
|
| 83 | + // normalize WxH |
|
| 84 | + list($width, $height) = explode('x', $size); |
|
| 85 | + $width = intval($width); |
|
| 86 | + if($width > $this->maxWidth) $width = $this->maxWidth; |
|
| 87 | + $height = intval($height); |
|
| 88 | + if($height > $this->maxHeight) $height = $this->maxHeight; |
|
| 89 | 89 | |
| 90 | - // cleanup/validate gpx/kml |
|
| 91 | - $kml = $this->mediaIdToPath($kml); |
|
| 92 | - // dbglog($kml,'helper_plugin_openlayersmap_staticmap::getMap: kml file:'); |
|
| 93 | - $gpx = $this->mediaIdToPath($gpx); |
|
| 94 | - // dbglog($gpx,'helper_plugin_openlayersmap_staticmap::getMap: gpx file:'); |
|
| 95 | - $geojson = $this->mediaIdToPath($geojson); |
|
| 90 | + // cleanup/validate gpx/kml |
|
| 91 | + $kml = $this->mediaIdToPath($kml); |
|
| 92 | + // dbglog($kml,'helper_plugin_openlayersmap_staticmap::getMap: kml file:'); |
|
| 93 | + $gpx = $this->mediaIdToPath($gpx); |
|
| 94 | + // dbglog($gpx,'helper_plugin_openlayersmap_staticmap::getMap: gpx file:'); |
|
| 95 | + $geojson = $this->mediaIdToPath($geojson); |
|
| 96 | 96 | |
| 97 | - // create map |
|
| 98 | - $map = new StaticMap( |
|
| 99 | - $lat, $lon, $zoom, $width, $height, $maptype, |
|
| 100 | - $markers, $gpx, $kml, $geojson, $conf['mediadir'], $conf['cachedir'], |
|
| 101 | - $this->getConf('autoZoomMap'), |
|
| 102 | - $apikey |
|
| 103 | - ); |
|
| 97 | + // create map |
|
| 98 | + $map = new StaticMap( |
|
| 99 | + $lat, $lon, $zoom, $width, $height, $maptype, |
|
| 100 | + $markers, $gpx, $kml, $geojson, $conf['mediadir'], $conf['cachedir'], |
|
| 101 | + $this->getConf('autoZoomMap'), |
|
| 102 | + $apikey |
|
| 103 | + ); |
|
| 104 | 104 | |
| 105 | - // return the media id url |
|
| 106 | - $mediaId = str_replace('/', ':', $map->getMap()); |
|
| 107 | - // if($this->startsWith($mediaId,':')) { |
|
| 108 | - // $mediaId = substr($mediaId, 1); |
|
| 109 | - // } |
|
| 110 | - return $mediaId; |
|
| 111 | - } |
|
| 105 | + // return the media id url |
|
| 106 | + $mediaId = str_replace('/', ':', $map->getMap()); |
|
| 107 | + // if($this->startsWith($mediaId,':')) { |
|
| 108 | + // $mediaId = substr($mediaId, 1); |
|
| 109 | + // } |
|
| 110 | + return $mediaId; |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Constructs the path to a file. |
|
| 115 | - * @param string $id the DW media id |
|
| 116 | - * @return string the path to the file |
|
| 117 | - */ |
|
| 118 | - private function mediaIdToPath(string $id): string { |
|
| 119 | - global $conf; |
|
| 120 | - if(empty($id)) { |
|
| 121 | - return ""; |
|
| 122 | - } |
|
| 123 | - $id = str_replace("[[", "", $id); |
|
| 124 | - $id = str_replace("]]", "", $id); |
|
| 125 | - if($this->startsWith($id, ':')) { |
|
| 126 | - $id = substr($id, 1); |
|
| 127 | - } |
|
| 128 | - $id = str_replace(":", "/", $id); |
|
| 129 | - return $conf['mediadir'] . '/' . $id; |
|
| 130 | - } |
|
| 113 | + /** |
|
| 114 | + * Constructs the path to a file. |
|
| 115 | + * @param string $id the DW media id |
|
| 116 | + * @return string the path to the file |
|
| 117 | + */ |
|
| 118 | + private function mediaIdToPath(string $id): string { |
|
| 119 | + global $conf; |
|
| 120 | + if(empty($id)) { |
|
| 121 | + return ""; |
|
| 122 | + } |
|
| 123 | + $id = str_replace("[[", "", $id); |
|
| 124 | + $id = str_replace("]]", "", $id); |
|
| 125 | + if($this->startsWith($id, ':')) { |
|
| 126 | + $id = substr($id, 1); |
|
| 127 | + } |
|
| 128 | + $id = str_replace(":", "/", $id); |
|
| 129 | + return $conf['mediadir'] . '/' . $id; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - private function startsWith($haystack, $needle): bool { |
|
| 133 | - $length = strlen($needle); |
|
| 134 | - return (substr($haystack, 0, $length) === $needle); |
|
| 135 | - } |
|
| 132 | + private function startsWith($haystack, $needle): bool { |
|
| 133 | + $length = strlen($needle); |
|
| 134 | + return (substr($haystack, 0, $length) === $needle); |
|
| 135 | + } |
|
| 136 | 136 | } |
@@ -79,13 +79,13 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | // normalize zoom |
| 81 | 81 | $zoom = $zoom ? intval($zoom) : 0; |
| 82 | - if($zoom > 18) $zoom = 18; |
|
| 82 | + if ($zoom > 18) $zoom = 18; |
|
| 83 | 83 | // normalize WxH |
| 84 | 84 | list($width, $height) = explode('x', $size); |
| 85 | 85 | $width = intval($width); |
| 86 | - if($width > $this->maxWidth) $width = $this->maxWidth; |
|
| 86 | + if ($width > $this->maxWidth) $width = $this->maxWidth; |
|
| 87 | 87 | $height = intval($height); |
| 88 | - if($height > $this->maxHeight) $height = $this->maxHeight; |
|
| 88 | + if ($height > $this->maxHeight) $height = $this->maxHeight; |
|
| 89 | 89 | |
| 90 | 90 | // cleanup/validate gpx/kml |
| 91 | 91 | $kml = $this->mediaIdToPath($kml); |
@@ -117,16 +117,16 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | private function mediaIdToPath(string $id): string { |
| 119 | 119 | global $conf; |
| 120 | - if(empty($id)) { |
|
| 120 | + if (empty($id)) { |
|
| 121 | 121 | return ""; |
| 122 | 122 | } |
| 123 | 123 | $id = str_replace("[[", "", $id); |
| 124 | 124 | $id = str_replace("]]", "", $id); |
| 125 | - if($this->startsWith($id, ':')) { |
|
| 125 | + if ($this->startsWith($id, ':')) { |
|
| 126 | 126 | $id = substr($id, 1); |
| 127 | 127 | } |
| 128 | 128 | $id = str_replace(":", "/", $id); |
| 129 | - return $conf['mediadir'] . '/' . $id; |
|
| 129 | + return $conf['mediadir'].'/'.$id; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | private function startsWith($haystack, $needle): bool { |
@@ -79,13 +79,19 @@ |
||
| 79 | 79 | |
| 80 | 80 | // normalize zoom |
| 81 | 81 | $zoom = $zoom ? intval($zoom) : 0; |
| 82 | - if($zoom > 18) $zoom = 18; |
|
| 82 | + if($zoom > 18) { |
|
| 83 | + $zoom = 18; |
|
| 84 | + } |
|
| 83 | 85 | // normalize WxH |
| 84 | 86 | list($width, $height) = explode('x', $size); |
| 85 | 87 | $width = intval($width); |
| 86 | - if($width > $this->maxWidth) $width = $this->maxWidth; |
|
| 88 | + if($width > $this->maxWidth) { |
|
| 89 | + $width = $this->maxWidth; |
|
| 90 | + } |
|
| 87 | 91 | $height = intval($height); |
| 88 | - if($height > $this->maxHeight) $height = $this->maxHeight; |
|
| 92 | + if($height > $this->maxHeight) { |
|
| 93 | + $height = $this->maxHeight; |
|
| 94 | + } |
|
| 89 | 95 | |
| 90 | 96 | // cleanup/validate gpx/kml |
| 91 | 97 | $kml = $this->mediaIdToPath($kml); |
@@ -24,46 +24,46 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class action_plugin_openlayersmap extends DokuWiki_Action_Plugin { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * plugin should use this method to register its handlers with the DokuWiki's event controller |
|
| 29 | - * |
|
| 30 | - * @param $controller DokuWiki's event controller object. Also available as global $EVENT_HANDLER |
|
| 31 | - */ |
|
| 32 | - public function register(Doku_Event_Handler $controller) { |
|
| 33 | - $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'insertButton', array()); |
|
| 34 | - $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'insertCSSSniffer'); |
|
| 35 | - } |
|
| 27 | + /** |
|
| 28 | + * plugin should use this method to register its handlers with the DokuWiki's event controller |
|
| 29 | + * |
|
| 30 | + * @param $controller DokuWiki's event controller object. Also available as global $EVENT_HANDLER |
|
| 31 | + */ |
|
| 32 | + public function register(Doku_Event_Handler $controller) { |
|
| 33 | + $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'insertButton', array()); |
|
| 34 | + $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'insertCSSSniffer'); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Inserts the toolbar button. |
|
| 39 | - * @param Doku_Event $event the DokuWiki event |
|
| 40 | - */ |
|
| 41 | - public function insertButton(Doku_Event $event, $param) { |
|
| 42 | - $strOpen = '<olmap id="olMapOne" width="550px" height="450px" lat="50.0" '; |
|
| 43 | - $strOpen .= 'lon="5.1" zoom="12" statusbar="1" controls="1" poihoverstyle="0" '; |
|
| 44 | - $strOpen .= 'baselyr="OpenStreetMap" gpxfile="" kmlfile="" geojsonfile="" summary="" >\n'; |
|
| 45 | - $strOpen .= '~~ Plugin olmap help.\n'; |
|
| 46 | - $strOpen .= '~~ Required in the above tag are values for: id (unique on this page), width, heigth.\n'; |
|
| 47 | - $strOpen .= '~~ Also you will want to enter zoomlevel and lat, lon values that make sense for where you'; |
|
| 48 | - $strOpen .= '~~ want the map to start.\n\n'; |
|
| 49 | - $strOpen .= '~~ Below is an example of a POI, you can add as many as you want. '; |
|
| 50 | - $strOpen .= '~~ More examples: https://dokuwiki.org/plugin:openlayersmap \n'; |
|
| 51 | - $event->data[] = array( |
|
| 52 | - 'type' => 'format', |
|
| 53 | - 'title' => $this->getLang('openlayersmap'), |
|
| 54 | - 'icon' => '../../plugins/openlayersmap/toolbar/map.png', |
|
| 55 | - 'open' => $strOpen, |
|
| 56 | - 'sample' => '50.0117,5.1287,-90,.8,marker-green.png,Pont de Barbouillons; Daverdisse \\\\ external link: |
|
| 37 | + /** |
|
| 38 | + * Inserts the toolbar button. |
|
| 39 | + * @param Doku_Event $event the DokuWiki event |
|
| 40 | + */ |
|
| 41 | + public function insertButton(Doku_Event $event, $param) { |
|
| 42 | + $strOpen = '<olmap id="olMapOne" width="550px" height="450px" lat="50.0" '; |
|
| 43 | + $strOpen .= 'lon="5.1" zoom="12" statusbar="1" controls="1" poihoverstyle="0" '; |
|
| 44 | + $strOpen .= 'baselyr="OpenStreetMap" gpxfile="" kmlfile="" geojsonfile="" summary="" >\n'; |
|
| 45 | + $strOpen .= '~~ Plugin olmap help.\n'; |
|
| 46 | + $strOpen .= '~~ Required in the above tag are values for: id (unique on this page), width, heigth.\n'; |
|
| 47 | + $strOpen .= '~~ Also you will want to enter zoomlevel and lat, lon values that make sense for where you'; |
|
| 48 | + $strOpen .= '~~ want the map to start.\n\n'; |
|
| 49 | + $strOpen .= '~~ Below is an example of a POI, you can add as many as you want. '; |
|
| 50 | + $strOpen .= '~~ More examples: https://dokuwiki.org/plugin:openlayersmap \n'; |
|
| 51 | + $event->data[] = array( |
|
| 52 | + 'type' => 'format', |
|
| 53 | + 'title' => $this->getLang('openlayersmap'), |
|
| 54 | + 'icon' => '../../plugins/openlayersmap/toolbar/map.png', |
|
| 55 | + 'open' => $strOpen, |
|
| 56 | + 'sample' => '50.0117,5.1287,-90,.8,marker-green.png,Pont de Barbouillons; Daverdisse \\\\ external link: |
|
| 57 | 57 | [[https://test.com|test.com]] \\\\ internal link: [[::start]]\\\\ **DW Formatting** \n', |
| 58 | - 'close' => '</olmap>\n', |
|
| 59 | - ); |
|
| 60 | - } |
|
| 58 | + 'close' => '</olmap>\n', |
|
| 59 | + ); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** add a snippet of javascript into the head to do a css operation we can check for later on.*/ |
|
| 63 | - public function insertCSSSniffer(Doku_Event $event, $param) { |
|
| 64 | - $event->data["script"][] = array( |
|
| 65 | - "type" => "text/javascript", |
|
| 66 | - "_data" => "document.documentElement.className += ' olCSSsupported';", |
|
| 67 | - ); |
|
| 68 | - } |
|
| 62 | + /** add a snippet of javascript into the head to do a css operation we can check for later on.*/ |
|
| 63 | + public function insertCSSSniffer(Doku_Event $event, $param) { |
|
| 64 | + $event->data["script"][] = array( |
|
| 65 | + "type" => "text/javascript", |
|
| 66 | + "_data" => "document.documentElement.className += ' olCSSsupported';", |
|
| 67 | + ); |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -39,7 +39,7 @@ |
||
| 39 | 39 | * @param Doku_Event $event the DokuWiki event |
| 40 | 40 | */ |
| 41 | 41 | public function insertButton(Doku_Event $event, $param) { |
| 42 | - $strOpen = '<olmap id="olMapOne" width="550px" height="450px" lat="50.0" '; |
|
| 42 | + $strOpen = '<olmap id="olMapOne" width="550px" height="450px" lat="50.0" '; |
|
| 43 | 43 | $strOpen .= 'lon="5.1" zoom="12" statusbar="1" controls="1" poihoverstyle="0" '; |
| 44 | 44 | $strOpen .= 'baselyr="OpenStreetMap" gpxfile="" kmlfile="" geojsonfile="" summary="" >\n'; |
| 45 | 45 | $strOpen .= '~~ Plugin olmap help.\n'; |
@@ -25,108 +25,108 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | class syntax_plugin_openlayersmap_olmap extends DokuWiki_Syntax_Plugin { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * defaults of the known attributes of the olmap tag. |
|
| 30 | - */ |
|
| 31 | - private $dflt = array( |
|
| 32 | - 'id' => 'olmap', |
|
| 33 | - 'width' => '550px', |
|
| 34 | - 'height' => '450px', |
|
| 35 | - 'lat' => 50.0, |
|
| 36 | - 'lon' => 5.1, |
|
| 37 | - 'zoom' => 12, |
|
| 38 | - 'autozoom' => 1, |
|
| 39 | - 'statusbar' => true, |
|
| 40 | - 'toolbar' => true, |
|
| 41 | - 'controls' => true, |
|
| 42 | - 'poihoverstyle' => false, |
|
| 43 | - 'baselyr' => 'OpenStreetMap', |
|
| 44 | - 'gpxfile' => '', |
|
| 45 | - 'kmlfile' => '', |
|
| 46 | - 'geojsonfile' => '', |
|
| 47 | - 'summary' => '' |
|
| 48 | - ); |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * |
|
| 52 | - * @see DokuWiki_Syntax_Plugin::getType() |
|
| 53 | - */ |
|
| 54 | - public function getType(): string { |
|
| 55 | - return 'substition'; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * |
|
| 60 | - * @see DokuWiki_Syntax_Plugin::getPType() |
|
| 61 | - */ |
|
| 62 | - public function getPType(): string { |
|
| 63 | - return 'block'; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * |
|
| 68 | - * @see Doku_Parser_Mode::getSort() |
|
| 69 | - */ |
|
| 70 | - public function getSort(): int { |
|
| 71 | - return 901; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * |
|
| 76 | - * @see Doku_Parser_Mode::connectTo() |
|
| 77 | - */ |
|
| 78 | - public function connectTo($mode) { |
|
| 79 | - $this->Lexer->addSpecialPattern( |
|
| 80 | - '<olmap ?[^>\n]*>.*?</olmap>', $mode, |
|
| 81 | - 'plugin_openlayersmap_olmap' |
|
| 82 | - ); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * |
|
| 87 | - * @see DokuWiki_Syntax_Plugin::handle() |
|
| 88 | - */ |
|
| 89 | - public function handle($match, $state, $pos, Doku_Handler $handler): array { |
|
| 90 | - // break matched cdata into its components |
|
| 91 | - list ($str_params, $str_points) = explode('>', substr($match, 7, -9), 2); |
|
| 92 | - // get the lat/lon for adding them to the metadata (used by geotag) |
|
| 93 | - preg_match('(lat[:|=]\"-?\d*\.?\d*\")', $match, $mainLat); |
|
| 94 | - preg_match('(lon[:|=]\"-?\d*\.?\d*\")', $match, $mainLon); |
|
| 95 | - $mainLat = substr($mainLat [0], 5, -1); |
|
| 96 | - $mainLon = substr($mainLon [0], 5, -1); |
|
| 97 | - if(!is_numeric($mainLat)) { |
|
| 98 | - $mainLat = $this->dflt ['lat']; |
|
| 99 | - } |
|
| 100 | - if(!is_numeric($mainLon)) { |
|
| 101 | - $mainLon = $this->dflt ['lon']; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $gmap = $this->_extract_params($str_params); |
|
| 105 | - $overlay = $this->_extract_points($str_points); |
|
| 106 | - $_firstimageID = ''; |
|
| 107 | - |
|
| 108 | - $_nocache = false; |
|
| 109 | - // choose maptype based on the specified tag |
|
| 110 | - $imgUrl = "{{"; |
|
| 111 | - if(stripos($gmap ['baselyr'], 'google') !== false) { |
|
| 112 | ||
| 113 | - $imgUrl .= $this->_getGoogle($gmap, $overlay); |
|
| 114 | - $imgUrl .= "&.png"; |
|
| 115 | - } elseif(stripos($gmap ['baselyr'], 'bing') !== false) { |
|
| 116 | - // Bing |
|
| 117 | - if(!$this->getConf('bingAPIKey')) { |
|
| 118 | - // in case there is no Bing api key we'll use OSM |
|
| 119 | - $_firstimageID = $this->_getStaticOSM($gmap, $overlay); |
|
| 120 | - $imgUrl .= $_firstimageID; |
|
| 121 | - if($this->getConf('optionStaticMapGenerator') == 'remote') { |
|
| 122 | - $imgUrl .= "&.png"; |
|
| 123 | - } |
|
| 124 | - } else { |
|
| 125 | - // seems that Bing doesn't like the DW client, turn off caching |
|
| 126 | - $_nocache = true; |
|
| 127 | - $imgUrl .= $this->_getBing($gmap, $overlay) . "&.png"; |
|
| 128 | - } |
|
| 129 | - } /* elseif (stripos ( $gmap ['baselyr'], 'mapquest' ) !== false) { |
|
| 28 | + /** |
|
| 29 | + * defaults of the known attributes of the olmap tag. |
|
| 30 | + */ |
|
| 31 | + private $dflt = array( |
|
| 32 | + 'id' => 'olmap', |
|
| 33 | + 'width' => '550px', |
|
| 34 | + 'height' => '450px', |
|
| 35 | + 'lat' => 50.0, |
|
| 36 | + 'lon' => 5.1, |
|
| 37 | + 'zoom' => 12, |
|
| 38 | + 'autozoom' => 1, |
|
| 39 | + 'statusbar' => true, |
|
| 40 | + 'toolbar' => true, |
|
| 41 | + 'controls' => true, |
|
| 42 | + 'poihoverstyle' => false, |
|
| 43 | + 'baselyr' => 'OpenStreetMap', |
|
| 44 | + 'gpxfile' => '', |
|
| 45 | + 'kmlfile' => '', |
|
| 46 | + 'geojsonfile' => '', |
|
| 47 | + 'summary' => '' |
|
| 48 | + ); |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * |
|
| 52 | + * @see DokuWiki_Syntax_Plugin::getType() |
|
| 53 | + */ |
|
| 54 | + public function getType(): string { |
|
| 55 | + return 'substition'; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * |
|
| 60 | + * @see DokuWiki_Syntax_Plugin::getPType() |
|
| 61 | + */ |
|
| 62 | + public function getPType(): string { |
|
| 63 | + return 'block'; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * |
|
| 68 | + * @see Doku_Parser_Mode::getSort() |
|
| 69 | + */ |
|
| 70 | + public function getSort(): int { |
|
| 71 | + return 901; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * |
|
| 76 | + * @see Doku_Parser_Mode::connectTo() |
|
| 77 | + */ |
|
| 78 | + public function connectTo($mode) { |
|
| 79 | + $this->Lexer->addSpecialPattern( |
|
| 80 | + '<olmap ?[^>\n]*>.*?</olmap>', $mode, |
|
| 81 | + 'plugin_openlayersmap_olmap' |
|
| 82 | + ); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * |
|
| 87 | + * @see DokuWiki_Syntax_Plugin::handle() |
|
| 88 | + */ |
|
| 89 | + public function handle($match, $state, $pos, Doku_Handler $handler): array { |
|
| 90 | + // break matched cdata into its components |
|
| 91 | + list ($str_params, $str_points) = explode('>', substr($match, 7, -9), 2); |
|
| 92 | + // get the lat/lon for adding them to the metadata (used by geotag) |
|
| 93 | + preg_match('(lat[:|=]\"-?\d*\.?\d*\")', $match, $mainLat); |
|
| 94 | + preg_match('(lon[:|=]\"-?\d*\.?\d*\")', $match, $mainLon); |
|
| 95 | + $mainLat = substr($mainLat [0], 5, -1); |
|
| 96 | + $mainLon = substr($mainLon [0], 5, -1); |
|
| 97 | + if(!is_numeric($mainLat)) { |
|
| 98 | + $mainLat = $this->dflt ['lat']; |
|
| 99 | + } |
|
| 100 | + if(!is_numeric($mainLon)) { |
|
| 101 | + $mainLon = $this->dflt ['lon']; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $gmap = $this->_extract_params($str_params); |
|
| 105 | + $overlay = $this->_extract_points($str_points); |
|
| 106 | + $_firstimageID = ''; |
|
| 107 | + |
|
| 108 | + $_nocache = false; |
|
| 109 | + // choose maptype based on the specified tag |
|
| 110 | + $imgUrl = "{{"; |
|
| 111 | + if(stripos($gmap ['baselyr'], 'google') !== false) { |
|
| 112 | ||
| 113 | + $imgUrl .= $this->_getGoogle($gmap, $overlay); |
|
| 114 | + $imgUrl .= "&.png"; |
|
| 115 | + } elseif(stripos($gmap ['baselyr'], 'bing') !== false) { |
|
| 116 | + // Bing |
|
| 117 | + if(!$this->getConf('bingAPIKey')) { |
|
| 118 | + // in case there is no Bing api key we'll use OSM |
|
| 119 | + $_firstimageID = $this->_getStaticOSM($gmap, $overlay); |
|
| 120 | + $imgUrl .= $_firstimageID; |
|
| 121 | + if($this->getConf('optionStaticMapGenerator') == 'remote') { |
|
| 122 | + $imgUrl .= "&.png"; |
|
| 123 | + } |
|
| 124 | + } else { |
|
| 125 | + // seems that Bing doesn't like the DW client, turn off caching |
|
| 126 | + $_nocache = true; |
|
| 127 | + $imgUrl .= $this->_getBing($gmap, $overlay) . "&.png"; |
|
| 128 | + } |
|
| 129 | + } /* elseif (stripos ( $gmap ['baselyr'], 'mapquest' ) !== false) { |
|
| 130 | 130 | // MapQuest |
| 131 | 131 | if (! $this->getConf ( 'mapquestAPIKey' )) { |
| 132 | 132 | // no API key for MapQuest, use OSM |
@@ -140,268 +140,268 @@ discard block |
||
| 140 | 140 | $imgUrl .= "&.png"; |
| 141 | 141 | } |
| 142 | 142 | } */ else { |
| 143 | - // default OSM |
|
| 144 | - $_firstimageID = $this->_getStaticOSM($gmap, $overlay); |
|
| 145 | - $imgUrl .= $_firstimageID; |
|
| 146 | - if($this->getConf('optionStaticMapGenerator') == 'remote') { |
|
| 147 | - $imgUrl .= "&.png"; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // append dw p_render specific params and render |
|
| 152 | - $imgUrl .= "?" . str_replace("px", "", $gmap ['width']) . "x" |
|
| 153 | - . str_replace("px", "", $gmap ['height']); |
|
| 154 | - $imgUrl .= "&nolink"; |
|
| 155 | - |
|
| 156 | - // add nocache option for selected services |
|
| 157 | - if($_nocache) { |
|
| 158 | - $imgUrl .= "&nocache"; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - $imgUrl .= " |" . $gmap ['summary'] . " }}"; |
|
| 162 | - |
|
| 163 | - // dbglog($imgUrl,"complete image tags is:"); |
|
| 164 | - |
|
| 165 | - $mapid = $gmap ['id']; |
|
| 166 | - // create a javascript parameter string for the map |
|
| 167 | - $param = ''; |
|
| 168 | - foreach($gmap as $key => $val) { |
|
| 169 | - $param .= is_numeric($val) ? "$key: $val, " : "$key: '" . hsc($val) . "', "; |
|
| 170 | - } |
|
| 171 | - if(!empty ($param)) { |
|
| 172 | - $param = substr($param, 0, -2); |
|
| 173 | - } |
|
| 174 | - unset ($gmap ['id']); |
|
| 175 | - |
|
| 176 | - // create a javascript serialisation of the point data |
|
| 177 | - $poi = ''; |
|
| 178 | - $poitable = ''; |
|
| 179 | - $rowId = 0; |
|
| 180 | - if(!empty ($overlay)) { |
|
| 181 | - foreach($overlay as $data) { |
|
| 182 | - list ($lat, $lon, $text, $angle, $opacity, $img) = $data; |
|
| 183 | - $rowId++; |
|
| 184 | - $poi .= ", {lat: $lat, lon: $lon, txt: '$text', angle: $angle, opacity: $opacity, img: '$img', rowId: $rowId}"; |
|
| 185 | - |
|
| 186 | - if($this->getConf('displayformat') === 'DMS') { |
|
| 187 | - $lat = $this->convertLat($lat); |
|
| 188 | - $lon = $this->convertLon($lon); |
|
| 189 | - } else { |
|
| 190 | - $lat .= 'º'; |
|
| 191 | - $lon .= 'º'; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - $poitable .= ' |
|
| 143 | + // default OSM |
|
| 144 | + $_firstimageID = $this->_getStaticOSM($gmap, $overlay); |
|
| 145 | + $imgUrl .= $_firstimageID; |
|
| 146 | + if($this->getConf('optionStaticMapGenerator') == 'remote') { |
|
| 147 | + $imgUrl .= "&.png"; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // append dw p_render specific params and render |
|
| 152 | + $imgUrl .= "?" . str_replace("px", "", $gmap ['width']) . "x" |
|
| 153 | + . str_replace("px", "", $gmap ['height']); |
|
| 154 | + $imgUrl .= "&nolink"; |
|
| 155 | + |
|
| 156 | + // add nocache option for selected services |
|
| 157 | + if($_nocache) { |
|
| 158 | + $imgUrl .= "&nocache"; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + $imgUrl .= " |" . $gmap ['summary'] . " }}"; |
|
| 162 | + |
|
| 163 | + // dbglog($imgUrl,"complete image tags is:"); |
|
| 164 | + |
|
| 165 | + $mapid = $gmap ['id']; |
|
| 166 | + // create a javascript parameter string for the map |
|
| 167 | + $param = ''; |
|
| 168 | + foreach($gmap as $key => $val) { |
|
| 169 | + $param .= is_numeric($val) ? "$key: $val, " : "$key: '" . hsc($val) . "', "; |
|
| 170 | + } |
|
| 171 | + if(!empty ($param)) { |
|
| 172 | + $param = substr($param, 0, -2); |
|
| 173 | + } |
|
| 174 | + unset ($gmap ['id']); |
|
| 175 | + |
|
| 176 | + // create a javascript serialisation of the point data |
|
| 177 | + $poi = ''; |
|
| 178 | + $poitable = ''; |
|
| 179 | + $rowId = 0; |
|
| 180 | + if(!empty ($overlay)) { |
|
| 181 | + foreach($overlay as $data) { |
|
| 182 | + list ($lat, $lon, $text, $angle, $opacity, $img) = $data; |
|
| 183 | + $rowId++; |
|
| 184 | + $poi .= ", {lat: $lat, lon: $lon, txt: '$text', angle: $angle, opacity: $opacity, img: '$img', rowId: $rowId}"; |
|
| 185 | + |
|
| 186 | + if($this->getConf('displayformat') === 'DMS') { |
|
| 187 | + $lat = $this->convertLat($lat); |
|
| 188 | + $lon = $this->convertLon($lon); |
|
| 189 | + } else { |
|
| 190 | + $lat .= 'º'; |
|
| 191 | + $lon .= 'º'; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + $poitable .= ' |
|
| 195 | 195 | <tr> |
| 196 | 196 | <td class="rowId">' . $rowId . '</td> |
| 197 | 197 | <td class="icon"><img src="' . DOKU_BASE . 'lib/plugins/openlayersmap/icons/' . $img . '" alt="' |
| 198 | - . substr($img, 0, -4) . $this->getlang('alt_legend_poi') . ' " /></td> |
|
| 198 | + . substr($img, 0, -4) . $this->getlang('alt_legend_poi') . ' " /></td> |
|
| 199 | 199 | <td class="lat" title="' . $this->getLang('olmapPOIlatTitle') . '">' . $lat . '</td> |
| 200 | 200 | <td class="lon" title="' . $this->getLang('olmapPOIlonTitle') . '">' . $lon . '</td> |
| 201 | 201 | <td class="txt">' . $text . '</td> |
| 202 | 202 | </tr>'; |
| 203 | - } |
|
| 204 | - $poi = substr($poi, 2); |
|
| 205 | - } |
|
| 206 | - if(!empty ($gmap ['kmlfile'])) { |
|
| 207 | - $poitable .= ' |
|
| 203 | + } |
|
| 204 | + $poi = substr($poi, 2); |
|
| 205 | + } |
|
| 206 | + if(!empty ($gmap ['kmlfile'])) { |
|
| 207 | + $poitable .= ' |
|
| 208 | 208 | <tr> |
| 209 | 209 | <td class="rowId"><img src="' . DOKU_BASE |
| 210 | - . 'lib/plugins/openlayersmap/toolbar/kml_file.png" alt="KML file" /></td> |
|
| 210 | + . 'lib/plugins/openlayersmap/toolbar/kml_file.png" alt="KML file" /></td> |
|
| 211 | 211 | <td class="icon"><img src="' . DOKU_BASE . 'lib/plugins/openlayersmap/toolbar/kml_line.png" alt="' |
| 212 | - . $this->getlang('alt_legend_kml') . '" /></td> |
|
| 212 | + . $this->getlang('alt_legend_kml') . '" /></td> |
|
| 213 | 213 | <td class="txt" colspan="3">KML track: ' . $this->getFileName($gmap ['kmlfile']) . '</td> |
| 214 | 214 | </tr>'; |
| 215 | - } |
|
| 216 | - if(!empty ($gmap ['gpxfile'])) { |
|
| 217 | - $poitable .= ' |
|
| 215 | + } |
|
| 216 | + if(!empty ($gmap ['gpxfile'])) { |
|
| 217 | + $poitable .= ' |
|
| 218 | 218 | <tr> |
| 219 | 219 | <td class="rowId"><img src="' . DOKU_BASE |
| 220 | - . 'lib/plugins/openlayersmap/toolbar/gpx_file.png" alt="GPX file" /></td> |
|
| 220 | + . 'lib/plugins/openlayersmap/toolbar/gpx_file.png" alt="GPX file" /></td> |
|
| 221 | 221 | <td class="icon"><img src="' . DOKU_BASE |
| 222 | - . 'lib/plugins/openlayersmap/toolbar/gpx_line.png" alt="' |
|
| 223 | - . $this->getlang('alt_legend_gpx') . '" /></td> |
|
| 222 | + . 'lib/plugins/openlayersmap/toolbar/gpx_line.png" alt="' |
|
| 223 | + . $this->getlang('alt_legend_gpx') . '" /></td> |
|
| 224 | 224 | <td class="txt" colspan="3">GPX track: ' . $this->getFileName($gmap ['gpxfile']) . '</td> |
| 225 | 225 | </tr>'; |
| 226 | - } |
|
| 227 | - if(!empty ($gmap ['geojsonfile'])) { |
|
| 228 | - $poitable .= ' |
|
| 226 | + } |
|
| 227 | + if(!empty ($gmap ['geojsonfile'])) { |
|
| 228 | + $poitable .= ' |
|
| 229 | 229 | <tr> |
| 230 | 230 | <td class="rowId"><img src="' . DOKU_BASE |
| 231 | - . 'lib/plugins/openlayersmap/toolbar/geojson_file.png" alt="GeoJSON file" /></td> |
|
| 231 | + . 'lib/plugins/openlayersmap/toolbar/geojson_file.png" alt="GeoJSON file" /></td> |
|
| 232 | 232 | <td class="icon"><img src="' . DOKU_BASE |
| 233 | - . 'lib/plugins/openlayersmap/toolbar/geojson_line.png" alt="' |
|
| 234 | - . $this->getlang('alt_legend_geojson') . '" /></td> |
|
| 233 | + . 'lib/plugins/openlayersmap/toolbar/geojson_line.png" alt="' |
|
| 234 | + . $this->getlang('alt_legend_geojson') . '" /></td> |
|
| 235 | 235 | <td class="txt" colspan="3">GeoJSON track: ' . $this->getFileName($gmap ['geojsonfile']) . '</td> |
| 236 | 236 | </tr>'; |
| 237 | - } |
|
| 238 | - |
|
| 239 | - $autozoom = empty ($gmap ['autozoom']) ? $this->getConf('autoZoomMap') : $gmap ['autozoom']; |
|
| 240 | - $js = "{mapOpts: {" . $param . ", displayformat: '" . $this->getConf('displayformat') |
|
| 241 | - . "', autozoom: " . $autozoom . "}, poi: [$poi]};"; |
|
| 242 | - // unescape the json |
|
| 243 | - $poitable = stripslashes($poitable); |
|
| 244 | - |
|
| 245 | - return array( |
|
| 246 | - $mapid, |
|
| 247 | - $js, |
|
| 248 | - $mainLat, |
|
| 249 | - $mainLon, |
|
| 250 | - $poitable, |
|
| 251 | - $gmap ['summary'], |
|
| 252 | - $imgUrl, |
|
| 253 | - $_firstimageID |
|
| 254 | - ); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * extract parameters for the map from the parameter string |
|
| 259 | - * |
|
| 260 | - * @param string $str_params |
|
| 261 | - * string of key="value" pairs |
|
| 262 | - * @return array associative array of parameters key=>value |
|
| 263 | - */ |
|
| 264 | - private function _extract_params(string $str_params): array { |
|
| 265 | - $param = array(); |
|
| 266 | - preg_match_all('/(\w*)="(.*?)"/us', $str_params, $param, PREG_SET_ORDER); |
|
| 267 | - // parse match for instructions, break into key value pairs |
|
| 268 | - $gmap = $this->dflt; |
|
| 269 | - foreach($gmap as $key => &$value) { |
|
| 270 | - $defval = $this->getConf('default_' . $key); |
|
| 271 | - if($defval !== '') { |
|
| 272 | - $value = $defval; |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - unset ($value); |
|
| 276 | - foreach($param as $kvpair) { |
|
| 277 | - list ($match, $key, $val) = $kvpair; |
|
| 278 | - $key = strtolower($key); |
|
| 279 | - if(isset ($gmap [$key])) { |
|
| 280 | - if($key == 'summary') { |
|
| 281 | - // preserve case for summary field |
|
| 282 | - $gmap [$key] = $val; |
|
| 283 | - } elseif($key == 'id') { |
|
| 284 | - // preserve case for id field |
|
| 285 | - $gmap [$key] = $val; |
|
| 286 | - } else { |
|
| 287 | - $gmap [$key] = strtolower($val); |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - return $gmap; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * extract overlay points for the map from the wiki syntax data |
|
| 296 | - * |
|
| 297 | - * @param string $str_points |
|
| 298 | - * multi-line string of lat,lon,text triplets |
|
| 299 | - * @return array multi-dimensional array of lat,lon,text triplets |
|
| 300 | - */ |
|
| 301 | - private function _extract_points(string $str_points): array { |
|
| 302 | - $point = array(); |
|
| 303 | - // preg_match_all('/^([+-]?[0-9].*?),\s*([+-]?[0-9].*?),(.*?),(.*?),(.*?),(.*)$/um', $str_points, $point, PREG_SET_ORDER); |
|
| 304 | - /* |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + $autozoom = empty ($gmap ['autozoom']) ? $this->getConf('autoZoomMap') : $gmap ['autozoom']; |
|
| 240 | + $js = "{mapOpts: {" . $param . ", displayformat: '" . $this->getConf('displayformat') |
|
| 241 | + . "', autozoom: " . $autozoom . "}, poi: [$poi]};"; |
|
| 242 | + // unescape the json |
|
| 243 | + $poitable = stripslashes($poitable); |
|
| 244 | + |
|
| 245 | + return array( |
|
| 246 | + $mapid, |
|
| 247 | + $js, |
|
| 248 | + $mainLat, |
|
| 249 | + $mainLon, |
|
| 250 | + $poitable, |
|
| 251 | + $gmap ['summary'], |
|
| 252 | + $imgUrl, |
|
| 253 | + $_firstimageID |
|
| 254 | + ); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * extract parameters for the map from the parameter string |
|
| 259 | + * |
|
| 260 | + * @param string $str_params |
|
| 261 | + * string of key="value" pairs |
|
| 262 | + * @return array associative array of parameters key=>value |
|
| 263 | + */ |
|
| 264 | + private function _extract_params(string $str_params): array { |
|
| 265 | + $param = array(); |
|
| 266 | + preg_match_all('/(\w*)="(.*?)"/us', $str_params, $param, PREG_SET_ORDER); |
|
| 267 | + // parse match for instructions, break into key value pairs |
|
| 268 | + $gmap = $this->dflt; |
|
| 269 | + foreach($gmap as $key => &$value) { |
|
| 270 | + $defval = $this->getConf('default_' . $key); |
|
| 271 | + if($defval !== '') { |
|
| 272 | + $value = $defval; |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + unset ($value); |
|
| 276 | + foreach($param as $kvpair) { |
|
| 277 | + list ($match, $key, $val) = $kvpair; |
|
| 278 | + $key = strtolower($key); |
|
| 279 | + if(isset ($gmap [$key])) { |
|
| 280 | + if($key == 'summary') { |
|
| 281 | + // preserve case for summary field |
|
| 282 | + $gmap [$key] = $val; |
|
| 283 | + } elseif($key == 'id') { |
|
| 284 | + // preserve case for id field |
|
| 285 | + $gmap [$key] = $val; |
|
| 286 | + } else { |
|
| 287 | + $gmap [$key] = strtolower($val); |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + return $gmap; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * extract overlay points for the map from the wiki syntax data |
|
| 296 | + * |
|
| 297 | + * @param string $str_points |
|
| 298 | + * multi-line string of lat,lon,text triplets |
|
| 299 | + * @return array multi-dimensional array of lat,lon,text triplets |
|
| 300 | + */ |
|
| 301 | + private function _extract_points(string $str_points): array { |
|
| 302 | + $point = array(); |
|
| 303 | + // preg_match_all('/^([+-]?[0-9].*?),\s*([+-]?[0-9].*?),(.*?),(.*?),(.*?),(.*)$/um', $str_points, $point, PREG_SET_ORDER); |
|
| 304 | + /* |
|
| 305 | 305 | * group 1: ([+-]?[0-9]+(?:\.[0-9]*)?) group 2: ([+-]?[0-9]+(?:\.[0-9]*)?) group 3: (.*?) group 4: (.*?) group 5: (.*?) group 6: (.*) |
| 306 | 306 | */ |
| 307 | - preg_match_all( |
|
| 308 | - '/^([+-]?[0-9]+(?:\.[0-9]*)?),\s*([+-]?[0-9]+(?:\.[0-9]*)?),(.*?),(.*?),(.*?),(.*)$/um', |
|
| 309 | - $str_points, $point, PREG_SET_ORDER |
|
| 310 | - ); |
|
| 311 | - // create poi array |
|
| 312 | - $overlay = array(); |
|
| 313 | - foreach($point as $pt) { |
|
| 314 | - list ($match, $lat, $lon, $angle, $opacity, $img, $text) = $pt; |
|
| 315 | - $lat = is_numeric($lat) ? $lat : 0; |
|
| 316 | - $lon = is_numeric($lon) ? $lon : 0; |
|
| 317 | - $angle = is_numeric($angle) ? $angle : 0; |
|
| 318 | - $opacity = is_numeric($opacity) ? $opacity : 0.8; |
|
| 319 | - // TODO validate using exist & set up default img? |
|
| 320 | - $img = trim($img); |
|
| 321 | - $text = p_get_instructions($text); |
|
| 322 | - // dbg ( $text ); |
|
| 323 | - $text = p_render("xhtml", $text, $info); |
|
| 324 | - // dbg ( $text ); |
|
| 325 | - $text = addslashes(str_replace("\n", "", $text)); |
|
| 326 | - $overlay [] = array( |
|
| 327 | - $lat, |
|
| 328 | - $lon, |
|
| 329 | - $text, |
|
| 330 | - $angle, |
|
| 331 | - $opacity, |
|
| 332 | - $img |
|
| 333 | - ); |
|
| 334 | - } |
|
| 335 | - return $overlay; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * Create a Google maps static image url w/ the poi. |
|
| 340 | - * |
|
| 341 | - * @param array $gmap |
|
| 342 | - * @param array $overlay |
|
| 343 | - * @return string |
|
| 344 | - */ |
|
| 345 | - private function _getGoogle(array $gmap, array $overlay): string { |
|
| 346 | - $sUrl = $this->getConf('iconUrlOverload'); |
|
| 347 | - if(!$sUrl) { |
|
| 348 | - $sUrl = DOKU_URL; |
|
| 349 | - } |
|
| 350 | - switch($gmap ['baselyr']) { |
|
| 351 | - case 'google hybrid' : |
|
| 352 | - $maptype = 'hybrid'; |
|
| 353 | - break; |
|
| 354 | - case 'google sat' : |
|
| 355 | - $maptype = 'satellite'; |
|
| 356 | - break; |
|
| 357 | - case 'terrain' : |
|
| 358 | - case 'google relief' : |
|
| 359 | - $maptype = 'terrain'; |
|
| 360 | - break; |
|
| 361 | - case 'google road' : |
|
| 362 | - default : |
|
| 363 | - $maptype = 'roadmap'; |
|
| 364 | - break; |
|
| 365 | - } |
|
| 366 | - // TODO maybe use viewport / visible instead of center/zoom, |
|
| 367 | - // see: https://developers.google.com/maps/documentation/staticmaps/index#Viewports |
|
| 368 | - // http://maps.google.com/maps/api/staticmap?center=51.565690,5.456756&zoom=16&size=600x400&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/marker.png|label:1|51.565690,5.456756&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/marker-blue.png|51.566197,5.458966|label:2&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/parking.png|51.567177,5.457909|label:3&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/parking.png|51.566283,5.457330|label:4&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/parking.png|51.565630,5.457695|label:5&sensor=false&format=png&maptype=roadmap |
|
| 369 | - $imgUrl = "https://maps.googleapis.com/maps/api/staticmap?"; |
|
| 370 | - $imgUrl .= "&size=" . str_replace("px", "", $gmap ['width']) . "x" |
|
| 371 | - . str_replace("px", "", $gmap ['height']); |
|
| 372 | - //if (!$this->getConf( 'autoZoomMap')) { // no need for center & zoom params } |
|
| 373 | - $imgUrl .= "¢er=" . $gmap ['lat'] . "," . $gmap ['lon']; |
|
| 374 | - // max is 21 (== building scale), but that's overkill.. |
|
| 375 | - if($gmap ['zoom'] > 17) { |
|
| 376 | - $imgUrl .= "&zoom=17"; |
|
| 377 | - } else { |
|
| 378 | - $imgUrl .= "&zoom=" . $gmap ['zoom']; |
|
| 379 | - } |
|
| 380 | - if(!empty ($overlay)) { |
|
| 381 | - $rowId = 0; |
|
| 382 | - foreach($overlay as $data) { |
|
| 383 | - list ($lat, $lon, $text, $angle, $opacity, $img) = $data; |
|
| 384 | - $imgUrl .= "&markers=icon%3a" . $sUrl . "lib/plugins/openlayersmap/icons/" . $img . "%7c" |
|
| 385 | - . $lat . "," . $lon . "%7clabel%3a" . ++$rowId; |
|
| 386 | - } |
|
| 387 | - } |
|
| 388 | - $imgUrl .= "&format=png&maptype=" . $maptype; |
|
| 389 | - global $conf; |
|
| 390 | - $imgUrl .= "&language=" . $conf ['lang']; |
|
| 391 | - if($this->getConf('googleAPIkey')) { |
|
| 392 | - $imgUrl .= "&key=" . $this->getConf('googleAPIkey'); |
|
| 393 | - } |
|
| 394 | - // dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::_getGoogle: Google image url is:'); |
|
| 395 | - return $imgUrl; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Create a MapQuest static map API image url. |
|
| 400 | - * |
|
| 401 | - * @param array $gmap |
|
| 402 | - * @param array $overlay |
|
| 403 | - */ |
|
| 404 | - /* |
|
| 307 | + preg_match_all( |
|
| 308 | + '/^([+-]?[0-9]+(?:\.[0-9]*)?),\s*([+-]?[0-9]+(?:\.[0-9]*)?),(.*?),(.*?),(.*?),(.*)$/um', |
|
| 309 | + $str_points, $point, PREG_SET_ORDER |
|
| 310 | + ); |
|
| 311 | + // create poi array |
|
| 312 | + $overlay = array(); |
|
| 313 | + foreach($point as $pt) { |
|
| 314 | + list ($match, $lat, $lon, $angle, $opacity, $img, $text) = $pt; |
|
| 315 | + $lat = is_numeric($lat) ? $lat : 0; |
|
| 316 | + $lon = is_numeric($lon) ? $lon : 0; |
|
| 317 | + $angle = is_numeric($angle) ? $angle : 0; |
|
| 318 | + $opacity = is_numeric($opacity) ? $opacity : 0.8; |
|
| 319 | + // TODO validate using exist & set up default img? |
|
| 320 | + $img = trim($img); |
|
| 321 | + $text = p_get_instructions($text); |
|
| 322 | + // dbg ( $text ); |
|
| 323 | + $text = p_render("xhtml", $text, $info); |
|
| 324 | + // dbg ( $text ); |
|
| 325 | + $text = addslashes(str_replace("\n", "", $text)); |
|
| 326 | + $overlay [] = array( |
|
| 327 | + $lat, |
|
| 328 | + $lon, |
|
| 329 | + $text, |
|
| 330 | + $angle, |
|
| 331 | + $opacity, |
|
| 332 | + $img |
|
| 333 | + ); |
|
| 334 | + } |
|
| 335 | + return $overlay; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * Create a Google maps static image url w/ the poi. |
|
| 340 | + * |
|
| 341 | + * @param array $gmap |
|
| 342 | + * @param array $overlay |
|
| 343 | + * @return string |
|
| 344 | + */ |
|
| 345 | + private function _getGoogle(array $gmap, array $overlay): string { |
|
| 346 | + $sUrl = $this->getConf('iconUrlOverload'); |
|
| 347 | + if(!$sUrl) { |
|
| 348 | + $sUrl = DOKU_URL; |
|
| 349 | + } |
|
| 350 | + switch($gmap ['baselyr']) { |
|
| 351 | + case 'google hybrid' : |
|
| 352 | + $maptype = 'hybrid'; |
|
| 353 | + break; |
|
| 354 | + case 'google sat' : |
|
| 355 | + $maptype = 'satellite'; |
|
| 356 | + break; |
|
| 357 | + case 'terrain' : |
|
| 358 | + case 'google relief' : |
|
| 359 | + $maptype = 'terrain'; |
|
| 360 | + break; |
|
| 361 | + case 'google road' : |
|
| 362 | + default : |
|
| 363 | + $maptype = 'roadmap'; |
|
| 364 | + break; |
|
| 365 | + } |
|
| 366 | + // TODO maybe use viewport / visible instead of center/zoom, |
|
| 367 | + // see: https://developers.google.com/maps/documentation/staticmaps/index#Viewports |
|
| 368 | + // http://maps.google.com/maps/api/staticmap?center=51.565690,5.456756&zoom=16&size=600x400&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/marker.png|label:1|51.565690,5.456756&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/marker-blue.png|51.566197,5.458966|label:2&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/parking.png|51.567177,5.457909|label:3&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/parking.png|51.566283,5.457330|label:4&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/parking.png|51.565630,5.457695|label:5&sensor=false&format=png&maptype=roadmap |
|
| 369 | + $imgUrl = "https://maps.googleapis.com/maps/api/staticmap?"; |
|
| 370 | + $imgUrl .= "&size=" . str_replace("px", "", $gmap ['width']) . "x" |
|
| 371 | + . str_replace("px", "", $gmap ['height']); |
|
| 372 | + //if (!$this->getConf( 'autoZoomMap')) { // no need for center & zoom params } |
|
| 373 | + $imgUrl .= "¢er=" . $gmap ['lat'] . "," . $gmap ['lon']; |
|
| 374 | + // max is 21 (== building scale), but that's overkill.. |
|
| 375 | + if($gmap ['zoom'] > 17) { |
|
| 376 | + $imgUrl .= "&zoom=17"; |
|
| 377 | + } else { |
|
| 378 | + $imgUrl .= "&zoom=" . $gmap ['zoom']; |
|
| 379 | + } |
|
| 380 | + if(!empty ($overlay)) { |
|
| 381 | + $rowId = 0; |
|
| 382 | + foreach($overlay as $data) { |
|
| 383 | + list ($lat, $lon, $text, $angle, $opacity, $img) = $data; |
|
| 384 | + $imgUrl .= "&markers=icon%3a" . $sUrl . "lib/plugins/openlayersmap/icons/" . $img . "%7c" |
|
| 385 | + . $lat . "," . $lon . "%7clabel%3a" . ++$rowId; |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | + $imgUrl .= "&format=png&maptype=" . $maptype; |
|
| 389 | + global $conf; |
|
| 390 | + $imgUrl .= "&language=" . $conf ['lang']; |
|
| 391 | + if($this->getConf('googleAPIkey')) { |
|
| 392 | + $imgUrl .= "&key=" . $this->getConf('googleAPIkey'); |
|
| 393 | + } |
|
| 394 | + // dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::_getGoogle: Google image url is:'); |
|
| 395 | + return $imgUrl; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Create a MapQuest static map API image url. |
|
| 400 | + * |
|
| 401 | + * @param array $gmap |
|
| 402 | + * @param array $overlay |
|
| 403 | + */ |
|
| 404 | + /* |
|
| 405 | 405 | private function _getMapQuest($gmap, $overlay) { |
| 406 | 406 | $sUrl = $this->getConf ( 'iconUrlOverload' ); |
| 407 | 407 | if (! $sUrl) { |
@@ -458,334 +458,334 @@ discard block |
||
| 458 | 458 | } |
| 459 | 459 | */ |
| 460 | 460 | |
| 461 | - /** |
|
| 462 | - * Create a static OSM map image url w/ the poi from http://staticmap.openstreetmap.de (staticMapLite) |
|
| 463 | - * use http://staticmap.openstreetmap.de "staticMapLite" or a local version |
|
| 464 | - * |
|
| 465 | - * @param array $gmap |
|
| 466 | - * @param array $overlay |
|
| 467 | - * |
|
| 468 | - * @return false|string |
|
| 469 | - * @todo implementation for http://ojw.dev.openstreetmap.org/StaticMapDev/ |
|
| 470 | - */ |
|
| 471 | - private function _getStaticOSM(array $gmap, array $overlay) { |
|
| 472 | - global $conf; |
|
| 473 | - |
|
| 474 | - if($this->getConf('optionStaticMapGenerator') == 'local') { |
|
| 475 | - // using local basemap composer |
|
| 476 | - if(!$myMap = plugin_load('helper', 'openlayersmap_staticmap')) { |
|
| 477 | - dbglog($myMap, 'syntax_plugin_openlayersmap_olmap::_getStaticOSM: openlayersmap_staticmap plugin is not available.'); |
|
| 478 | - } |
|
| 479 | - if(!$geophp = plugin_load('helper', 'geophp')) { |
|
| 480 | - dbglog($geophp, 'syntax_plugin_openlayersmap_olmap::_getStaticOSM: geophp plugin is not available.'); |
|
| 481 | - } |
|
| 482 | - $size = str_replace("px", "", $gmap ['width']) . "x" |
|
| 483 | - . str_replace("px", "", $gmap ['height']); |
|
| 484 | - |
|
| 485 | - $markers = array(); |
|
| 486 | - if(!empty ($overlay)) { |
|
| 487 | - foreach($overlay as $data) { |
|
| 488 | - list ($lat, $lon, $text, $angle, $opacity, $img) = $data; |
|
| 489 | - $iconStyle = substr($img, 0, strlen($img) - 4); |
|
| 490 | - $markers [] = array( |
|
| 491 | - 'lat' => $lat, |
|
| 492 | - 'lon' => $lon, |
|
| 493 | - 'type' => $iconStyle |
|
| 494 | - ); |
|
| 495 | - } |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - $apikey = ''; |
|
| 499 | - switch($gmap ['baselyr']) { |
|
| 500 | - case 'mapnik' : |
|
| 501 | - case 'openstreetmap' : |
|
| 502 | - $maptype = 'openstreetmap'; |
|
| 503 | - break; |
|
| 504 | - case 'transport' : |
|
| 505 | - $maptype = 'transport'; |
|
| 506 | - $apikey = $this->getConf('tfApiKey'); |
|
| 507 | - break; |
|
| 508 | - case 'landscape' : |
|
| 509 | - $maptype = 'landscape'; |
|
| 510 | - $apikey = $this->getConf('tfApiKey'); |
|
| 511 | - break; |
|
| 512 | - case 'outdoors' : |
|
| 513 | - $maptype = 'outdoors'; |
|
| 514 | - $apikey = $this->getConf('tfApiKey'); |
|
| 515 | - break; |
|
| 516 | - case 'cycle map' : |
|
| 517 | - $maptype = 'cycle'; |
|
| 518 | - $apikey = $this->getConf('tfApiKey'); |
|
| 519 | - break; |
|
| 520 | - case 'hike and bike map' : |
|
| 521 | - $maptype = 'hikeandbike'; |
|
| 522 | - break; |
|
| 523 | - case 'mapquest hybrid' : |
|
| 524 | - case 'mapquest road' : |
|
| 525 | - case 'mapquest sat' : |
|
| 526 | - $maptype = 'mapquest'; |
|
| 527 | - break; |
|
| 528 | - default : |
|
| 529 | - $maptype = ''; |
|
| 530 | - break; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - $result = $myMap->getMap( |
|
| 534 | - $gmap ['lat'], $gmap ['lon'], $gmap ['zoom'], $size, $maptype, $markers, |
|
| 535 | - $gmap ['gpxfile'], $gmap ['kmlfile'], $gmap ['geojsonfile'] |
|
| 536 | - ); |
|
| 537 | - } else { |
|
| 538 | - // using external basemap composer |
|
| 539 | - |
|
| 540 | - // http://staticmap.openstreetmap.de/staticmap.php?center=47.000622235634,10.117187497601&zoom=5&size=500x350 |
|
| 541 | - // &markers=48.999812532766,8.3593749976708,lightblue1|43.154850037315,17.499999997306,lightblue1|49.487527053077,10.820312497573,ltblu-pushpin|47.951071133739,15.917968747369,ol-marker|47.921629720114,18.027343747285,ol-marker-gold|47.951071133739,19.257812497236,ol-marker-blue|47.180141361692,19.257812497236,ol-marker-green |
|
| 542 | - $imgUrl = "https://staticmap.openstreetmap.de/staticmap.php"; |
|
| 543 | - $imgUrl .= "?center=" . $gmap ['lat'] . "," . $gmap ['lon']; |
|
| 544 | - $imgUrl .= "&size=" . str_replace("px", "", $gmap ['width']) . "x" |
|
| 545 | - . str_replace("px", "", $gmap ['height']); |
|
| 546 | - |
|
| 547 | - if($gmap ['zoom'] > 16) { |
|
| 548 | - // actually this could even be 18, but that seems overkill |
|
| 549 | - $imgUrl .= "&zoom=16"; |
|
| 550 | - } else { |
|
| 551 | - $imgUrl .= "&zoom=" . $gmap ['zoom']; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - if(!empty ($overlay)) { |
|
| 555 | - $rowId = 0; |
|
| 556 | - $imgUrl .= "&markers="; |
|
| 557 | - foreach($overlay as $data) { |
|
| 558 | - list ($lat, $lon, $text, $angle, $opacity, $img) = $data; |
|
| 559 | - $rowId++; |
|
| 560 | - $iconStyle = "lightblue$rowId"; |
|
| 561 | - $imgUrl .= "$lat,$lon,$iconStyle%7c"; |
|
| 562 | - } |
|
| 563 | - $imgUrl = substr($imgUrl, 0, -3); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - $result = $imgUrl; |
|
| 567 | - } |
|
| 568 | - // dbglog ( $result, 'syntax_plugin_openlayersmap_olmap::_getStaticOSM: osm image url is:' ); |
|
| 569 | - return $result; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * Create a Bing maps static image url w/ the poi. |
|
| 574 | - * |
|
| 575 | - * @param array $gmap |
|
| 576 | - * @param array $overlay |
|
| 577 | - * @return string |
|
| 578 | - */ |
|
| 579 | - private function _getBing(array $gmap, array $overlay): string { |
|
| 580 | - switch($gmap ['baselyr']) { |
|
| 581 | - case 've hybrid' : |
|
| 582 | - case 'bing hybrid' : |
|
| 583 | - $maptype = 'AerialWithLabels'; |
|
| 584 | - break; |
|
| 585 | - case 've sat' : |
|
| 586 | - case 'bing sat' : |
|
| 587 | - $maptype = 'Aerial'; |
|
| 588 | - break; |
|
| 589 | - case 've normal' : |
|
| 590 | - case 've road' : |
|
| 591 | - case 've' : |
|
| 592 | - case 'bing road' : |
|
| 593 | - default : |
|
| 594 | - $maptype = 'Road'; |
|
| 595 | - break; |
|
| 596 | - } |
|
| 597 | - $imgUrl = "https://dev.virtualearth.net/REST/v1/Imagery/Map/" . $maptype;// . "/"; |
|
| 598 | - if($this->getConf('autoZoomMap')) { |
|
| 599 | - $bbox = $this->_calcBBOX($overlay, $gmap ['lat'], $gmap ['lon']); |
|
| 600 | - //$imgUrl .= "?ma=" . $bbox ['minlat'] . "," . $bbox ['minlon'] . "," . $bbox ['maxlat'] . "," . $bbox ['maxlon']; |
|
| 601 | - $imgUrl .= "?ma=" . $bbox ['minlat'] . "%2C" . $bbox ['minlon'] . "%2C" . $bbox ['maxlat'] |
|
| 602 | - . "%2C" . $bbox ['maxlon']; |
|
| 603 | - $imgUrl .= "&dcl=1"; |
|
| 604 | - } |
|
| 605 | - if(strpos($imgUrl, "?") === false) |
|
| 606 | - $imgUrl .= "?"; |
|
| 607 | - |
|
| 608 | - //$imgUrl .= "&ms=" . str_replace ( "px", "", $gmap ['width'] ) . "," . str_replace ( "px", "", $gmap ['height'] ); |
|
| 609 | - $imgUrl .= "&ms=" . str_replace("px", "", $gmap ['width']) . "%2C" |
|
| 610 | - . str_replace("px", "", $gmap ['height']); |
|
| 611 | - $imgUrl .= "&key=" . $this->getConf('bingAPIKey'); |
|
| 612 | - if(!empty ($overlay)) { |
|
| 613 | - $rowId = 0; |
|
| 614 | - foreach($overlay as $data) { |
|
| 615 | - list ($lat, $lon, $text, $angle, $opacity, $img) = $data; |
|
| 616 | - // TODO icon style lookup, see: http://msdn.microsoft.com/en-us/library/ff701719.aspx for iconStyle |
|
| 617 | - $iconStyle = 32; |
|
| 618 | - $rowId++; |
|
| 619 | - // NOTE: the max number of pushpins is 18! or we have to use POST (http://msdn.microsoft.com/en-us/library/ff701724.aspx) |
|
| 620 | - if($rowId == 18) { |
|
| 621 | - break; |
|
| 622 | - } |
|
| 623 | - //$imgUrl .= "&pp=$lat,$lon;$iconStyle;$rowId"; |
|
| 624 | - $imgUrl .= "&pp=$lat%2C$lon%3B$iconStyle%3B$rowId"; |
|
| 625 | - |
|
| 626 | - } |
|
| 627 | - } |
|
| 628 | - global $conf; |
|
| 629 | - $imgUrl .= "&fmt=png"; |
|
| 630 | - $imgUrl .= "&c=" . $conf ['lang']; |
|
| 631 | - // dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::_getBing: bing image url is:'); |
|
| 632 | - return $imgUrl; |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - /** |
|
| 636 | - * Calculate the minimum bbox for a start location + poi. |
|
| 637 | - * |
|
| 638 | - * @param array $overlay |
|
| 639 | - * multi-dimensional array of array($lat, $lon, $text, $angle, $opacity, $img) |
|
| 640 | - * @param float $lat |
|
| 641 | - * latitude for map center |
|
| 642 | - * @param float $lon |
|
| 643 | - * longitude for map center |
|
| 644 | - * @return array :float array describing the mbr and center point |
|
| 645 | - */ |
|
| 646 | - private function _calcBBOX(array $overlay, float $lat, float $lon): array { |
|
| 647 | - $lats = array($lat); |
|
| 648 | - $lons = array($lon); |
|
| 649 | - foreach($overlay as $data) { |
|
| 650 | - list ($lat, $lon, $text, $angle, $opacity, $img) = $data; |
|
| 651 | - $lats [] = $lat; |
|
| 652 | - $lons [] = $lon; |
|
| 653 | - } |
|
| 654 | - sort($lats); |
|
| 655 | - sort($lons); |
|
| 656 | - // TODO: make edge/wrap around cases work |
|
| 657 | - $centerlat = $lats [0] + ($lats [count($lats) - 1] - $lats [0]); |
|
| 658 | - $centerlon = $lons [0] + ($lons [count($lats) - 1] - $lons [0]); |
|
| 659 | - return array( |
|
| 660 | - 'minlat' => $lats [0], |
|
| 661 | - 'minlon' => $lons [0], |
|
| 662 | - 'maxlat' => $lats [count($lats) - 1], |
|
| 663 | - 'maxlon' => $lons [count($lats) - 1], |
|
| 664 | - 'centerlat' => $centerlat, |
|
| 665 | - 'centerlon' => $centerlon |
|
| 666 | - ); |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - /** |
|
| 670 | - * convert latitude in decimal degrees to DMS+hemisphere. |
|
| 671 | - * |
|
| 672 | - * @param float $decimaldegrees |
|
| 673 | - * @return string |
|
| 674 | - * @todo move this into a shared library |
|
| 675 | - */ |
|
| 676 | - private function convertLat(float $decimaldegrees): string { |
|
| 677 | - if(strpos($decimaldegrees, '-') !== false) { |
|
| 678 | - $latPos = "S"; |
|
| 679 | - } else { |
|
| 680 | - $latPos = "N"; |
|
| 681 | - } |
|
| 682 | - $dms = $this->_convertDDtoDMS(abs($decimaldegrees)); |
|
| 683 | - return hsc($dms . $latPos); |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - /** |
|
| 687 | - * Convert decimal degrees to degrees, minutes, seconds format |
|
| 688 | - * |
|
| 689 | - * @param float $decimaldegrees |
|
| 690 | - * @return string dms |
|
| 691 | - * @todo move this into a shared library |
|
| 692 | - */ |
|
| 693 | - private function _convertDDtoDMS(float $decimaldegrees): string { |
|
| 694 | - $dms = floor($decimaldegrees); |
|
| 695 | - $secs = ($decimaldegrees - $dms) * 3600; |
|
| 696 | - $min = floor($secs / 60); |
|
| 697 | - $sec = round($secs - ($min * 60), 3); |
|
| 698 | - $dms .= 'º' . $min . '\'' . $sec . '"'; |
|
| 699 | - return $dms; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - /** |
|
| 703 | - * convert longitude in decimal degrees to DMS+hemisphere. |
|
| 704 | - * |
|
| 705 | - * @param float $decimaldegrees |
|
| 706 | - * @return string |
|
| 707 | - * @todo move this into a shared library |
|
| 708 | - */ |
|
| 709 | - private function convertLon(float $decimaldegrees): string { |
|
| 710 | - if(strpos($decimaldegrees, '-') !== false) { |
|
| 711 | - $lonPos = "W"; |
|
| 712 | - } else { |
|
| 713 | - $lonPos = "E"; |
|
| 714 | - } |
|
| 715 | - $dms = $this->_convertDDtoDMS(abs($decimaldegrees)); |
|
| 716 | - return hsc($dms . $lonPos); |
|
| 717 | - } |
|
| 718 | - |
|
| 719 | - /** |
|
| 720 | - * Figures out the base filename of a media path. |
|
| 721 | - * |
|
| 722 | - * @param string $mediaLink |
|
| 723 | - * @return string |
|
| 724 | - */ |
|
| 725 | - private function getFileName(string $mediaLink): string { |
|
| 726 | - $mediaLink = str_replace('[[', '', $mediaLink); |
|
| 727 | - $mediaLink = str_replace(']]', '', $mediaLink); |
|
| 728 | - $mediaLink = substr($mediaLink, 0, -4); |
|
| 729 | - $parts = explode(':', $mediaLink); |
|
| 730 | - $mediaLink = end($parts); |
|
| 731 | - return str_replace('_', ' ', $mediaLink); |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - /** |
|
| 735 | - * |
|
| 736 | - * @see DokuWiki_Syntax_Plugin::render() |
|
| 737 | - */ |
|
| 738 | - function render($format, Doku_Renderer $renderer, $data): bool { |
|
| 739 | - // set to true after external scripts tags are written |
|
| 740 | - static $initialised = false; |
|
| 741 | - // incremented for each map tag in the page source so we can keep track of each map in this page |
|
| 742 | - static $mapnumber = 0; |
|
| 743 | - |
|
| 744 | - // dbglog($data, 'olmap::render() data.'); |
|
| 745 | - list ($mapid, $param, $mainLat, $mainLon, $poitable, $poitabledesc, $staticImgUrl, $_firstimage) = $data; |
|
| 746 | - |
|
| 747 | - if($format == 'xhtml') { |
|
| 748 | - $olscript = ''; |
|
| 749 | - $olEnable = false; |
|
| 750 | - $gscript = ''; |
|
| 751 | - $gEnable = $this->getConf('enableGoogle'); |
|
| 752 | - $stamenEnable = $this->getConf('enableStamen'); |
|
| 753 | - $osmEnable = $this->getConf('enableOSM'); |
|
| 754 | - $enableBing = $this->getConf('enableBing'); |
|
| 755 | - |
|
| 756 | - $scriptEnable = ''; |
|
| 757 | - if(!$initialised) { |
|
| 758 | - $initialised = true; |
|
| 759 | - // render necessary script tags |
|
| 760 | - if($gEnable) { |
|
| 761 | - $gscript = '<script charset="utf-8" defer="defer" src="//maps.google.com/maps/api/js?v=3.29&key=' |
|
| 762 | - . $this->getConf('googleAPIkey') . '"></script>'; |
|
| 763 | - } |
|
| 764 | - $olscript = '<script charset="utf-8" defer="defer" src="' . DOKU_BASE |
|
| 765 | - . 'lib/plugins/openlayersmap/lib/OpenLayers.js"></script>'; |
|
| 766 | - |
|
| 767 | - $scriptEnable = '<script defer="defer" charset="utf-8" src="data:text/javascript;base64,'; |
|
| 768 | - $scriptSrc = $olscript ? 'olEnable = true;' : 'olEnable = false;'; |
|
| 769 | - $scriptSrc .= 'gEnable = ' . ($gEnable ? 'true' : 'false') . ';'; |
|
| 770 | - $scriptSrc .= 'osmEnable = ' . ($osmEnable ? 'true' : 'false') . ';'; |
|
| 771 | - $scriptSrc .= 'stamenEnable = ' . ($stamenEnable ? 'true' : 'false') . ';'; |
|
| 772 | - $scriptSrc .= 'bEnable = ' . ($enableBing ? 'true' : 'false') . ';'; |
|
| 773 | - $scriptSrc .= 'bApiKey="' . $this->getConf('bingAPIKey') . '";'; |
|
| 774 | - $scriptSrc .= 'tfApiKey="' . $this->getConf('tfApiKey') . '";'; |
|
| 775 | - $scriptSrc .= 'gApiKey="' . $this->getConf('googleAPIkey') . '";'; |
|
| 776 | - $scriptEnable .= base64_encode($scriptSrc); |
|
| 777 | - $scriptEnable .= '"></script>'; |
|
| 778 | - } |
|
| 779 | - $renderer->doc .= "$gscript\n$olscript\n$scriptEnable"; |
|
| 780 | - $renderer->doc .= '<div class="olMapHelp">' . $this->locale_xhtml("help") . '</div>'; |
|
| 781 | - if($this->getConf('enableA11y')) { |
|
| 782 | - $renderer->doc .= '<div id="' . $mapid . '-static" class="olStaticMap">' |
|
| 783 | - . p_render($format, p_get_instructions($staticImgUrl), $info) . '</div>'; |
|
| 784 | - } |
|
| 785 | - $renderer->doc .= '<div id="' . $mapid . '-clearer" class="clearer"><p> </p></div>'; |
|
| 786 | - if($this->getConf('enableA11y')) { |
|
| 787 | - // render a table of the POI for the print and a11y presentation, it is hidden using javascript |
|
| 788 | - $renderer->doc .= '<div class="olPOItableSpan" id="' . $mapid . '-table-span"> |
|
| 461 | + /** |
|
| 462 | + * Create a static OSM map image url w/ the poi from http://staticmap.openstreetmap.de (staticMapLite) |
|
| 463 | + * use http://staticmap.openstreetmap.de "staticMapLite" or a local version |
|
| 464 | + * |
|
| 465 | + * @param array $gmap |
|
| 466 | + * @param array $overlay |
|
| 467 | + * |
|
| 468 | + * @return false|string |
|
| 469 | + * @todo implementation for http://ojw.dev.openstreetmap.org/StaticMapDev/ |
|
| 470 | + */ |
|
| 471 | + private function _getStaticOSM(array $gmap, array $overlay) { |
|
| 472 | + global $conf; |
|
| 473 | + |
|
| 474 | + if($this->getConf('optionStaticMapGenerator') == 'local') { |
|
| 475 | + // using local basemap composer |
|
| 476 | + if(!$myMap = plugin_load('helper', 'openlayersmap_staticmap')) { |
|
| 477 | + dbglog($myMap, 'syntax_plugin_openlayersmap_olmap::_getStaticOSM: openlayersmap_staticmap plugin is not available.'); |
|
| 478 | + } |
|
| 479 | + if(!$geophp = plugin_load('helper', 'geophp')) { |
|
| 480 | + dbglog($geophp, 'syntax_plugin_openlayersmap_olmap::_getStaticOSM: geophp plugin is not available.'); |
|
| 481 | + } |
|
| 482 | + $size = str_replace("px", "", $gmap ['width']) . "x" |
|
| 483 | + . str_replace("px", "", $gmap ['height']); |
|
| 484 | + |
|
| 485 | + $markers = array(); |
|
| 486 | + if(!empty ($overlay)) { |
|
| 487 | + foreach($overlay as $data) { |
|
| 488 | + list ($lat, $lon, $text, $angle, $opacity, $img) = $data; |
|
| 489 | + $iconStyle = substr($img, 0, strlen($img) - 4); |
|
| 490 | + $markers [] = array( |
|
| 491 | + 'lat' => $lat, |
|
| 492 | + 'lon' => $lon, |
|
| 493 | + 'type' => $iconStyle |
|
| 494 | + ); |
|
| 495 | + } |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + $apikey = ''; |
|
| 499 | + switch($gmap ['baselyr']) { |
|
| 500 | + case 'mapnik' : |
|
| 501 | + case 'openstreetmap' : |
|
| 502 | + $maptype = 'openstreetmap'; |
|
| 503 | + break; |
|
| 504 | + case 'transport' : |
|
| 505 | + $maptype = 'transport'; |
|
| 506 | + $apikey = $this->getConf('tfApiKey'); |
|
| 507 | + break; |
|
| 508 | + case 'landscape' : |
|
| 509 | + $maptype = 'landscape'; |
|
| 510 | + $apikey = $this->getConf('tfApiKey'); |
|
| 511 | + break; |
|
| 512 | + case 'outdoors' : |
|
| 513 | + $maptype = 'outdoors'; |
|
| 514 | + $apikey = $this->getConf('tfApiKey'); |
|
| 515 | + break; |
|
| 516 | + case 'cycle map' : |
|
| 517 | + $maptype = 'cycle'; |
|
| 518 | + $apikey = $this->getConf('tfApiKey'); |
|
| 519 | + break; |
|
| 520 | + case 'hike and bike map' : |
|
| 521 | + $maptype = 'hikeandbike'; |
|
| 522 | + break; |
|
| 523 | + case 'mapquest hybrid' : |
|
| 524 | + case 'mapquest road' : |
|
| 525 | + case 'mapquest sat' : |
|
| 526 | + $maptype = 'mapquest'; |
|
| 527 | + break; |
|
| 528 | + default : |
|
| 529 | + $maptype = ''; |
|
| 530 | + break; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + $result = $myMap->getMap( |
|
| 534 | + $gmap ['lat'], $gmap ['lon'], $gmap ['zoom'], $size, $maptype, $markers, |
|
| 535 | + $gmap ['gpxfile'], $gmap ['kmlfile'], $gmap ['geojsonfile'] |
|
| 536 | + ); |
|
| 537 | + } else { |
|
| 538 | + // using external basemap composer |
|
| 539 | + |
|
| 540 | + // http://staticmap.openstreetmap.de/staticmap.php?center=47.000622235634,10.117187497601&zoom=5&size=500x350 |
|
| 541 | + // &markers=48.999812532766,8.3593749976708,lightblue1|43.154850037315,17.499999997306,lightblue1|49.487527053077,10.820312497573,ltblu-pushpin|47.951071133739,15.917968747369,ol-marker|47.921629720114,18.027343747285,ol-marker-gold|47.951071133739,19.257812497236,ol-marker-blue|47.180141361692,19.257812497236,ol-marker-green |
|
| 542 | + $imgUrl = "https://staticmap.openstreetmap.de/staticmap.php"; |
|
| 543 | + $imgUrl .= "?center=" . $gmap ['lat'] . "," . $gmap ['lon']; |
|
| 544 | + $imgUrl .= "&size=" . str_replace("px", "", $gmap ['width']) . "x" |
|
| 545 | + . str_replace("px", "", $gmap ['height']); |
|
| 546 | + |
|
| 547 | + if($gmap ['zoom'] > 16) { |
|
| 548 | + // actually this could even be 18, but that seems overkill |
|
| 549 | + $imgUrl .= "&zoom=16"; |
|
| 550 | + } else { |
|
| 551 | + $imgUrl .= "&zoom=" . $gmap ['zoom']; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + if(!empty ($overlay)) { |
|
| 555 | + $rowId = 0; |
|
| 556 | + $imgUrl .= "&markers="; |
|
| 557 | + foreach($overlay as $data) { |
|
| 558 | + list ($lat, $lon, $text, $angle, $opacity, $img) = $data; |
|
| 559 | + $rowId++; |
|
| 560 | + $iconStyle = "lightblue$rowId"; |
|
| 561 | + $imgUrl .= "$lat,$lon,$iconStyle%7c"; |
|
| 562 | + } |
|
| 563 | + $imgUrl = substr($imgUrl, 0, -3); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + $result = $imgUrl; |
|
| 567 | + } |
|
| 568 | + // dbglog ( $result, 'syntax_plugin_openlayersmap_olmap::_getStaticOSM: osm image url is:' ); |
|
| 569 | + return $result; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * Create a Bing maps static image url w/ the poi. |
|
| 574 | + * |
|
| 575 | + * @param array $gmap |
|
| 576 | + * @param array $overlay |
|
| 577 | + * @return string |
|
| 578 | + */ |
|
| 579 | + private function _getBing(array $gmap, array $overlay): string { |
|
| 580 | + switch($gmap ['baselyr']) { |
|
| 581 | + case 've hybrid' : |
|
| 582 | + case 'bing hybrid' : |
|
| 583 | + $maptype = 'AerialWithLabels'; |
|
| 584 | + break; |
|
| 585 | + case 've sat' : |
|
| 586 | + case 'bing sat' : |
|
| 587 | + $maptype = 'Aerial'; |
|
| 588 | + break; |
|
| 589 | + case 've normal' : |
|
| 590 | + case 've road' : |
|
| 591 | + case 've' : |
|
| 592 | + case 'bing road' : |
|
| 593 | + default : |
|
| 594 | + $maptype = 'Road'; |
|
| 595 | + break; |
|
| 596 | + } |
|
| 597 | + $imgUrl = "https://dev.virtualearth.net/REST/v1/Imagery/Map/" . $maptype;// . "/"; |
|
| 598 | + if($this->getConf('autoZoomMap')) { |
|
| 599 | + $bbox = $this->_calcBBOX($overlay, $gmap ['lat'], $gmap ['lon']); |
|
| 600 | + //$imgUrl .= "?ma=" . $bbox ['minlat'] . "," . $bbox ['minlon'] . "," . $bbox ['maxlat'] . "," . $bbox ['maxlon']; |
|
| 601 | + $imgUrl .= "?ma=" . $bbox ['minlat'] . "%2C" . $bbox ['minlon'] . "%2C" . $bbox ['maxlat'] |
|
| 602 | + . "%2C" . $bbox ['maxlon']; |
|
| 603 | + $imgUrl .= "&dcl=1"; |
|
| 604 | + } |
|
| 605 | + if(strpos($imgUrl, "?") === false) |
|
| 606 | + $imgUrl .= "?"; |
|
| 607 | + |
|
| 608 | + //$imgUrl .= "&ms=" . str_replace ( "px", "", $gmap ['width'] ) . "," . str_replace ( "px", "", $gmap ['height'] ); |
|
| 609 | + $imgUrl .= "&ms=" . str_replace("px", "", $gmap ['width']) . "%2C" |
|
| 610 | + . str_replace("px", "", $gmap ['height']); |
|
| 611 | + $imgUrl .= "&key=" . $this->getConf('bingAPIKey'); |
|
| 612 | + if(!empty ($overlay)) { |
|
| 613 | + $rowId = 0; |
|
| 614 | + foreach($overlay as $data) { |
|
| 615 | + list ($lat, $lon, $text, $angle, $opacity, $img) = $data; |
|
| 616 | + // TODO icon style lookup, see: http://msdn.microsoft.com/en-us/library/ff701719.aspx for iconStyle |
|
| 617 | + $iconStyle = 32; |
|
| 618 | + $rowId++; |
|
| 619 | + // NOTE: the max number of pushpins is 18! or we have to use POST (http://msdn.microsoft.com/en-us/library/ff701724.aspx) |
|
| 620 | + if($rowId == 18) { |
|
| 621 | + break; |
|
| 622 | + } |
|
| 623 | + //$imgUrl .= "&pp=$lat,$lon;$iconStyle;$rowId"; |
|
| 624 | + $imgUrl .= "&pp=$lat%2C$lon%3B$iconStyle%3B$rowId"; |
|
| 625 | + |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | + global $conf; |
|
| 629 | + $imgUrl .= "&fmt=png"; |
|
| 630 | + $imgUrl .= "&c=" . $conf ['lang']; |
|
| 631 | + // dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::_getBing: bing image url is:'); |
|
| 632 | + return $imgUrl; |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + /** |
|
| 636 | + * Calculate the minimum bbox for a start location + poi. |
|
| 637 | + * |
|
| 638 | + * @param array $overlay |
|
| 639 | + * multi-dimensional array of array($lat, $lon, $text, $angle, $opacity, $img) |
|
| 640 | + * @param float $lat |
|
| 641 | + * latitude for map center |
|
| 642 | + * @param float $lon |
|
| 643 | + * longitude for map center |
|
| 644 | + * @return array :float array describing the mbr and center point |
|
| 645 | + */ |
|
| 646 | + private function _calcBBOX(array $overlay, float $lat, float $lon): array { |
|
| 647 | + $lats = array($lat); |
|
| 648 | + $lons = array($lon); |
|
| 649 | + foreach($overlay as $data) { |
|
| 650 | + list ($lat, $lon, $text, $angle, $opacity, $img) = $data; |
|
| 651 | + $lats [] = $lat; |
|
| 652 | + $lons [] = $lon; |
|
| 653 | + } |
|
| 654 | + sort($lats); |
|
| 655 | + sort($lons); |
|
| 656 | + // TODO: make edge/wrap around cases work |
|
| 657 | + $centerlat = $lats [0] + ($lats [count($lats) - 1] - $lats [0]); |
|
| 658 | + $centerlon = $lons [0] + ($lons [count($lats) - 1] - $lons [0]); |
|
| 659 | + return array( |
|
| 660 | + 'minlat' => $lats [0], |
|
| 661 | + 'minlon' => $lons [0], |
|
| 662 | + 'maxlat' => $lats [count($lats) - 1], |
|
| 663 | + 'maxlon' => $lons [count($lats) - 1], |
|
| 664 | + 'centerlat' => $centerlat, |
|
| 665 | + 'centerlon' => $centerlon |
|
| 666 | + ); |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + /** |
|
| 670 | + * convert latitude in decimal degrees to DMS+hemisphere. |
|
| 671 | + * |
|
| 672 | + * @param float $decimaldegrees |
|
| 673 | + * @return string |
|
| 674 | + * @todo move this into a shared library |
|
| 675 | + */ |
|
| 676 | + private function convertLat(float $decimaldegrees): string { |
|
| 677 | + if(strpos($decimaldegrees, '-') !== false) { |
|
| 678 | + $latPos = "S"; |
|
| 679 | + } else { |
|
| 680 | + $latPos = "N"; |
|
| 681 | + } |
|
| 682 | + $dms = $this->_convertDDtoDMS(abs($decimaldegrees)); |
|
| 683 | + return hsc($dms . $latPos); |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + /** |
|
| 687 | + * Convert decimal degrees to degrees, minutes, seconds format |
|
| 688 | + * |
|
| 689 | + * @param float $decimaldegrees |
|
| 690 | + * @return string dms |
|
| 691 | + * @todo move this into a shared library |
|
| 692 | + */ |
|
| 693 | + private function _convertDDtoDMS(float $decimaldegrees): string { |
|
| 694 | + $dms = floor($decimaldegrees); |
|
| 695 | + $secs = ($decimaldegrees - $dms) * 3600; |
|
| 696 | + $min = floor($secs / 60); |
|
| 697 | + $sec = round($secs - ($min * 60), 3); |
|
| 698 | + $dms .= 'º' . $min . '\'' . $sec . '"'; |
|
| 699 | + return $dms; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + /** |
|
| 703 | + * convert longitude in decimal degrees to DMS+hemisphere. |
|
| 704 | + * |
|
| 705 | + * @param float $decimaldegrees |
|
| 706 | + * @return string |
|
| 707 | + * @todo move this into a shared library |
|
| 708 | + */ |
|
| 709 | + private function convertLon(float $decimaldegrees): string { |
|
| 710 | + if(strpos($decimaldegrees, '-') !== false) { |
|
| 711 | + $lonPos = "W"; |
|
| 712 | + } else { |
|
| 713 | + $lonPos = "E"; |
|
| 714 | + } |
|
| 715 | + $dms = $this->_convertDDtoDMS(abs($decimaldegrees)); |
|
| 716 | + return hsc($dms . $lonPos); |
|
| 717 | + } |
|
| 718 | + |
|
| 719 | + /** |
|
| 720 | + * Figures out the base filename of a media path. |
|
| 721 | + * |
|
| 722 | + * @param string $mediaLink |
|
| 723 | + * @return string |
|
| 724 | + */ |
|
| 725 | + private function getFileName(string $mediaLink): string { |
|
| 726 | + $mediaLink = str_replace('[[', '', $mediaLink); |
|
| 727 | + $mediaLink = str_replace(']]', '', $mediaLink); |
|
| 728 | + $mediaLink = substr($mediaLink, 0, -4); |
|
| 729 | + $parts = explode(':', $mediaLink); |
|
| 730 | + $mediaLink = end($parts); |
|
| 731 | + return str_replace('_', ' ', $mediaLink); |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + /** |
|
| 735 | + * |
|
| 736 | + * @see DokuWiki_Syntax_Plugin::render() |
|
| 737 | + */ |
|
| 738 | + function render($format, Doku_Renderer $renderer, $data): bool { |
|
| 739 | + // set to true after external scripts tags are written |
|
| 740 | + static $initialised = false; |
|
| 741 | + // incremented for each map tag in the page source so we can keep track of each map in this page |
|
| 742 | + static $mapnumber = 0; |
|
| 743 | + |
|
| 744 | + // dbglog($data, 'olmap::render() data.'); |
|
| 745 | + list ($mapid, $param, $mainLat, $mainLon, $poitable, $poitabledesc, $staticImgUrl, $_firstimage) = $data; |
|
| 746 | + |
|
| 747 | + if($format == 'xhtml') { |
|
| 748 | + $olscript = ''; |
|
| 749 | + $olEnable = false; |
|
| 750 | + $gscript = ''; |
|
| 751 | + $gEnable = $this->getConf('enableGoogle'); |
|
| 752 | + $stamenEnable = $this->getConf('enableStamen'); |
|
| 753 | + $osmEnable = $this->getConf('enableOSM'); |
|
| 754 | + $enableBing = $this->getConf('enableBing'); |
|
| 755 | + |
|
| 756 | + $scriptEnable = ''; |
|
| 757 | + if(!$initialised) { |
|
| 758 | + $initialised = true; |
|
| 759 | + // render necessary script tags |
|
| 760 | + if($gEnable) { |
|
| 761 | + $gscript = '<script charset="utf-8" defer="defer" src="//maps.google.com/maps/api/js?v=3.29&key=' |
|
| 762 | + . $this->getConf('googleAPIkey') . '"></script>'; |
|
| 763 | + } |
|
| 764 | + $olscript = '<script charset="utf-8" defer="defer" src="' . DOKU_BASE |
|
| 765 | + . 'lib/plugins/openlayersmap/lib/OpenLayers.js"></script>'; |
|
| 766 | + |
|
| 767 | + $scriptEnable = '<script defer="defer" charset="utf-8" src="data:text/javascript;base64,'; |
|
| 768 | + $scriptSrc = $olscript ? 'olEnable = true;' : 'olEnable = false;'; |
|
| 769 | + $scriptSrc .= 'gEnable = ' . ($gEnable ? 'true' : 'false') . ';'; |
|
| 770 | + $scriptSrc .= 'osmEnable = ' . ($osmEnable ? 'true' : 'false') . ';'; |
|
| 771 | + $scriptSrc .= 'stamenEnable = ' . ($stamenEnable ? 'true' : 'false') . ';'; |
|
| 772 | + $scriptSrc .= 'bEnable = ' . ($enableBing ? 'true' : 'false') . ';'; |
|
| 773 | + $scriptSrc .= 'bApiKey="' . $this->getConf('bingAPIKey') . '";'; |
|
| 774 | + $scriptSrc .= 'tfApiKey="' . $this->getConf('tfApiKey') . '";'; |
|
| 775 | + $scriptSrc .= 'gApiKey="' . $this->getConf('googleAPIkey') . '";'; |
|
| 776 | + $scriptEnable .= base64_encode($scriptSrc); |
|
| 777 | + $scriptEnable .= '"></script>'; |
|
| 778 | + } |
|
| 779 | + $renderer->doc .= "$gscript\n$olscript\n$scriptEnable"; |
|
| 780 | + $renderer->doc .= '<div class="olMapHelp">' . $this->locale_xhtml("help") . '</div>'; |
|
| 781 | + if($this->getConf('enableA11y')) { |
|
| 782 | + $renderer->doc .= '<div id="' . $mapid . '-static" class="olStaticMap">' |
|
| 783 | + . p_render($format, p_get_instructions($staticImgUrl), $info) . '</div>'; |
|
| 784 | + } |
|
| 785 | + $renderer->doc .= '<div id="' . $mapid . '-clearer" class="clearer"><p> </p></div>'; |
|
| 786 | + if($this->getConf('enableA11y')) { |
|
| 787 | + // render a table of the POI for the print and a11y presentation, it is hidden using javascript |
|
| 788 | + $renderer->doc .= '<div class="olPOItableSpan" id="' . $mapid . '-table-span"> |
|
| 789 | 789 | <table class="olPOItable" id="' . $mapid . '-table"> |
| 790 | 790 | <caption class="olPOITblCaption">' . $this->getLang('olmapPOItitle') . '</caption> |
| 791 | 791 | <thead class="olPOITblHeader"> |
@@ -793,59 +793,59 @@ discard block |
||
| 793 | 793 | <th class="rowId" scope="col">id</th> |
| 794 | 794 | <th class="icon" scope="col">' . $this->getLang('olmapPOIicon') . '</th> |
| 795 | 795 | <th class="lat" scope="col" title="' . $this->getLang('olmapPOIlatTitle') . '">' |
| 796 | - . $this->getLang('olmapPOIlat') . '</th> |
|
| 796 | + . $this->getLang('olmapPOIlat') . '</th> |
|
| 797 | 797 | <th class="lon" scope="col" title="' . $this->getLang('olmapPOIlonTitle') . '">' |
| 798 | - . $this->getLang('olmapPOIlon') . '</th> |
|
| 798 | + . $this->getLang('olmapPOIlon') . '</th> |
|
| 799 | 799 | <th class="txt" scope="col">' . $this->getLang('olmapPOItxt') . '</th> |
| 800 | 800 | </tr> |
| 801 | 801 | </thead>'; |
| 802 | - if($poitabledesc != '') { |
|
| 803 | - $renderer->doc .= '<tfoot class="olPOITblFooter"><tr><td colspan="5">' . $poitabledesc |
|
| 804 | - . '</td></tr></tfoot>'; |
|
| 805 | - } |
|
| 806 | - $renderer->doc .= '<tbody class="olPOITblBody">' . $poitable . '</tbody> |
|
| 802 | + if($poitabledesc != '') { |
|
| 803 | + $renderer->doc .= '<tfoot class="olPOITblFooter"><tr><td colspan="5">' . $poitabledesc |
|
| 804 | + . '</td></tr></tfoot>'; |
|
| 805 | + } |
|
| 806 | + $renderer->doc .= '<tbody class="olPOITblBody">' . $poitable . '</tbody> |
|
| 807 | 807 | </table></div>'; |
| 808 | - } |
|
| 809 | - // render inline mapscript parts |
|
| 810 | - $renderer->doc .= '<script charset="utf-8" defer="defer" src="data:text/javascript;base64,'; |
|
| 811 | - $renderer->doc .= base64_encode("olMapData[$mapnumber] = $param"); |
|
| 812 | - $renderer->doc .= '"></script>'; |
|
| 813 | - $mapnumber++; |
|
| 814 | - return true; |
|
| 815 | - } elseif($format == 'metadata') { |
|
| 816 | - if(!(($this->dflt ['lat'] == $mainLat) && ($this->dflt ['lon'] == $mainLon))) { |
|
| 817 | - // render geo metadata, unless they are the default |
|
| 818 | - $renderer->meta ['geo'] ['lat'] = $mainLat; |
|
| 819 | - $renderer->meta ['geo'] ['lon'] = $mainLon; |
|
| 820 | - if($geophp = plugin_load('helper', 'geophp')) { |
|
| 821 | - // if we have the geoPHP helper, add the geohash |
|
| 822 | - // fails with older php versions.. $renderer->meta['geo']['geohash'] = (new Point($mainLon,$mainLat))->out('geohash'); |
|
| 823 | - $p = new Point ($mainLon, $mainLat); |
|
| 824 | - $renderer->meta ['geo'] ['geohash'] = $p->out('geohash'); |
|
| 825 | - } |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - if(($this->getConf('enableA11y')) && (!empty ($_firstimage))) { |
|
| 829 | - // add map local image into relation/firstimage if not already filled and when it is a local image |
|
| 830 | - |
|
| 831 | - global $ID; |
|
| 832 | - $rel = p_get_metadata($ID, 'relation', METADATA_RENDER_USING_CACHE); |
|
| 833 | - $img = $rel ['firstimage']; |
|
| 834 | - if(empty ($img) /* || $img == $_firstimage*/) { |
|
| 835 | - //dbglog ( $_firstimage, 'olmap::render#rendering image relation metadata for _firstimage as $img was empty or the same.' ); |
|
| 836 | - // This seems to never work; the firstimage entry in the .meta file is empty |
|
| 837 | - // $renderer->meta['relation']['firstimage'] = $_firstimage; |
|
| 838 | - |
|
| 839 | - // ... and neither does this; the firstimage entry in the .meta file is empty |
|
| 840 | - // $relation = array('relation'=>array('firstimage'=>$_firstimage)); |
|
| 841 | - // p_set_metadata($ID, $relation, false, false); |
|
| 842 | - |
|
| 843 | - // ... this works |
|
| 844 | - $renderer->internalmedia($_firstimage, $poitabledesc); |
|
| 845 | - } |
|
| 846 | - } |
|
| 847 | - return true; |
|
| 848 | - } |
|
| 849 | - return false; |
|
| 850 | - } |
|
| 808 | + } |
|
| 809 | + // render inline mapscript parts |
|
| 810 | + $renderer->doc .= '<script charset="utf-8" defer="defer" src="data:text/javascript;base64,'; |
|
| 811 | + $renderer->doc .= base64_encode("olMapData[$mapnumber] = $param"); |
|
| 812 | + $renderer->doc .= '"></script>'; |
|
| 813 | + $mapnumber++; |
|
| 814 | + return true; |
|
| 815 | + } elseif($format == 'metadata') { |
|
| 816 | + if(!(($this->dflt ['lat'] == $mainLat) && ($this->dflt ['lon'] == $mainLon))) { |
|
| 817 | + // render geo metadata, unless they are the default |
|
| 818 | + $renderer->meta ['geo'] ['lat'] = $mainLat; |
|
| 819 | + $renderer->meta ['geo'] ['lon'] = $mainLon; |
|
| 820 | + if($geophp = plugin_load('helper', 'geophp')) { |
|
| 821 | + // if we have the geoPHP helper, add the geohash |
|
| 822 | + // fails with older php versions.. $renderer->meta['geo']['geohash'] = (new Point($mainLon,$mainLat))->out('geohash'); |
|
| 823 | + $p = new Point ($mainLon, $mainLat); |
|
| 824 | + $renderer->meta ['geo'] ['geohash'] = $p->out('geohash'); |
|
| 825 | + } |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + if(($this->getConf('enableA11y')) && (!empty ($_firstimage))) { |
|
| 829 | + // add map local image into relation/firstimage if not already filled and when it is a local image |
|
| 830 | + |
|
| 831 | + global $ID; |
|
| 832 | + $rel = p_get_metadata($ID, 'relation', METADATA_RENDER_USING_CACHE); |
|
| 833 | + $img = $rel ['firstimage']; |
|
| 834 | + if(empty ($img) /* || $img == $_firstimage*/) { |
|
| 835 | + //dbglog ( $_firstimage, 'olmap::render#rendering image relation metadata for _firstimage as $img was empty or the same.' ); |
|
| 836 | + // This seems to never work; the firstimage entry in the .meta file is empty |
|
| 837 | + // $renderer->meta['relation']['firstimage'] = $_firstimage; |
|
| 838 | + |
|
| 839 | + // ... and neither does this; the firstimage entry in the .meta file is empty |
|
| 840 | + // $relation = array('relation'=>array('firstimage'=>$_firstimage)); |
|
| 841 | + // p_set_metadata($ID, $relation, false, false); |
|
| 842 | + |
|
| 843 | + // ... this works |
|
| 844 | + $renderer->internalmedia($_firstimage, $poitabledesc); |
|
| 845 | + } |
|
| 846 | + } |
|
| 847 | + return true; |
|
| 848 | + } |
|
| 849 | + return false; |
|
| 850 | + } |
|
| 851 | 851 | } |
@@ -94,10 +94,10 @@ discard block |
||
| 94 | 94 | preg_match('(lon[:|=]\"-?\d*\.?\d*\")', $match, $mainLon); |
| 95 | 95 | $mainLat = substr($mainLat [0], 5, -1); |
| 96 | 96 | $mainLon = substr($mainLon [0], 5, -1); |
| 97 | - if(!is_numeric($mainLat)) { |
|
| 97 | + if (!is_numeric($mainLat)) { |
|
| 98 | 98 | $mainLat = $this->dflt ['lat']; |
| 99 | 99 | } |
| 100 | - if(!is_numeric($mainLon)) { |
|
| 100 | + if (!is_numeric($mainLon)) { |
|
| 101 | 101 | $mainLon = $this->dflt ['lon']; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -108,23 +108,23 @@ discard block |
||
| 108 | 108 | $_nocache = false; |
| 109 | 109 | // choose maptype based on the specified tag |
| 110 | 110 | $imgUrl = "{{"; |
| 111 | - if(stripos($gmap ['baselyr'], 'google') !== false) { |
|
| 111 | + if (stripos($gmap ['baselyr'], 'google') !== false) { |
|
| 112 | 112 | |
| 113 | 113 | $imgUrl .= $this->_getGoogle($gmap, $overlay); |
| 114 | 114 | $imgUrl .= "&.png"; |
| 115 | - } elseif(stripos($gmap ['baselyr'], 'bing') !== false) { |
|
| 115 | + } elseif (stripos($gmap ['baselyr'], 'bing') !== false) { |
|
| 116 | 116 | // Bing |
| 117 | - if(!$this->getConf('bingAPIKey')) { |
|
| 117 | + if (!$this->getConf('bingAPIKey')) { |
|
| 118 | 118 | // in case there is no Bing api key we'll use OSM |
| 119 | 119 | $_firstimageID = $this->_getStaticOSM($gmap, $overlay); |
| 120 | - $imgUrl .= $_firstimageID; |
|
| 121 | - if($this->getConf('optionStaticMapGenerator') == 'remote') { |
|
| 120 | + $imgUrl .= $_firstimageID; |
|
| 121 | + if ($this->getConf('optionStaticMapGenerator') == 'remote') { |
|
| 122 | 122 | $imgUrl .= "&.png"; |
| 123 | 123 | } |
| 124 | 124 | } else { |
| 125 | 125 | // seems that Bing doesn't like the DW client, turn off caching |
| 126 | 126 | $_nocache = true; |
| 127 | - $imgUrl .= $this->_getBing($gmap, $overlay) . "&.png"; |
|
| 127 | + $imgUrl .= $this->_getBing($gmap, $overlay)."&.png"; |
|
| 128 | 128 | } |
| 129 | 129 | } /* elseif (stripos ( $gmap ['baselyr'], 'mapquest' ) !== false) { |
| 130 | 130 | // MapQuest |
@@ -142,33 +142,33 @@ discard block |
||
| 142 | 142 | } */ else { |
| 143 | 143 | // default OSM |
| 144 | 144 | $_firstimageID = $this->_getStaticOSM($gmap, $overlay); |
| 145 | - $imgUrl .= $_firstimageID; |
|
| 146 | - if($this->getConf('optionStaticMapGenerator') == 'remote') { |
|
| 145 | + $imgUrl .= $_firstimageID; |
|
| 146 | + if ($this->getConf('optionStaticMapGenerator') == 'remote') { |
|
| 147 | 147 | $imgUrl .= "&.png"; |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // append dw p_render specific params and render |
| 152 | - $imgUrl .= "?" . str_replace("px", "", $gmap ['width']) . "x" |
|
| 152 | + $imgUrl .= "?".str_replace("px", "", $gmap ['width'])."x" |
|
| 153 | 153 | . str_replace("px", "", $gmap ['height']); |
| 154 | 154 | $imgUrl .= "&nolink"; |
| 155 | 155 | |
| 156 | 156 | // add nocache option for selected services |
| 157 | - if($_nocache) { |
|
| 157 | + if ($_nocache) { |
|
| 158 | 158 | $imgUrl .= "&nocache"; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - $imgUrl .= " |" . $gmap ['summary'] . " }}"; |
|
| 161 | + $imgUrl .= " |".$gmap ['summary']." }}"; |
|
| 162 | 162 | |
| 163 | 163 | // dbglog($imgUrl,"complete image tags is:"); |
| 164 | 164 | |
| 165 | 165 | $mapid = $gmap ['id']; |
| 166 | 166 | // create a javascript parameter string for the map |
| 167 | 167 | $param = ''; |
| 168 | - foreach($gmap as $key => $val) { |
|
| 169 | - $param .= is_numeric($val) ? "$key: $val, " : "$key: '" . hsc($val) . "', "; |
|
| 168 | + foreach ($gmap as $key => $val) { |
|
| 169 | + $param .= is_numeric($val) ? "$key: $val, " : "$key: '".hsc($val)."', "; |
|
| 170 | 170 | } |
| 171 | - if(!empty ($param)) { |
|
| 171 | + if (!empty ($param)) { |
|
| 172 | 172 | $param = substr($param, 0, -2); |
| 173 | 173 | } |
| 174 | 174 | unset ($gmap ['id']); |
@@ -177,13 +177,13 @@ discard block |
||
| 177 | 177 | $poi = ''; |
| 178 | 178 | $poitable = ''; |
| 179 | 179 | $rowId = 0; |
| 180 | - if(!empty ($overlay)) { |
|
| 181 | - foreach($overlay as $data) { |
|
| 180 | + if (!empty ($overlay)) { |
|
| 181 | + foreach ($overlay as $data) { |
|
| 182 | 182 | list ($lat, $lon, $text, $angle, $opacity, $img) = $data; |
| 183 | 183 | $rowId++; |
| 184 | 184 | $poi .= ", {lat: $lat, lon: $lon, txt: '$text', angle: $angle, opacity: $opacity, img: '$img', rowId: $rowId}"; |
| 185 | 185 | |
| 186 | - if($this->getConf('displayformat') === 'DMS') { |
|
| 186 | + if ($this->getConf('displayformat') === 'DMS') { |
|
| 187 | 187 | $lat = $this->convertLat($lat); |
| 188 | 188 | $lon = $this->convertLon($lon); |
| 189 | 189 | } else { |
@@ -193,52 +193,52 @@ discard block |
||
| 193 | 193 | |
| 194 | 194 | $poitable .= ' |
| 195 | 195 | <tr> |
| 196 | - <td class="rowId">' . $rowId . '</td> |
|
| 197 | - <td class="icon"><img src="' . DOKU_BASE . 'lib/plugins/openlayersmap/icons/' . $img . '" alt="' |
|
| 198 | - . substr($img, 0, -4) . $this->getlang('alt_legend_poi') . ' " /></td> |
|
| 199 | - <td class="lat" title="' . $this->getLang('olmapPOIlatTitle') . '">' . $lat . '</td> |
|
| 200 | - <td class="lon" title="' . $this->getLang('olmapPOIlonTitle') . '">' . $lon . '</td> |
|
| 201 | - <td class="txt">' . $text . '</td> |
|
| 196 | + <td class="rowId">' . $rowId.'</td> |
|
| 197 | + <td class="icon"><img src="' . DOKU_BASE.'lib/plugins/openlayersmap/icons/'.$img.'" alt="' |
|
| 198 | + . substr($img, 0, -4).$this->getlang('alt_legend_poi').' " /></td> |
|
| 199 | + <td class="lat" title="' . $this->getLang('olmapPOIlatTitle').'">'.$lat.'</td> |
|
| 200 | + <td class="lon" title="' . $this->getLang('olmapPOIlonTitle').'">'.$lon.'</td> |
|
| 201 | + <td class="txt">' . $text.'</td> |
|
| 202 | 202 | </tr>'; |
| 203 | 203 | } |
| 204 | 204 | $poi = substr($poi, 2); |
| 205 | 205 | } |
| 206 | - if(!empty ($gmap ['kmlfile'])) { |
|
| 206 | + if (!empty ($gmap ['kmlfile'])) { |
|
| 207 | 207 | $poitable .= ' |
| 208 | 208 | <tr> |
| 209 | 209 | <td class="rowId"><img src="' . DOKU_BASE |
| 210 | 210 | . 'lib/plugins/openlayersmap/toolbar/kml_file.png" alt="KML file" /></td> |
| 211 | - <td class="icon"><img src="' . DOKU_BASE . 'lib/plugins/openlayersmap/toolbar/kml_line.png" alt="' |
|
| 212 | - . $this->getlang('alt_legend_kml') . '" /></td> |
|
| 213 | - <td class="txt" colspan="3">KML track: ' . $this->getFileName($gmap ['kmlfile']) . '</td> |
|
| 211 | + <td class="icon"><img src="' . DOKU_BASE.'lib/plugins/openlayersmap/toolbar/kml_line.png" alt="' |
|
| 212 | + . $this->getlang('alt_legend_kml').'" /></td> |
|
| 213 | + <td class="txt" colspan="3">KML track: ' . $this->getFileName($gmap ['kmlfile']).'</td> |
|
| 214 | 214 | </tr>'; |
| 215 | 215 | } |
| 216 | - if(!empty ($gmap ['gpxfile'])) { |
|
| 216 | + if (!empty ($gmap ['gpxfile'])) { |
|
| 217 | 217 | $poitable .= ' |
| 218 | 218 | <tr> |
| 219 | 219 | <td class="rowId"><img src="' . DOKU_BASE |
| 220 | 220 | . 'lib/plugins/openlayersmap/toolbar/gpx_file.png" alt="GPX file" /></td> |
| 221 | 221 | <td class="icon"><img src="' . DOKU_BASE |
| 222 | 222 | . 'lib/plugins/openlayersmap/toolbar/gpx_line.png" alt="' |
| 223 | - . $this->getlang('alt_legend_gpx') . '" /></td> |
|
| 224 | - <td class="txt" colspan="3">GPX track: ' . $this->getFileName($gmap ['gpxfile']) . '</td> |
|
| 223 | + . $this->getlang('alt_legend_gpx').'" /></td> |
|
| 224 | + <td class="txt" colspan="3">GPX track: ' . $this->getFileName($gmap ['gpxfile']).'</td> |
|
| 225 | 225 | </tr>'; |
| 226 | 226 | } |
| 227 | - if(!empty ($gmap ['geojsonfile'])) { |
|
| 227 | + if (!empty ($gmap ['geojsonfile'])) { |
|
| 228 | 228 | $poitable .= ' |
| 229 | 229 | <tr> |
| 230 | 230 | <td class="rowId"><img src="' . DOKU_BASE |
| 231 | 231 | . 'lib/plugins/openlayersmap/toolbar/geojson_file.png" alt="GeoJSON file" /></td> |
| 232 | 232 | <td class="icon"><img src="' . DOKU_BASE |
| 233 | 233 | . 'lib/plugins/openlayersmap/toolbar/geojson_line.png" alt="' |
| 234 | - . $this->getlang('alt_legend_geojson') . '" /></td> |
|
| 235 | - <td class="txt" colspan="3">GeoJSON track: ' . $this->getFileName($gmap ['geojsonfile']) . '</td> |
|
| 234 | + . $this->getlang('alt_legend_geojson').'" /></td> |
|
| 235 | + <td class="txt" colspan="3">GeoJSON track: ' . $this->getFileName($gmap ['geojsonfile']).'</td> |
|
| 236 | 236 | </tr>'; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | $autozoom = empty ($gmap ['autozoom']) ? $this->getConf('autoZoomMap') : $gmap ['autozoom']; |
| 240 | - $js = "{mapOpts: {" . $param . ", displayformat: '" . $this->getConf('displayformat') |
|
| 241 | - . "', autozoom: " . $autozoom . "}, poi: [$poi]};"; |
|
| 240 | + $js = "{mapOpts: {".$param.", displayformat: '".$this->getConf('displayformat') |
|
| 241 | + . "', autozoom: ".$autozoom."}, poi: [$poi]};"; |
|
| 242 | 242 | // unescape the json |
| 243 | 243 | $poitable = stripslashes($poitable); |
| 244 | 244 | |
@@ -266,21 +266,21 @@ discard block |
||
| 266 | 266 | preg_match_all('/(\w*)="(.*?)"/us', $str_params, $param, PREG_SET_ORDER); |
| 267 | 267 | // parse match for instructions, break into key value pairs |
| 268 | 268 | $gmap = $this->dflt; |
| 269 | - foreach($gmap as $key => &$value) { |
|
| 270 | - $defval = $this->getConf('default_' . $key); |
|
| 271 | - if($defval !== '') { |
|
| 269 | + foreach ($gmap as $key => &$value) { |
|
| 270 | + $defval = $this->getConf('default_'.$key); |
|
| 271 | + if ($defval !== '') { |
|
| 272 | 272 | $value = $defval; |
| 273 | 273 | } |
| 274 | 274 | } |
| 275 | 275 | unset ($value); |
| 276 | - foreach($param as $kvpair) { |
|
| 276 | + foreach ($param as $kvpair) { |
|
| 277 | 277 | list ($match, $key, $val) = $kvpair; |
| 278 | 278 | $key = strtolower($key); |
| 279 | - if(isset ($gmap [$key])) { |
|
| 280 | - if($key == 'summary') { |
|
| 279 | + if (isset ($gmap [$key])) { |
|
| 280 | + if ($key == 'summary') { |
|
| 281 | 281 | // preserve case for summary field |
| 282 | 282 | $gmap [$key] = $val; |
| 283 | - } elseif($key == 'id') { |
|
| 283 | + } elseif ($key == 'id') { |
|
| 284 | 284 | // preserve case for id field |
| 285 | 285 | $gmap [$key] = $val; |
| 286 | 286 | } else { |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | ); |
| 311 | 311 | // create poi array |
| 312 | 312 | $overlay = array(); |
| 313 | - foreach($point as $pt) { |
|
| 313 | + foreach ($point as $pt) { |
|
| 314 | 314 | list ($match, $lat, $lon, $angle, $opacity, $img, $text) = $pt; |
| 315 | 315 | $lat = is_numeric($lat) ? $lat : 0; |
| 316 | 316 | $lon = is_numeric($lon) ? $lon : 0; |
@@ -344,10 +344,10 @@ discard block |
||
| 344 | 344 | */ |
| 345 | 345 | private function _getGoogle(array $gmap, array $overlay): string { |
| 346 | 346 | $sUrl = $this->getConf('iconUrlOverload'); |
| 347 | - if(!$sUrl) { |
|
| 347 | + if (!$sUrl) { |
|
| 348 | 348 | $sUrl = DOKU_URL; |
| 349 | 349 | } |
| 350 | - switch($gmap ['baselyr']) { |
|
| 350 | + switch ($gmap ['baselyr']) { |
|
| 351 | 351 | case 'google hybrid' : |
| 352 | 352 | $maptype = 'hybrid'; |
| 353 | 353 | break; |
@@ -367,29 +367,29 @@ discard block |
||
| 367 | 367 | // see: https://developers.google.com/maps/documentation/staticmaps/index#Viewports |
| 368 | 368 | // http://maps.google.com/maps/api/staticmap?center=51.565690,5.456756&zoom=16&size=600x400&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/marker.png|label:1|51.565690,5.456756&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/marker-blue.png|51.566197,5.458966|label:2&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/parking.png|51.567177,5.457909|label:3&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/parking.png|51.566283,5.457330|label:4&markers=icon:http://wild-water.nl/dokuwiki/lib/plugins/openlayersmap/icons/parking.png|51.565630,5.457695|label:5&sensor=false&format=png&maptype=roadmap |
| 369 | 369 | $imgUrl = "https://maps.googleapis.com/maps/api/staticmap?"; |
| 370 | - $imgUrl .= "&size=" . str_replace("px", "", $gmap ['width']) . "x" |
|
| 370 | + $imgUrl .= "&size=".str_replace("px", "", $gmap ['width'])."x" |
|
| 371 | 371 | . str_replace("px", "", $gmap ['height']); |
| 372 | 372 | //if (!$this->getConf( 'autoZoomMap')) { // no need for center & zoom params } |
| 373 | - $imgUrl .= "¢er=" . $gmap ['lat'] . "," . $gmap ['lon']; |
|
| 373 | + $imgUrl .= "¢er=".$gmap ['lat'].",".$gmap ['lon']; |
|
| 374 | 374 | // max is 21 (== building scale), but that's overkill.. |
| 375 | - if($gmap ['zoom'] > 17) { |
|
| 375 | + if ($gmap ['zoom'] > 17) { |
|
| 376 | 376 | $imgUrl .= "&zoom=17"; |
| 377 | 377 | } else { |
| 378 | - $imgUrl .= "&zoom=" . $gmap ['zoom']; |
|
| 378 | + $imgUrl .= "&zoom=".$gmap ['zoom']; |
|
| 379 | 379 | } |
| 380 | - if(!empty ($overlay)) { |
|
| 380 | + if (!empty ($overlay)) { |
|
| 381 | 381 | $rowId = 0; |
| 382 | - foreach($overlay as $data) { |
|
| 382 | + foreach ($overlay as $data) { |
|
| 383 | 383 | list ($lat, $lon, $text, $angle, $opacity, $img) = $data; |
| 384 | - $imgUrl .= "&markers=icon%3a" . $sUrl . "lib/plugins/openlayersmap/icons/" . $img . "%7c" |
|
| 385 | - . $lat . "," . $lon . "%7clabel%3a" . ++$rowId; |
|
| 384 | + $imgUrl .= "&markers=icon%3a".$sUrl."lib/plugins/openlayersmap/icons/".$img."%7c" |
|
| 385 | + . $lat.",".$lon."%7clabel%3a".++$rowId; |
|
| 386 | 386 | } |
| 387 | 387 | } |
| 388 | - $imgUrl .= "&format=png&maptype=" . $maptype; |
|
| 388 | + $imgUrl .= "&format=png&maptype=".$maptype; |
|
| 389 | 389 | global $conf; |
| 390 | - $imgUrl .= "&language=" . $conf ['lang']; |
|
| 391 | - if($this->getConf('googleAPIkey')) { |
|
| 392 | - $imgUrl .= "&key=" . $this->getConf('googleAPIkey'); |
|
| 390 | + $imgUrl .= "&language=".$conf ['lang']; |
|
| 391 | + if ($this->getConf('googleAPIkey')) { |
|
| 392 | + $imgUrl .= "&key=".$this->getConf('googleAPIkey'); |
|
| 393 | 393 | } |
| 394 | 394 | // dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::_getGoogle: Google image url is:'); |
| 395 | 395 | return $imgUrl; |
@@ -471,20 +471,20 @@ discard block |
||
| 471 | 471 | private function _getStaticOSM(array $gmap, array $overlay) { |
| 472 | 472 | global $conf; |
| 473 | 473 | |
| 474 | - if($this->getConf('optionStaticMapGenerator') == 'local') { |
|
| 474 | + if ($this->getConf('optionStaticMapGenerator') == 'local') { |
|
| 475 | 475 | // using local basemap composer |
| 476 | - if(!$myMap = plugin_load('helper', 'openlayersmap_staticmap')) { |
|
| 476 | + if (!$myMap = plugin_load('helper', 'openlayersmap_staticmap')) { |
|
| 477 | 477 | dbglog($myMap, 'syntax_plugin_openlayersmap_olmap::_getStaticOSM: openlayersmap_staticmap plugin is not available.'); |
| 478 | 478 | } |
| 479 | - if(!$geophp = plugin_load('helper', 'geophp')) { |
|
| 479 | + if (!$geophp = plugin_load('helper', 'geophp')) { |
|
| 480 | 480 | dbglog($geophp, 'syntax_plugin_openlayersmap_olmap::_getStaticOSM: geophp plugin is not available.'); |
| 481 | 481 | } |
| 482 | - $size = str_replace("px", "", $gmap ['width']) . "x" |
|
| 482 | + $size = str_replace("px", "", $gmap ['width'])."x" |
|
| 483 | 483 | . str_replace("px", "", $gmap ['height']); |
| 484 | 484 | |
| 485 | 485 | $markers = array(); |
| 486 | - if(!empty ($overlay)) { |
|
| 487 | - foreach($overlay as $data) { |
|
| 486 | + if (!empty ($overlay)) { |
|
| 487 | + foreach ($overlay as $data) { |
|
| 488 | 488 | list ($lat, $lon, $text, $angle, $opacity, $img) = $data; |
| 489 | 489 | $iconStyle = substr($img, 0, strlen($img) - 4); |
| 490 | 490 | $markers [] = array( |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | $apikey = ''; |
| 499 | - switch($gmap ['baselyr']) { |
|
| 499 | + switch ($gmap ['baselyr']) { |
|
| 500 | 500 | case 'mapnik' : |
| 501 | 501 | case 'openstreetmap' : |
| 502 | 502 | $maptype = 'openstreetmap'; |
@@ -540,25 +540,25 @@ discard block |
||
| 540 | 540 | // http://staticmap.openstreetmap.de/staticmap.php?center=47.000622235634,10.117187497601&zoom=5&size=500x350 |
| 541 | 541 | // &markers=48.999812532766,8.3593749976708,lightblue1|43.154850037315,17.499999997306,lightblue1|49.487527053077,10.820312497573,ltblu-pushpin|47.951071133739,15.917968747369,ol-marker|47.921629720114,18.027343747285,ol-marker-gold|47.951071133739,19.257812497236,ol-marker-blue|47.180141361692,19.257812497236,ol-marker-green |
| 542 | 542 | $imgUrl = "https://staticmap.openstreetmap.de/staticmap.php"; |
| 543 | - $imgUrl .= "?center=" . $gmap ['lat'] . "," . $gmap ['lon']; |
|
| 544 | - $imgUrl .= "&size=" . str_replace("px", "", $gmap ['width']) . "x" |
|
| 543 | + $imgUrl .= "?center=".$gmap ['lat'].",".$gmap ['lon']; |
|
| 544 | + $imgUrl .= "&size=".str_replace("px", "", $gmap ['width'])."x" |
|
| 545 | 545 | . str_replace("px", "", $gmap ['height']); |
| 546 | 546 | |
| 547 | - if($gmap ['zoom'] > 16) { |
|
| 547 | + if ($gmap ['zoom'] > 16) { |
|
| 548 | 548 | // actually this could even be 18, but that seems overkill |
| 549 | 549 | $imgUrl .= "&zoom=16"; |
| 550 | 550 | } else { |
| 551 | - $imgUrl .= "&zoom=" . $gmap ['zoom']; |
|
| 551 | + $imgUrl .= "&zoom=".$gmap ['zoom']; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | - if(!empty ($overlay)) { |
|
| 555 | - $rowId = 0; |
|
| 554 | + if (!empty ($overlay)) { |
|
| 555 | + $rowId = 0; |
|
| 556 | 556 | $imgUrl .= "&markers="; |
| 557 | - foreach($overlay as $data) { |
|
| 557 | + foreach ($overlay as $data) { |
|
| 558 | 558 | list ($lat, $lon, $text, $angle, $opacity, $img) = $data; |
| 559 | 559 | $rowId++; |
| 560 | 560 | $iconStyle = "lightblue$rowId"; |
| 561 | - $imgUrl .= "$lat,$lon,$iconStyle%7c"; |
|
| 561 | + $imgUrl .= "$lat,$lon,$iconStyle%7c"; |
|
| 562 | 562 | } |
| 563 | 563 | $imgUrl = substr($imgUrl, 0, -3); |
| 564 | 564 | } |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | * @return string |
| 578 | 578 | */ |
| 579 | 579 | private function _getBing(array $gmap, array $overlay): string { |
| 580 | - switch($gmap ['baselyr']) { |
|
| 580 | + switch ($gmap ['baselyr']) { |
|
| 581 | 581 | case 've hybrid' : |
| 582 | 582 | case 'bing hybrid' : |
| 583 | 583 | $maptype = 'AerialWithLabels'; |
@@ -594,30 +594,30 @@ discard block |
||
| 594 | 594 | $maptype = 'Road'; |
| 595 | 595 | break; |
| 596 | 596 | } |
| 597 | - $imgUrl = "https://dev.virtualearth.net/REST/v1/Imagery/Map/" . $maptype;// . "/"; |
|
| 598 | - if($this->getConf('autoZoomMap')) { |
|
| 597 | + $imgUrl = "https://dev.virtualearth.net/REST/v1/Imagery/Map/".$maptype; // . "/"; |
|
| 598 | + if ($this->getConf('autoZoomMap')) { |
|
| 599 | 599 | $bbox = $this->_calcBBOX($overlay, $gmap ['lat'], $gmap ['lon']); |
| 600 | 600 | //$imgUrl .= "?ma=" . $bbox ['minlat'] . "," . $bbox ['minlon'] . "," . $bbox ['maxlat'] . "," . $bbox ['maxlon']; |
| 601 | - $imgUrl .= "?ma=" . $bbox ['minlat'] . "%2C" . $bbox ['minlon'] . "%2C" . $bbox ['maxlat'] |
|
| 602 | - . "%2C" . $bbox ['maxlon']; |
|
| 601 | + $imgUrl .= "?ma=".$bbox ['minlat']."%2C".$bbox ['minlon']."%2C".$bbox ['maxlat'] |
|
| 602 | + . "%2C".$bbox ['maxlon']; |
|
| 603 | 603 | $imgUrl .= "&dcl=1"; |
| 604 | 604 | } |
| 605 | - if(strpos($imgUrl, "?") === false) |
|
| 605 | + if (strpos($imgUrl, "?") === false) |
|
| 606 | 606 | $imgUrl .= "?"; |
| 607 | 607 | |
| 608 | 608 | //$imgUrl .= "&ms=" . str_replace ( "px", "", $gmap ['width'] ) . "," . str_replace ( "px", "", $gmap ['height'] ); |
| 609 | - $imgUrl .= "&ms=" . str_replace("px", "", $gmap ['width']) . "%2C" |
|
| 609 | + $imgUrl .= "&ms=".str_replace("px", "", $gmap ['width'])."%2C" |
|
| 610 | 610 | . str_replace("px", "", $gmap ['height']); |
| 611 | - $imgUrl .= "&key=" . $this->getConf('bingAPIKey'); |
|
| 612 | - if(!empty ($overlay)) { |
|
| 611 | + $imgUrl .= "&key=".$this->getConf('bingAPIKey'); |
|
| 612 | + if (!empty ($overlay)) { |
|
| 613 | 613 | $rowId = 0; |
| 614 | - foreach($overlay as $data) { |
|
| 614 | + foreach ($overlay as $data) { |
|
| 615 | 615 | list ($lat, $lon, $text, $angle, $opacity, $img) = $data; |
| 616 | 616 | // TODO icon style lookup, see: http://msdn.microsoft.com/en-us/library/ff701719.aspx for iconStyle |
| 617 | 617 | $iconStyle = 32; |
| 618 | 618 | $rowId++; |
| 619 | 619 | // NOTE: the max number of pushpins is 18! or we have to use POST (http://msdn.microsoft.com/en-us/library/ff701724.aspx) |
| 620 | - if($rowId == 18) { |
|
| 620 | + if ($rowId == 18) { |
|
| 621 | 621 | break; |
| 622 | 622 | } |
| 623 | 623 | //$imgUrl .= "&pp=$lat,$lon;$iconStyle;$rowId"; |
@@ -627,7 +627,7 @@ discard block |
||
| 627 | 627 | } |
| 628 | 628 | global $conf; |
| 629 | 629 | $imgUrl .= "&fmt=png"; |
| 630 | - $imgUrl .= "&c=" . $conf ['lang']; |
|
| 630 | + $imgUrl .= "&c=".$conf ['lang']; |
|
| 631 | 631 | // dbglog($imgUrl,'syntax_plugin_openlayersmap_olmap::_getBing: bing image url is:'); |
| 632 | 632 | return $imgUrl; |
| 633 | 633 | } |
@@ -646,7 +646,7 @@ discard block |
||
| 646 | 646 | private function _calcBBOX(array $overlay, float $lat, float $lon): array { |
| 647 | 647 | $lats = array($lat); |
| 648 | 648 | $lons = array($lon); |
| 649 | - foreach($overlay as $data) { |
|
| 649 | + foreach ($overlay as $data) { |
|
| 650 | 650 | list ($lat, $lon, $text, $angle, $opacity, $img) = $data; |
| 651 | 651 | $lats [] = $lat; |
| 652 | 652 | $lons [] = $lon; |
@@ -674,13 +674,13 @@ discard block |
||
| 674 | 674 | * @todo move this into a shared library |
| 675 | 675 | */ |
| 676 | 676 | private function convertLat(float $decimaldegrees): string { |
| 677 | - if(strpos($decimaldegrees, '-') !== false) { |
|
| 677 | + if (strpos($decimaldegrees, '-') !== false) { |
|
| 678 | 678 | $latPos = "S"; |
| 679 | 679 | } else { |
| 680 | 680 | $latPos = "N"; |
| 681 | 681 | } |
| 682 | 682 | $dms = $this->_convertDDtoDMS(abs($decimaldegrees)); |
| 683 | - return hsc($dms . $latPos); |
|
| 683 | + return hsc($dms.$latPos); |
|
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | /** |
@@ -695,7 +695,7 @@ discard block |
||
| 695 | 695 | $secs = ($decimaldegrees - $dms) * 3600; |
| 696 | 696 | $min = floor($secs / 60); |
| 697 | 697 | $sec = round($secs - ($min * 60), 3); |
| 698 | - $dms .= 'º' . $min . '\'' . $sec . '"'; |
|
| 698 | + $dms .= 'º'.$min.'\''.$sec.'"'; |
|
| 699 | 699 | return $dms; |
| 700 | 700 | } |
| 701 | 701 | |
@@ -707,13 +707,13 @@ discard block |
||
| 707 | 707 | * @todo move this into a shared library |
| 708 | 708 | */ |
| 709 | 709 | private function convertLon(float $decimaldegrees): string { |
| 710 | - if(strpos($decimaldegrees, '-') !== false) { |
|
| 710 | + if (strpos($decimaldegrees, '-') !== false) { |
|
| 711 | 711 | $lonPos = "W"; |
| 712 | 712 | } else { |
| 713 | 713 | $lonPos = "E"; |
| 714 | 714 | } |
| 715 | 715 | $dms = $this->_convertDDtoDMS(abs($decimaldegrees)); |
| 716 | - return hsc($dms . $lonPos); |
|
| 716 | + return hsc($dms.$lonPos); |
|
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | /** |
@@ -744,7 +744,7 @@ discard block |
||
| 744 | 744 | // dbglog($data, 'olmap::render() data.'); |
| 745 | 745 | list ($mapid, $param, $mainLat, $mainLon, $poitable, $poitabledesc, $staticImgUrl, $_firstimage) = $data; |
| 746 | 746 | |
| 747 | - if($format == 'xhtml') { |
|
| 747 | + if ($format == 'xhtml') { |
|
| 748 | 748 | $olscript = ''; |
| 749 | 749 | $olEnable = false; |
| 750 | 750 | $gscript = ''; |
@@ -754,56 +754,56 @@ discard block |
||
| 754 | 754 | $enableBing = $this->getConf('enableBing'); |
| 755 | 755 | |
| 756 | 756 | $scriptEnable = ''; |
| 757 | - if(!$initialised) { |
|
| 757 | + if (!$initialised) { |
|
| 758 | 758 | $initialised = true; |
| 759 | 759 | // render necessary script tags |
| 760 | - if($gEnable) { |
|
| 760 | + if ($gEnable) { |
|
| 761 | 761 | $gscript = '<script charset="utf-8" defer="defer" src="//maps.google.com/maps/api/js?v=3.29&key=' |
| 762 | - . $this->getConf('googleAPIkey') . '"></script>'; |
|
| 762 | + . $this->getConf('googleAPIkey').'"></script>'; |
|
| 763 | 763 | } |
| 764 | - $olscript = '<script charset="utf-8" defer="defer" src="' . DOKU_BASE |
|
| 764 | + $olscript = '<script charset="utf-8" defer="defer" src="'.DOKU_BASE |
|
| 765 | 765 | . 'lib/plugins/openlayersmap/lib/OpenLayers.js"></script>'; |
| 766 | 766 | |
| 767 | 767 | $scriptEnable = '<script defer="defer" charset="utf-8" src="data:text/javascript;base64,'; |
| 768 | 768 | $scriptSrc = $olscript ? 'olEnable = true;' : 'olEnable = false;'; |
| 769 | - $scriptSrc .= 'gEnable = ' . ($gEnable ? 'true' : 'false') . ';'; |
|
| 770 | - $scriptSrc .= 'osmEnable = ' . ($osmEnable ? 'true' : 'false') . ';'; |
|
| 771 | - $scriptSrc .= 'stamenEnable = ' . ($stamenEnable ? 'true' : 'false') . ';'; |
|
| 772 | - $scriptSrc .= 'bEnable = ' . ($enableBing ? 'true' : 'false') . ';'; |
|
| 773 | - $scriptSrc .= 'bApiKey="' . $this->getConf('bingAPIKey') . '";'; |
|
| 774 | - $scriptSrc .= 'tfApiKey="' . $this->getConf('tfApiKey') . '";'; |
|
| 775 | - $scriptSrc .= 'gApiKey="' . $this->getConf('googleAPIkey') . '";'; |
|
| 769 | + $scriptSrc .= 'gEnable = '.($gEnable ? 'true' : 'false').';'; |
|
| 770 | + $scriptSrc .= 'osmEnable = '.($osmEnable ? 'true' : 'false').';'; |
|
| 771 | + $scriptSrc .= 'stamenEnable = '.($stamenEnable ? 'true' : 'false').';'; |
|
| 772 | + $scriptSrc .= 'bEnable = '.($enableBing ? 'true' : 'false').';'; |
|
| 773 | + $scriptSrc .= 'bApiKey="'.$this->getConf('bingAPIKey').'";'; |
|
| 774 | + $scriptSrc .= 'tfApiKey="'.$this->getConf('tfApiKey').'";'; |
|
| 775 | + $scriptSrc .= 'gApiKey="'.$this->getConf('googleAPIkey').'";'; |
|
| 776 | 776 | $scriptEnable .= base64_encode($scriptSrc); |
| 777 | 777 | $scriptEnable .= '"></script>'; |
| 778 | 778 | } |
| 779 | 779 | $renderer->doc .= "$gscript\n$olscript\n$scriptEnable"; |
| 780 | - $renderer->doc .= '<div class="olMapHelp">' . $this->locale_xhtml("help") . '</div>'; |
|
| 781 | - if($this->getConf('enableA11y')) { |
|
| 782 | - $renderer->doc .= '<div id="' . $mapid . '-static" class="olStaticMap">' |
|
| 783 | - . p_render($format, p_get_instructions($staticImgUrl), $info) . '</div>'; |
|
| 780 | + $renderer->doc .= '<div class="olMapHelp">'.$this->locale_xhtml("help").'</div>'; |
|
| 781 | + if ($this->getConf('enableA11y')) { |
|
| 782 | + $renderer->doc .= '<div id="'.$mapid.'-static" class="olStaticMap">' |
|
| 783 | + . p_render($format, p_get_instructions($staticImgUrl), $info).'</div>'; |
|
| 784 | 784 | } |
| 785 | - $renderer->doc .= '<div id="' . $mapid . '-clearer" class="clearer"><p> </p></div>'; |
|
| 786 | - if($this->getConf('enableA11y')) { |
|
| 785 | + $renderer->doc .= '<div id="'.$mapid.'-clearer" class="clearer"><p> </p></div>'; |
|
| 786 | + if ($this->getConf('enableA11y')) { |
|
| 787 | 787 | // render a table of the POI for the print and a11y presentation, it is hidden using javascript |
| 788 | - $renderer->doc .= '<div class="olPOItableSpan" id="' . $mapid . '-table-span"> |
|
| 789 | - <table class="olPOItable" id="' . $mapid . '-table"> |
|
| 790 | - <caption class="olPOITblCaption">' . $this->getLang('olmapPOItitle') . '</caption> |
|
| 788 | + $renderer->doc .= '<div class="olPOItableSpan" id="'.$mapid.'-table-span"> |
|
| 789 | + <table class="olPOItable" id="' . $mapid.'-table"> |
|
| 790 | + <caption class="olPOITblCaption">' . $this->getLang('olmapPOItitle').'</caption> |
|
| 791 | 791 | <thead class="olPOITblHeader"> |
| 792 | 792 | <tr> |
| 793 | 793 | <th class="rowId" scope="col">id</th> |
| 794 | - <th class="icon" scope="col">' . $this->getLang('olmapPOIicon') . '</th> |
|
| 795 | - <th class="lat" scope="col" title="' . $this->getLang('olmapPOIlatTitle') . '">' |
|
| 796 | - . $this->getLang('olmapPOIlat') . '</th> |
|
| 797 | - <th class="lon" scope="col" title="' . $this->getLang('olmapPOIlonTitle') . '">' |
|
| 798 | - . $this->getLang('olmapPOIlon') . '</th> |
|
| 799 | - <th class="txt" scope="col">' . $this->getLang('olmapPOItxt') . '</th> |
|
| 794 | + <th class="icon" scope="col">' . $this->getLang('olmapPOIicon').'</th> |
|
| 795 | + <th class="lat" scope="col" title="' . $this->getLang('olmapPOIlatTitle').'">' |
|
| 796 | + . $this->getLang('olmapPOIlat').'</th> |
|
| 797 | + <th class="lon" scope="col" title="' . $this->getLang('olmapPOIlonTitle').'">' |
|
| 798 | + . $this->getLang('olmapPOIlon').'</th> |
|
| 799 | + <th class="txt" scope="col">' . $this->getLang('olmapPOItxt').'</th> |
|
| 800 | 800 | </tr> |
| 801 | 801 | </thead>'; |
| 802 | - if($poitabledesc != '') { |
|
| 803 | - $renderer->doc .= '<tfoot class="olPOITblFooter"><tr><td colspan="5">' . $poitabledesc |
|
| 802 | + if ($poitabledesc != '') { |
|
| 803 | + $renderer->doc .= '<tfoot class="olPOITblFooter"><tr><td colspan="5">'.$poitabledesc |
|
| 804 | 804 | . '</td></tr></tfoot>'; |
| 805 | 805 | } |
| 806 | - $renderer->doc .= '<tbody class="olPOITblBody">' . $poitable . '</tbody> |
|
| 806 | + $renderer->doc .= '<tbody class="olPOITblBody">'.$poitable.'</tbody> |
|
| 807 | 807 | </table></div>'; |
| 808 | 808 | } |
| 809 | 809 | // render inline mapscript parts |
@@ -812,26 +812,26 @@ discard block |
||
| 812 | 812 | $renderer->doc .= '"></script>'; |
| 813 | 813 | $mapnumber++; |
| 814 | 814 | return true; |
| 815 | - } elseif($format == 'metadata') { |
|
| 816 | - if(!(($this->dflt ['lat'] == $mainLat) && ($this->dflt ['lon'] == $mainLon))) { |
|
| 815 | + } elseif ($format == 'metadata') { |
|
| 816 | + if (!(($this->dflt ['lat'] == $mainLat) && ($this->dflt ['lon'] == $mainLon))) { |
|
| 817 | 817 | // render geo metadata, unless they are the default |
| 818 | 818 | $renderer->meta ['geo'] ['lat'] = $mainLat; |
| 819 | 819 | $renderer->meta ['geo'] ['lon'] = $mainLon; |
| 820 | - if($geophp = plugin_load('helper', 'geophp')) { |
|
| 820 | + if ($geophp = plugin_load('helper', 'geophp')) { |
|
| 821 | 821 | // if we have the geoPHP helper, add the geohash |
| 822 | 822 | // fails with older php versions.. $renderer->meta['geo']['geohash'] = (new Point($mainLon,$mainLat))->out('geohash'); |
| 823 | - $p = new Point ($mainLon, $mainLat); |
|
| 823 | + $p = new Point($mainLon, $mainLat); |
|
| 824 | 824 | $renderer->meta ['geo'] ['geohash'] = $p->out('geohash'); |
| 825 | 825 | } |
| 826 | 826 | } |
| 827 | 827 | |
| 828 | - if(($this->getConf('enableA11y')) && (!empty ($_firstimage))) { |
|
| 828 | + if (($this->getConf('enableA11y')) && (!empty ($_firstimage))) { |
|
| 829 | 829 | // add map local image into relation/firstimage if not already filled and when it is a local image |
| 830 | 830 | |
| 831 | 831 | global $ID; |
| 832 | 832 | $rel = p_get_metadata($ID, 'relation', METADATA_RENDER_USING_CACHE); |
| 833 | 833 | $img = $rel ['firstimage']; |
| 834 | - if(empty ($img) /* || $img == $_firstimage*/) { |
|
| 834 | + if (empty ($img) /* || $img == $_firstimage*/) { |
|
| 835 | 835 | //dbglog ( $_firstimage, 'olmap::render#rendering image relation metadata for _firstimage as $img was empty or the same.' ); |
| 836 | 836 | // This seems to never work; the firstimage entry in the .meta file is empty |
| 837 | 837 | // $renderer->meta['relation']['firstimage'] = $_firstimage; |
@@ -602,8 +602,9 @@ |
||
| 602 | 602 | . "%2C" . $bbox ['maxlon']; |
| 603 | 603 | $imgUrl .= "&dcl=1"; |
| 604 | 604 | } |
| 605 | - if(strpos($imgUrl, "?") === false) |
|
| 606 | - $imgUrl .= "?"; |
|
| 605 | + if(strpos($imgUrl, "?") === false) { |
|
| 606 | + $imgUrl .= "?"; |
|
| 607 | + } |
|
| 607 | 608 | |
| 608 | 609 | //$imgUrl .= "&ms=" . str_replace ( "px", "", $gmap ['width'] ) . "," . str_replace ( "px", "", $gmap ['height'] ); |
| 609 | 610 | $imgUrl .= "&ms=" . str_replace("px", "", $gmap ['width']) . "%2C" |
@@ -42,9 +42,9 @@ |
||
| 42 | 42 | </head> |
| 43 | 43 | <body> |
| 44 | 44 | <div class="box"><?php |
| 45 | - foreach(glob('*.png') as $img) { |
|
| 46 | - echo '<img src="' . $img . '" alt="' . $img . '" title="' . $img . '" /> '; |
|
| 47 | - } |
|
| 48 | - ?></div> |
|
| 45 | + foreach(glob('*.png') as $img) { |
|
| 46 | + echo '<img src="' . $img . '" alt="' . $img . '" title="' . $img . '" /> '; |
|
| 47 | + } |
|
| 48 | + ?></div> |
|
| 49 | 49 | </body> |
| 50 | 50 | </html> |
@@ -42,8 +42,8 @@ |
||
| 42 | 42 | </head> |
| 43 | 43 | <body> |
| 44 | 44 | <div class="box"><?php |
| 45 | - foreach(glob('*.png') as $img) { |
|
| 46 | - echo '<img src="' . $img . '" alt="' . $img . '" title="' . $img . '" /> '; |
|
| 45 | + foreach (glob('*.png') as $img) { |
|
| 46 | + echo '<img src="'.$img.'" alt="'.$img.'" title="'.$img.'" /> '; |
|
| 47 | 47 | } |
| 48 | 48 | ?></div> |
| 49 | 49 | </body> |