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