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