Passed
Pull Request — master (#14)
by Mark
03:14 queued 16s
created
conf/metadata.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -22,72 +22,72 @@
 block discarded – undo
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
 );
Please login to merge, or discard this patch.
icons/index.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -42,9 +42,9 @@
 block discarded – undo
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>
Please login to merge, or discard this patch.
_test/general.test.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -24,42 +24,42 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
admin/purge.php 1 patch
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -24,101 +24,101 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
helper/staticmap.php 1 patch
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -24,125 +24,125 @@
 block discarded – undo
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'), $apikey
120
-        );
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'), $apikey
120
+		);
121 121
 
122
-        // return the media id url
123
-        // $mediaId = str_replace('/', ':', $map->getMap());
124
-        // if($this->startsWith($mediaId,':')) {
125
-        //     $mediaId = substr($mediaId, 1);
126
-        // }
127
-        // return $mediaId;
128
-        return str_replace('/', ':', $map->getMap());
129
-    }
122
+		// return the media id url
123
+		// $mediaId = str_replace('/', ':', $map->getMap());
124
+		// if($this->startsWith($mediaId,':')) {
125
+		//     $mediaId = substr($mediaId, 1);
126
+		// }
127
+		// return $mediaId;
128
+		return str_replace('/', ':', $map->getMap());
129
+	}
130 130
 
131
-    /**
132
-     * Constructs the path to a file.
133
-     * @param string $id the DW media id
134
-     * @return string the path to the file
135
-     */
136
-    private function mediaIdToPath(string $id): string {
137
-        global $conf;
138
-        if(empty($id)) {
139
-            return "";
140
-        }
141
-        $id = str_replace(array("[[", "]]"), "", $id);
142
-        if((strpos($id, ':') === 0)) {
143
-            $id = substr($id, 1);
144
-        }
145
-        $id = str_replace(":", "/", $id);
146
-        return $conf['mediadir'] . '/' . $id;
147
-    }
131
+	/**
132
+	 * Constructs the path to a file.
133
+	 * @param string $id the DW media id
134
+	 * @return string the path to the file
135
+	 */
136
+	private function mediaIdToPath(string $id): string {
137
+		global $conf;
138
+		if(empty($id)) {
139
+			return "";
140
+		}
141
+		$id = str_replace(array("[[", "]]"), "", $id);
142
+		if((strpos($id, ':') === 0)) {
143
+			$id = substr($id, 1);
144
+		}
145
+		$id = str_replace(":", "/", $id);
146
+		return $conf['mediadir'] . '/' . $id;
147
+	}
148 148
 }
Please login to merge, or discard this patch.
StaticMap.php 1 patch
Indentation   +836 added lines, -836 removed lines patch added patch discarded remove patch
@@ -31,840 +31,840 @@
 block discarded – undo
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 data/ODbl',
40
-            'logo' => 'osm_logo.png',
41
-            'url'  => 'https://tile.openstreetmap.org/{Z}/{X}/{Y}.png'
42
-        ),
43
-        // OCM sources
44
-        'cycle'         => array(
45
-            'txt'  => '(c) Thunderforest maps',
46
-            'logo' => 'tf_logo.png',
47
-            'url'  => 'https://tile.thunderforest.com/cycle/{Z}/{X}/{Y}.png'
48
-        ),
49
-        'transport'     => array(
50
-            'txt'  => '(c) Thunderforest maps',
51
-            'logo' => 'tf_logo.png',
52
-            'url'  => 'https://tile.thunderforest.com/transport/{Z}/{X}/{Y}.png'
53
-        ),
54
-        'landscape'     => array(
55
-            'txt'  => '(c) Thunderforest maps',
56
-            'logo' => 'tf_logo.png',
57
-            'url'  => 'https://tile.thunderforest.com/landscape/{Z}/{X}/{Y}.png'
58
-        ),
59
-        'outdoors'      => array(
60
-            'txt'  => '(c) Thunderforest maps',
61
-            'logo' => 'tf_logo.png',
62
-            'url'  => 'https://tile.thunderforest.com/outdoors/{Z}/{X}/{Y}.png'
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;
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 $geojson
177
-     * @param string $mediaDir
178
-     *            Directory to store/cache maps
179
-     * @param string $tileCacheBaseDir
180
-     *            Directory to cache map tiles
181
-     * @param bool   $autoZoomExtent
182
-     *            Wheter or not to override zoom/lat/lon and zoom to the extent of gpx/kml and markers
183
-     * @param string $apikey
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 = $this->mapCacheIDToFilename();
245
-        // make url relative to media dir
246
-        return str_replace($this->mediaBaseDir, '', $doc);
247
-    }
248
-
249
-    /**
250
-     * Calculate the lat/lon/zoom values to make sure that all of the markers and gpx/kml are on the map.
251
-     * can throw an error like
252
-     * "Fatal error: Uncaught Exception: Cannot create a collection with non-geometries in
253
-     * D:\www\wild-water.nl\www\dokuwiki\lib\plugins\geophp\geoPHP\lib\geometry\Collection.class.php:29"
254
-     *
255
-     * @param float $paddingFactor
256
-     *            buffer constant to enlarge (>1.0) the zoom level
257
-     * @throws Exception
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
-        if(file_exists($this->kmlFileName)) {
268
-            $g = geoPHP::load(file_get_contents($this->kmlFileName), 'kml');
269
-            if($g !== false) {
270
-                $geoms [] = $g;
271
-            }
272
-        }
273
-        if(file_exists($this->gpxFileName)) {
274
-            $g = geoPHP::load(file_get_contents($this->gpxFileName), 'gpx');
275
-            if($g !== false) {
276
-                $geoms [] = $g;
277
-            }
278
-        }
279
-        if(file_exists($this->geojsonFileName)) {
280
-            $g = geoPHP::load(file_get_contents($this->geojsonFileName), 'geojson');
281
-            if($g !== false) {
282
-                $geoms [] = $g;
283
-            }
284
-        }
285
-
286
-        if(count($geoms) <= 1) {
287
-            dbglog($geoms, "StaticMap::autoZoom: Skip setting autozoom options");
288
-            return;
289
-        }
290
-
291
-        $geom     = new GeometryCollection ($geoms);
292
-        $centroid = $geom->centroid();
293
-        $bbox     = $geom->getBBox();
294
-
295
-        // determine vertical resolution, this depends on the distance from the equator
296
-        // $vy00 = log(tan(M_PI*(0.25 + $centroid->getY()/360)));
297
-        $vy0 = log(tan(M_PI * (0.25 + $bbox ['miny'] / 360)));
298
-        $vy1 = log(tan(M_PI * (0.25 + $bbox ['maxy'] / 360)));
299
-        dbglog("StaticMap::autoZoom: vertical resolution: $vy0, $vy1");
300
-        $zoomFactorPowered  = ($this->height / 2) / (40.7436654315252 * ($vy1 - $vy0));
301
-        $resolutionVertical = 360 / ($zoomFactorPowered * $this->tileSize);
302
-        // determine horizontal resolution
303
-        $resolutionHorizontal = ($bbox ['maxx'] - $bbox ['minx']) / $this->width;
304
-        $resolution           = max($resolutionHorizontal, $resolutionVertical) * $paddingFactor;
305
-        $zoom                 = log(360 / ($resolution * $this->tileSize), 2);
306
-
307
-        if(is_finite($zoom) && $zoom < 15 && $zoom > 2) {
308
-            $this->zoom = floor($zoom);
309
-        }
310
-        $this->lon = $centroid->getX();
311
-        $this->lat = $centroid->getY();
312
-        dbglog("StaticMap::autoZoom: Set autozoom options to: z: $this->zoom, lon: $this->lon, lat: $this->lat");
313
-    }
314
-
315
-    public function checkMapCache(): bool {
316
-        // side effect: set the mapCacheID
317
-        $this->mapCacheID = md5($this->serializeParams());
318
-        $filename         = $this->mapCacheIDToFilename();
319
-        return file_exists($filename);
320
-    }
321
-
322
-    public function serializeParams(): string {
323
-        return join(
324
-            "&", array(
325
-                   $this->zoom,
326
-                   $this->lat,
327
-                   $this->lon,
328
-                   $this->width,
329
-                   $this->height,
330
-                   serialize($this->markers),
331
-                   $this->maptype,
332
-                   $this->kmlFileName,
333
-                   $this->gpxFileName,
334
-                   $this->geojsonFileName
335
-               )
336
-        );
337
-    }
338
-
339
-    public function mapCacheIDToFilename(): string {
340
-        if(!$this->mapCacheFile) {
341
-            $this->mapCacheFile = $this->mapCacheBaseDir . "/" . $this->maptype . "/" . $this->zoom . "/cache_"
342
-                . substr($this->mapCacheID, 0, 2) . "/" . substr($this->mapCacheID, 2, 2)
343
-                . "/" . substr($this->mapCacheID, 4);
344
-        }
345
-        return $this->mapCacheFile . "." . $this->mapCacheExtension;
346
-    }
347
-
348
-    /**
349
-     * make the map.
350
-     */
351
-    public function makeMap(): void {
352
-        $this->initCoords();
353
-        $this->createBaseMap();
354
-        if(!empty ($this->markers))
355
-            $this->placeMarkers();
356
-        if(file_exists($this->kmlFileName))
357
-            $this->drawKML();
358
-        if(file_exists($this->gpxFileName))
359
-            $this->drawGPX();
360
-        if(file_exists($this->geojsonFileName))
361
-            $this->drawGeojson();
362
-
363
-        $this->drawCopyright();
364
-    }
365
-
366
-    /**
367
-     */
368
-    public function initCoords(): void {
369
-        $this->centerX = $this->lonToTile($this->lon, $this->zoom);
370
-        $this->centerY = $this->latToTile($this->lat, $this->zoom);
371
-        $this->offsetX = floor((floor($this->centerX) - $this->centerX) * $this->tileSize);
372
-        $this->offsetY = floor((floor($this->centerY) - $this->centerY) * $this->tileSize);
373
-    }
374
-
375
-    /**
376
-     *
377
-     * @param float $long
378
-     * @param int   $zoom
379
-     * @return float|int
380
-     */
381
-    public function lonToTile(float $long, int $zoom) {
382
-        return (($long + 180) / 360) * pow(2, $zoom);
383
-    }
384
-
385
-    /**
386
-     *
387
-     * @param float $lat
388
-     * @param int   $zoom
389
-     * @return float|int
390
-     */
391
-    public function latToTile(float $lat, int $zoom) {
392
-        return (1 - log(tan($lat * pi() / 180) + 1 / cos($lat * M_PI / 180)) / M_PI) / 2 * pow(2, $zoom);
393
-    }
394
-
395
-    /**
396
-     * make basemap image.
397
-     */
398
-    public function createBaseMap(): void {
399
-        $this->image   = imagecreatetruecolor($this->width, $this->height);
400
-        $startX        = floor($this->centerX - ($this->width / $this->tileSize) / 2);
401
-        $startY        = floor($this->centerY - ($this->height / $this->tileSize) / 2);
402
-        $endX          = ceil($this->centerX + ($this->width / $this->tileSize) / 2);
403
-        $endY          = ceil($this->centerY + ($this->height / $this->tileSize) / 2);
404
-        $this->offsetX = -floor(($this->centerX - floor($this->centerX)) * $this->tileSize);
405
-        $this->offsetY = -floor(($this->centerY - floor($this->centerY)) * $this->tileSize);
406
-        $this->offsetX += floor($this->width / 2);
407
-        $this->offsetY += floor($this->height / 2);
408
-        $this->offsetX += floor($startX - floor($this->centerX)) * $this->tileSize;
409
-        $this->offsetY += floor($startY - floor($this->centerY)) * $this->tileSize;
410
-
411
-        for($x = $startX; $x <= $endX; $x++) {
412
-            for($y = $startY; $y <= $endY; $y++) {
413
-                $url = str_replace(
414
-                    array(
415
-                        '{Z}',
416
-                        '{X}',
417
-                        '{Y}'
418
-                    ), array(
419
-                        $this->zoom,
420
-                        $x,
421
-                        $y
422
-                    ), $this->tileInfo [$this->maptype] ['url']
423
-                );
424
-
425
-                $tileData = $this->fetchTile($url);
426
-                if($tileData) {
427
-                    $tileImage = imagecreatefromstring($tileData);
428
-                } else {
429
-                    $tileImage = imagecreate($this->tileSize, $this->tileSize);
430
-                    $color     = imagecolorallocate($tileImage, 255, 255, 255);
431
-                    @imagestring($tileImage, 1, 127, 127, 'err', $color);
432
-                }
433
-                $destX = ($x - $startX) * $this->tileSize + $this->offsetX;
434
-                $destY = ($y - $startY) * $this->tileSize + $this->offsetY;
435
-                dbglog($this->tileSize, "imagecopy tile into image: $destX, $destY");
436
-                imagecopy(
437
-                    $this->image, $tileImage, $destX, $destY, 0, 0, $this->tileSize,
438
-                    $this->tileSize
439
-                );
440
-            }
441
-        }
442
-    }
443
-
444
-    /**
445
-     * Fetch a tile and (if configured) store it in the cache.
446
-     * @param string $url
447
-     * @return bool|string
448
-     * @todo refactor this to use dokuwiki\HTTP\HTTPClient or dokuwiki\HTTP\DokuHTTPClient
449
-     *          for better proxy handling...
450
-     */
451
-    public function fetchTile(string $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 . $this->apikey);
463
-            dbglog("StaticMap::fetchTile: getting: $url using curl_exec");
464
-            $tile = curl_exec($ch);
465
-            curl_close($ch);
466
-        } else {
467
-            // use file_get_contents
468
-            global $conf;
469
-            $opts = array(
470
-                'http' => array(
471
-                    'method'          => "GET",
472
-                    'header'          => "Accept-language: en\r\n" . "User-Agent: $_UA\r\n" . "accept: image/png\r\n",
473
-                    'request_fulluri' => true
474
-                )
475
-            );
476
-            if(isset($conf['proxy']['host'], $conf['proxy']['port'])
477
-                && $conf['proxy']['host'] !== ''
478
-                && $conf['proxy']['port'] !== '') {
479
-                $opts['http'] += ['proxy' => "tcp://" . $conf['proxy']['host'] . ":" . $conf['proxy']['port']];
480
-            }
481
-
482
-            $context = stream_context_create($opts);
483
-            dbglog("StaticMap::fetchTile: getting: $url . $this->apikey using file_get_contents and options $opts");
484
-            $tile = file_get_contents($url . $this->apikey, false, $context);
485
-        }
486
-        if($tile && $this->useTileCache) {
487
-            $this->writeTileToCache($url, $tile);
488
-        }
489
-        return $tile;
490
-    }
491
-
492
-    /**
493
-     *
494
-     * @param string $url
495
-     * @return string|false
496
-     */
497
-    public function checkTileCache(string $url) {
498
-        $filename = $this->tileUrlToFilename($url);
499
-        if(file_exists($filename)) {
500
-            return file_get_contents($filename);
501
-        }
502
-        return false;
503
-    }
504
-
505
-    /**
506
-     *
507
-     * @param string $url
508
-     * @return string
509
-     */
510
-    public function tileUrlToFilename(string $url): string {
511
-        return $this->tileCacheBaseDir . "/" . substr($url, strpos($url, '/') + 1);
512
-    }
513
-
514
-    /**
515
-     * Write a tile into the cache.
516
-     *
517
-     * @param string $url
518
-     * @param mixed  $data
519
-     */
520
-    public function writeTileToCache($url, $data): void {
521
-        $filename = $this->tileUrlToFilename($url);
522
-        $this->mkdirRecursive(dirname($filename), 0777);
523
-        file_put_contents($filename, $data);
524
-    }
525
-
526
-    /**
527
-     * Recursively create the directory.
528
-     *
529
-     * @param string $pathname
530
-     *            The directory path.
531
-     * @param int    $mode
532
-     *            File access mode. For more information on modes, read the details on the chmod manpage.
533
-     */
534
-    public function mkdirRecursive(string $pathname, int $mode): bool {
535
-        is_dir(dirname($pathname)) || $this->mkdirRecursive(dirname($pathname), $mode);
536
-        return is_dir($pathname) || mkdir($pathname, $mode) || is_dir($pathname);
537
-    }
538
-
539
-    /**
540
-     * Place markers on the map and number them in the same order as they are listed in the html.
541
-     */
542
-    public function placeMarkers(): void {
543
-        $count         = 0;
544
-        $color         = imagecolorallocate($this->image, 0, 0, 0);
545
-        $bgcolor       = imagecolorallocate($this->image, 200, 200, 200);
546
-        $markerBaseDir = __DIR__ . '/icons';
547
-        // loop thru marker array
548
-        foreach($this->markers as $marker) {
549
-            // set some local variables
550
-            $markerLat  = $marker ['lat'];
551
-            $markerLon  = $marker ['lon'];
552
-            $markerType = $marker ['type'];
553
-            // clear variables from previous loops
554
-            $markerFilename = '';
555
-            $markerShadow   = '';
556
-            $matches        = false;
557
-            // check for marker type, get settings from markerPrototypes
558
-            if($markerType) {
559
-                foreach($this->markerPrototypes as $markerPrototype) {
560
-                    if(preg_match($markerPrototype ['regex'], $markerType, $matches)) {
561
-                        $markerFilename = $matches [0] . $markerPrototype ['extension'];
562
-                        if($markerPrototype ['offsetImage']) {
563
-                            list ($markerImageOffsetX, $markerImageOffsetY) = explode(
564
-                                ",",
565
-                                $markerPrototype ['offsetImage']
566
-                            );
567
-                        }
568
-                        $markerShadow = $markerPrototype ['shadow'];
569
-                        if($markerShadow) {
570
-                            list ($markerShadowOffsetX, $markerShadowOffsetY) = explode(
571
-                                ",",
572
-                                $markerPrototype ['offsetShadow']
573
-                            );
574
-                        }
575
-                    }
576
-                }
577
-            }
578
-            // create img resource
579
-            if(file_exists($markerBaseDir . '/' . $markerFilename)) {
580
-                $markerImg = imagecreatefrompng($markerBaseDir . '/' . $markerFilename);
581
-            } else {
582
-                $markerImg = imagecreatefrompng($markerBaseDir . '/marker.png');
583
-            }
584
-            // check for shadow + create shadow recource
585
-            if($markerShadow && file_exists($markerBaseDir . '/' . $markerShadow)) {
586
-                $markerShadowImg = imagecreatefrompng($markerBaseDir . '/' . $markerShadow);
587
-            }
588
-            // calc position
589
-            $destX = floor(
590
-                ($this->width / 2) -
591
-                $this->tileSize * ($this->centerX - $this->lonToTile($markerLon, $this->zoom))
592
-            );
593
-            $destY = floor(
594
-                ($this->height / 2) -
595
-                $this->tileSize * ($this->centerY - $this->latToTile($markerLat, $this->zoom))
596
-            );
597
-            // copy shadow on basemap
598
-            if($markerShadow && $markerShadowImg) {
599
-                imagecopy(
600
-                    $this->image,
601
-                    $markerShadowImg,
602
-                    $destX + (int) $markerShadowOffsetX,
603
-                    $destY + (int) $markerShadowOffsetY,
604
-                    0,
605
-                    0,
606
-                    imagesx($markerShadowImg),
607
-                    imagesy($markerShadowImg)
608
-                );
609
-            }
610
-            // copy marker on basemap above shadow
611
-            imagecopy(
612
-                $this->image,
613
-                $markerImg,
614
-                $destX + (int) $markerImageOffsetX,
615
-                $destY + (int) $markerImageOffsetY,
616
-                0,
617
-                0,
618
-                imagesx($markerImg),
619
-                imagesy($markerImg)
620
-            );
621
-            // add label
622
-            imagestring(
623
-                $this->image,
624
-                3,
625
-                $destX - imagesx($markerImg) + 1,
626
-                $destY + (int) $markerImageOffsetY + 1,
627
-                ++$count,
628
-                $bgcolor
629
-            );
630
-            imagestring(
631
-                $this->image,
632
-                3,
633
-                $destX - imagesx($markerImg),
634
-                $destY + (int) $markerImageOffsetY,
635
-                $count,
636
-                $color
637
-            );
638
-        }
639
-    }
640
-
641
-    /**
642
-     * Draw kml trace on the map.
643
-     */
644
-    public function drawKML(): void {
645
-        // TODO get colour from kml node (not currently supported in geoPHP)
646
-        $col     = imagecolorallocatealpha($this->image, 255, 0, 0, .4 * 127);
647
-        $kmlgeom = geoPHP::load(file_get_contents($this->kmlFileName), 'kml');
648
-        $this->drawGeometry($kmlgeom, $col);
649
-    }
650
-
651
-    /**
652
-     * Draw geometry or geometry collection on the map.
653
-     *
654
-     * @param Geometry $geom
655
-     * @param int      $colour
656
-     *            drawing colour
657
-     */
658
-    private function drawGeometry(Geometry $geom, int $colour): void {
659
-        if(empty($geom)) {
660
-            return;
661
-        }
662
-
663
-        switch($geom->geometryType()) {
664
-            case 'GeometryCollection' :
665
-                // recursively draw part of the collection
666
-                for($i = 1; $i < $geom->numGeometries() + 1; $i++) {
667
-                    $_geom = $geom->geometryN($i);
668
-                    $this->drawGeometry($_geom, $colour);
669
-                }
670
-                break;
671
-            case 'MultiPolygon' :
672
-            case 'MultiLineString' :
673
-            case 'MultiPoint' :
674
-                // TODO implement / do nothing
675
-                break;
676
-            case 'Polygon' :
677
-                $this->drawPolygon($geom, $colour);
678
-                break;
679
-            case 'LineString' :
680
-                $this->drawLineString($geom, $colour);
681
-                break;
682
-            case 'Point' :
683
-                $this->drawPoint($geom, $colour);
684
-                break;
685
-            default :
686
-                // draw nothing
687
-                break;
688
-        }
689
-    }
690
-
691
-    /**
692
-     * Draw a polygon on the map.
693
-     *
694
-     * @param Polygon $polygon
695
-     * @param int     $colour
696
-     *            drawing colour
697
-     */
698
-    private function drawPolygon($polygon, int $colour) {
699
-        // TODO implementation of drawing holes,
700
-        // maybe draw the polygon to an in-memory image and use imagecopy, draw polygon in col., draw holes in bgcol?
701
-
702
-        // print_r('Polygon:<br />');
703
-        // print_r($polygon);
704
-        $extPoints = array();
705
-        // extring is a linestring actually..
706
-        $extRing = $polygon->exteriorRing();
707
-
708
-        for($i = 1; $i < $extRing->numGeometries(); $i++) {
709
-            $p1           = $extRing->geometryN($i);
710
-            $x            = floor(
711
-                ($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))
712
-            );
713
-            $y            = floor(
714
-                ($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p1->y(), $this->zoom))
715
-            );
716
-            $extPoints [] = $x;
717
-            $extPoints [] = $y;
718
-        }
719
-        // print_r('points:('.($i-1).')<br />');
720
-        // print_r($extPoints);
721
-        // imagepolygon ($this->image, $extPoints, $i-1, $colour );
722
-        imagefilledpolygon($this->image, $extPoints, $i - 1, $colour);
723
-    }
724
-
725
-    /**
726
-     * Draw a line on the map.
727
-     *
728
-     * @param LineString $line
729
-     * @param int        $colour
730
-     *            drawing colour
731
-     */
732
-    private function drawLineString($line, $colour) {
733
-        imagesetthickness($this->image, 2);
734
-        for($p = 1; $p < $line->numGeometries(); $p++) {
735
-            // get first pair of points
736
-            $p1 = $line->geometryN($p);
737
-            $p2 = $line->geometryN($p + 1);
738
-            // translate to paper space
739
-            $x1 = floor(
740
-                ($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))
741
-            );
742
-            $y1 = floor(
743
-                ($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p1->y(), $this->zoom))
744
-            );
745
-            $x2 = floor(
746
-                ($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p2->x(), $this->zoom))
747
-            );
748
-            $y2 = floor(
749
-                ($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p2->y(), $this->zoom))
750
-            );
751
-            // draw to image
752
-            imageline($this->image, $x1, $y1, $x2, $y2, $colour);
753
-        }
754
-        imagesetthickness($this->image, 1);
755
-    }
756
-
757
-    /**
758
-     * Draw a point on the map.
759
-     *
760
-     * @param Point $point
761
-     * @param int   $colour
762
-     *            drawing colour
763
-     */
764
-    private function drawPoint($point, $colour) {
765
-        imagesetthickness($this->image, 2);
766
-        // translate to paper space
767
-        $cx = floor(
768
-            ($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($point->x(), $this->zoom))
769
-        );
770
-        $cy = floor(
771
-            ($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($point->y(), $this->zoom))
772
-        );
773
-        $r  = 5;
774
-        // draw to image
775
-        // imageellipse($this->image, $cx, $cy,$r, $r, $colour);
776
-        imagefilledellipse($this->image, $cx, $cy, $r, $r, $colour);
777
-        // don't use imageellipse because the imagesetthickness function has
778
-        // no effect. So the better workaround is to use imagearc.
779
-        imagearc($this->image, $cx, $cy, $r, $r, 0, 359, $colour);
780
-        imagesetthickness($this->image, 1);
781
-    }
782
-
783
-    /**
784
-     * Draw gpx trace on the map.
785
-     */
786
-    public function drawGPX() {
787
-        $col     = imagecolorallocatealpha($this->image, 0, 0, 255, .4 * 127);
788
-        $gpxgeom = geoPHP::load(file_get_contents($this->gpxFileName), 'gpx');
789
-        $this->drawGeometry($gpxgeom, $col);
790
-    }
791
-
792
-    /**
793
-     * Draw geojson on the map.
794
-     */
795
-    public function drawGeojson() {
796
-        $col     = imagecolorallocatealpha($this->image, 255, 0, 255, .4 * 127);
797
-        $gpxgeom = geoPHP::load(file_get_contents($this->geojsonFileName), 'json');
798
-        $this->drawGeometry($gpxgeom, $col);
799
-    }
800
-
801
-    /**
802
-     * add copyright and origin notice and icons to the map.
803
-     */
804
-    public function drawCopyright() {
805
-        $logoBaseDir = dirname(__FILE__) . '/' . 'logo/';
806
-        $logoImg     = imagecreatefrompng($logoBaseDir . $this->tileInfo ['openstreetmap'] ['logo']);
807
-        $textcolor   = imagecolorallocate($this->image, 0, 0, 0);
808
-        $bgcolor     = imagecolorallocate($this->image, 200, 200, 200);
809
-
810
-        imagecopy(
811
-            $this->image,
812
-            $logoImg,
813
-            0,
814
-            imagesy($this->image) - imagesy($logoImg),
815
-            0,
816
-            0,
817
-            imagesx($logoImg),
818
-            imagesy($logoImg)
819
-        );
820
-        imagestring(
821
-            $this->image,
822
-            1,
823
-            imagesx($logoImg) + 2,
824
-            imagesy($this->image) - imagesy($logoImg) + 1,
825
-            $this->tileInfo ['openstreetmap'] ['txt'],
826
-            $bgcolor
827
-        );
828
-        imagestring(
829
-            $this->image,
830
-            1,
831
-            imagesx($logoImg) + 1,
832
-            imagesy($this->image) - imagesy($logoImg),
833
-            $this->tileInfo ['openstreetmap'] ['txt'],
834
-            $textcolor
835
-        );
836
-
837
-        // additional tile source info, ie. who created/hosted the tiles
838
-        $xIconOffset = 0;
839
-        if($this->maptype === 'openstreetmap') {
840
-            $mapAuthor = "(c) OpenStreetMap maps/CC BY-SA";
841
-        } else {
842
-            $mapAuthor   = $this->tileInfo [$this->maptype] ['txt'];
843
-            $iconImg     = imagecreatefrompng($logoBaseDir . $this->tileInfo [$this->maptype] ['logo']);
844
-            $xIconOffset = imagesx($iconImg);
845
-            imagecopy(
846
-                $this->image,
847
-                $iconImg, imagesx($logoImg) + 1,
848
-                imagesy($this->image) - imagesy($iconImg),
849
-                0,
850
-                0,
851
-                imagesx($iconImg), imagesy($iconImg)
852
-            );
853
-        }
854
-        imagestring(
855
-            $this->image,
856
-            1, imagesx($logoImg) + $xIconOffset + 4,
857
-            imagesy($this->image) - ceil(imagesy($logoImg) / 2) + 1,
858
-            $mapAuthor,
859
-            $bgcolor
860
-        );
861
-        imagestring(
862
-            $this->image,
863
-            1, imagesx($logoImg) + $xIconOffset + 3,
864
-            imagesy($this->image) - ceil(imagesy($logoImg) / 2),
865
-            $mapAuthor,
866
-            $textcolor
867
-        );
868
-
869
-    }
34
+	// the final output
35
+	private $tileSize = 256;
36
+	private $tileInfo = array(
37
+		// OSM sources
38
+		'openstreetmap' => array(
39
+			'txt'  => '(c) OpenStreetMap data/ODbl',
40
+			'logo' => 'osm_logo.png',
41
+			'url'  => 'https://tile.openstreetmap.org/{Z}/{X}/{Y}.png'
42
+		),
43
+		// OCM sources
44
+		'cycle'         => array(
45
+			'txt'  => '(c) Thunderforest maps',
46
+			'logo' => 'tf_logo.png',
47
+			'url'  => 'https://tile.thunderforest.com/cycle/{Z}/{X}/{Y}.png'
48
+		),
49
+		'transport'     => array(
50
+			'txt'  => '(c) Thunderforest maps',
51
+			'logo' => 'tf_logo.png',
52
+			'url'  => 'https://tile.thunderforest.com/transport/{Z}/{X}/{Y}.png'
53
+		),
54
+		'landscape'     => array(
55
+			'txt'  => '(c) Thunderforest maps',
56
+			'logo' => 'tf_logo.png',
57
+			'url'  => 'https://tile.thunderforest.com/landscape/{Z}/{X}/{Y}.png'
58
+		),
59
+		'outdoors'      => array(
60
+			'txt'  => '(c) Thunderforest maps',
61
+			'logo' => 'tf_logo.png',
62
+			'url'  => 'https://tile.thunderforest.com/outdoors/{Z}/{X}/{Y}.png'
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;
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 $geojson
177
+	 * @param string $mediaDir
178
+	 *            Directory to store/cache maps
179
+	 * @param string $tileCacheBaseDir
180
+	 *            Directory to cache map tiles
181
+	 * @param bool   $autoZoomExtent
182
+	 *            Wheter or not to override zoom/lat/lon and zoom to the extent of gpx/kml and markers
183
+	 * @param string $apikey
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 = $this->mapCacheIDToFilename();
245
+		// make url relative to media dir
246
+		return str_replace($this->mediaBaseDir, '', $doc);
247
+	}
248
+
249
+	/**
250
+	 * Calculate the lat/lon/zoom values to make sure that all of the markers and gpx/kml are on the map.
251
+	 * can throw an error like
252
+	 * "Fatal error: Uncaught Exception: Cannot create a collection with non-geometries in
253
+	 * D:\www\wild-water.nl\www\dokuwiki\lib\plugins\geophp\geoPHP\lib\geometry\Collection.class.php:29"
254
+	 *
255
+	 * @param float $paddingFactor
256
+	 *            buffer constant to enlarge (>1.0) the zoom level
257
+	 * @throws Exception
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
+		if(file_exists($this->kmlFileName)) {
268
+			$g = geoPHP::load(file_get_contents($this->kmlFileName), 'kml');
269
+			if($g !== false) {
270
+				$geoms [] = $g;
271
+			}
272
+		}
273
+		if(file_exists($this->gpxFileName)) {
274
+			$g = geoPHP::load(file_get_contents($this->gpxFileName), 'gpx');
275
+			if($g !== false) {
276
+				$geoms [] = $g;
277
+			}
278
+		}
279
+		if(file_exists($this->geojsonFileName)) {
280
+			$g = geoPHP::load(file_get_contents($this->geojsonFileName), 'geojson');
281
+			if($g !== false) {
282
+				$geoms [] = $g;
283
+			}
284
+		}
285
+
286
+		if(count($geoms) <= 1) {
287
+			dbglog($geoms, "StaticMap::autoZoom: Skip setting autozoom options");
288
+			return;
289
+		}
290
+
291
+		$geom     = new GeometryCollection ($geoms);
292
+		$centroid = $geom->centroid();
293
+		$bbox     = $geom->getBBox();
294
+
295
+		// determine vertical resolution, this depends on the distance from the equator
296
+		// $vy00 = log(tan(M_PI*(0.25 + $centroid->getY()/360)));
297
+		$vy0 = log(tan(M_PI * (0.25 + $bbox ['miny'] / 360)));
298
+		$vy1 = log(tan(M_PI * (0.25 + $bbox ['maxy'] / 360)));
299
+		dbglog("StaticMap::autoZoom: vertical resolution: $vy0, $vy1");
300
+		$zoomFactorPowered  = ($this->height / 2) / (40.7436654315252 * ($vy1 - $vy0));
301
+		$resolutionVertical = 360 / ($zoomFactorPowered * $this->tileSize);
302
+		// determine horizontal resolution
303
+		$resolutionHorizontal = ($bbox ['maxx'] - $bbox ['minx']) / $this->width;
304
+		$resolution           = max($resolutionHorizontal, $resolutionVertical) * $paddingFactor;
305
+		$zoom                 = log(360 / ($resolution * $this->tileSize), 2);
306
+
307
+		if(is_finite($zoom) && $zoom < 15 && $zoom > 2) {
308
+			$this->zoom = floor($zoom);
309
+		}
310
+		$this->lon = $centroid->getX();
311
+		$this->lat = $centroid->getY();
312
+		dbglog("StaticMap::autoZoom: Set autozoom options to: z: $this->zoom, lon: $this->lon, lat: $this->lat");
313
+	}
314
+
315
+	public function checkMapCache(): bool {
316
+		// side effect: set the mapCacheID
317
+		$this->mapCacheID = md5($this->serializeParams());
318
+		$filename         = $this->mapCacheIDToFilename();
319
+		return file_exists($filename);
320
+	}
321
+
322
+	public function serializeParams(): string {
323
+		return join(
324
+			"&", array(
325
+				   $this->zoom,
326
+				   $this->lat,
327
+				   $this->lon,
328
+				   $this->width,
329
+				   $this->height,
330
+				   serialize($this->markers),
331
+				   $this->maptype,
332
+				   $this->kmlFileName,
333
+				   $this->gpxFileName,
334
+				   $this->geojsonFileName
335
+			   )
336
+		);
337
+	}
338
+
339
+	public function mapCacheIDToFilename(): string {
340
+		if(!$this->mapCacheFile) {
341
+			$this->mapCacheFile = $this->mapCacheBaseDir . "/" . $this->maptype . "/" . $this->zoom . "/cache_"
342
+				. substr($this->mapCacheID, 0, 2) . "/" . substr($this->mapCacheID, 2, 2)
343
+				. "/" . substr($this->mapCacheID, 4);
344
+		}
345
+		return $this->mapCacheFile . "." . $this->mapCacheExtension;
346
+	}
347
+
348
+	/**
349
+	 * make the map.
350
+	 */
351
+	public function makeMap(): void {
352
+		$this->initCoords();
353
+		$this->createBaseMap();
354
+		if(!empty ($this->markers))
355
+			$this->placeMarkers();
356
+		if(file_exists($this->kmlFileName))
357
+			$this->drawKML();
358
+		if(file_exists($this->gpxFileName))
359
+			$this->drawGPX();
360
+		if(file_exists($this->geojsonFileName))
361
+			$this->drawGeojson();
362
+
363
+		$this->drawCopyright();
364
+	}
365
+
366
+	/**
367
+	 */
368
+	public function initCoords(): void {
369
+		$this->centerX = $this->lonToTile($this->lon, $this->zoom);
370
+		$this->centerY = $this->latToTile($this->lat, $this->zoom);
371
+		$this->offsetX = floor((floor($this->centerX) - $this->centerX) * $this->tileSize);
372
+		$this->offsetY = floor((floor($this->centerY) - $this->centerY) * $this->tileSize);
373
+	}
374
+
375
+	/**
376
+	 *
377
+	 * @param float $long
378
+	 * @param int   $zoom
379
+	 * @return float|int
380
+	 */
381
+	public function lonToTile(float $long, int $zoom) {
382
+		return (($long + 180) / 360) * pow(2, $zoom);
383
+	}
384
+
385
+	/**
386
+	 *
387
+	 * @param float $lat
388
+	 * @param int   $zoom
389
+	 * @return float|int
390
+	 */
391
+	public function latToTile(float $lat, int $zoom) {
392
+		return (1 - log(tan($lat * pi() / 180) + 1 / cos($lat * M_PI / 180)) / M_PI) / 2 * pow(2, $zoom);
393
+	}
394
+
395
+	/**
396
+	 * make basemap image.
397
+	 */
398
+	public function createBaseMap(): void {
399
+		$this->image   = imagecreatetruecolor($this->width, $this->height);
400
+		$startX        = floor($this->centerX - ($this->width / $this->tileSize) / 2);
401
+		$startY        = floor($this->centerY - ($this->height / $this->tileSize) / 2);
402
+		$endX          = ceil($this->centerX + ($this->width / $this->tileSize) / 2);
403
+		$endY          = ceil($this->centerY + ($this->height / $this->tileSize) / 2);
404
+		$this->offsetX = -floor(($this->centerX - floor($this->centerX)) * $this->tileSize);
405
+		$this->offsetY = -floor(($this->centerY - floor($this->centerY)) * $this->tileSize);
406
+		$this->offsetX += floor($this->width / 2);
407
+		$this->offsetY += floor($this->height / 2);
408
+		$this->offsetX += floor($startX - floor($this->centerX)) * $this->tileSize;
409
+		$this->offsetY += floor($startY - floor($this->centerY)) * $this->tileSize;
410
+
411
+		for($x = $startX; $x <= $endX; $x++) {
412
+			for($y = $startY; $y <= $endY; $y++) {
413
+				$url = str_replace(
414
+					array(
415
+						'{Z}',
416
+						'{X}',
417
+						'{Y}'
418
+					), array(
419
+						$this->zoom,
420
+						$x,
421
+						$y
422
+					), $this->tileInfo [$this->maptype] ['url']
423
+				);
424
+
425
+				$tileData = $this->fetchTile($url);
426
+				if($tileData) {
427
+					$tileImage = imagecreatefromstring($tileData);
428
+				} else {
429
+					$tileImage = imagecreate($this->tileSize, $this->tileSize);
430
+					$color     = imagecolorallocate($tileImage, 255, 255, 255);
431
+					@imagestring($tileImage, 1, 127, 127, 'err', $color);
432
+				}
433
+				$destX = ($x - $startX) * $this->tileSize + $this->offsetX;
434
+				$destY = ($y - $startY) * $this->tileSize + $this->offsetY;
435
+				dbglog($this->tileSize, "imagecopy tile into image: $destX, $destY");
436
+				imagecopy(
437
+					$this->image, $tileImage, $destX, $destY, 0, 0, $this->tileSize,
438
+					$this->tileSize
439
+				);
440
+			}
441
+		}
442
+	}
443
+
444
+	/**
445
+	 * Fetch a tile and (if configured) store it in the cache.
446
+	 * @param string $url
447
+	 * @return bool|string
448
+	 * @todo refactor this to use dokuwiki\HTTP\HTTPClient or dokuwiki\HTTP\DokuHTTPClient
449
+	 *          for better proxy handling...
450
+	 */
451
+	public function fetchTile(string $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 . $this->apikey);
463
+			dbglog("StaticMap::fetchTile: getting: $url using curl_exec");
464
+			$tile = curl_exec($ch);
465
+			curl_close($ch);
466
+		} else {
467
+			// use file_get_contents
468
+			global $conf;
469
+			$opts = array(
470
+				'http' => array(
471
+					'method'          => "GET",
472
+					'header'          => "Accept-language: en\r\n" . "User-Agent: $_UA\r\n" . "accept: image/png\r\n",
473
+					'request_fulluri' => true
474
+				)
475
+			);
476
+			if(isset($conf['proxy']['host'], $conf['proxy']['port'])
477
+				&& $conf['proxy']['host'] !== ''
478
+				&& $conf['proxy']['port'] !== '') {
479
+				$opts['http'] += ['proxy' => "tcp://" . $conf['proxy']['host'] . ":" . $conf['proxy']['port']];
480
+			}
481
+
482
+			$context = stream_context_create($opts);
483
+			dbglog("StaticMap::fetchTile: getting: $url . $this->apikey using file_get_contents and options $opts");
484
+			$tile = file_get_contents($url . $this->apikey, false, $context);
485
+		}
486
+		if($tile && $this->useTileCache) {
487
+			$this->writeTileToCache($url, $tile);
488
+		}
489
+		return $tile;
490
+	}
491
+
492
+	/**
493
+	 *
494
+	 * @param string $url
495
+	 * @return string|false
496
+	 */
497
+	public function checkTileCache(string $url) {
498
+		$filename = $this->tileUrlToFilename($url);
499
+		if(file_exists($filename)) {
500
+			return file_get_contents($filename);
501
+		}
502
+		return false;
503
+	}
504
+
505
+	/**
506
+	 *
507
+	 * @param string $url
508
+	 * @return string
509
+	 */
510
+	public function tileUrlToFilename(string $url): string {
511
+		return $this->tileCacheBaseDir . "/" . substr($url, strpos($url, '/') + 1);
512
+	}
513
+
514
+	/**
515
+	 * Write a tile into the cache.
516
+	 *
517
+	 * @param string $url
518
+	 * @param mixed  $data
519
+	 */
520
+	public function writeTileToCache($url, $data): void {
521
+		$filename = $this->tileUrlToFilename($url);
522
+		$this->mkdirRecursive(dirname($filename), 0777);
523
+		file_put_contents($filename, $data);
524
+	}
525
+
526
+	/**
527
+	 * Recursively create the directory.
528
+	 *
529
+	 * @param string $pathname
530
+	 *            The directory path.
531
+	 * @param int    $mode
532
+	 *            File access mode. For more information on modes, read the details on the chmod manpage.
533
+	 */
534
+	public function mkdirRecursive(string $pathname, int $mode): bool {
535
+		is_dir(dirname($pathname)) || $this->mkdirRecursive(dirname($pathname), $mode);
536
+		return is_dir($pathname) || mkdir($pathname, $mode) || is_dir($pathname);
537
+	}
538
+
539
+	/**
540
+	 * Place markers on the map and number them in the same order as they are listed in the html.
541
+	 */
542
+	public function placeMarkers(): void {
543
+		$count         = 0;
544
+		$color         = imagecolorallocate($this->image, 0, 0, 0);
545
+		$bgcolor       = imagecolorallocate($this->image, 200, 200, 200);
546
+		$markerBaseDir = __DIR__ . '/icons';
547
+		// loop thru marker array
548
+		foreach($this->markers as $marker) {
549
+			// set some local variables
550
+			$markerLat  = $marker ['lat'];
551
+			$markerLon  = $marker ['lon'];
552
+			$markerType = $marker ['type'];
553
+			// clear variables from previous loops
554
+			$markerFilename = '';
555
+			$markerShadow   = '';
556
+			$matches        = false;
557
+			// check for marker type, get settings from markerPrototypes
558
+			if($markerType) {
559
+				foreach($this->markerPrototypes as $markerPrototype) {
560
+					if(preg_match($markerPrototype ['regex'], $markerType, $matches)) {
561
+						$markerFilename = $matches [0] . $markerPrototype ['extension'];
562
+						if($markerPrototype ['offsetImage']) {
563
+							list ($markerImageOffsetX, $markerImageOffsetY) = explode(
564
+								",",
565
+								$markerPrototype ['offsetImage']
566
+							);
567
+						}
568
+						$markerShadow = $markerPrototype ['shadow'];
569
+						if($markerShadow) {
570
+							list ($markerShadowOffsetX, $markerShadowOffsetY) = explode(
571
+								",",
572
+								$markerPrototype ['offsetShadow']
573
+							);
574
+						}
575
+					}
576
+				}
577
+			}
578
+			// create img resource
579
+			if(file_exists($markerBaseDir . '/' . $markerFilename)) {
580
+				$markerImg = imagecreatefrompng($markerBaseDir . '/' . $markerFilename);
581
+			} else {
582
+				$markerImg = imagecreatefrompng($markerBaseDir . '/marker.png');
583
+			}
584
+			// check for shadow + create shadow recource
585
+			if($markerShadow && file_exists($markerBaseDir . '/' . $markerShadow)) {
586
+				$markerShadowImg = imagecreatefrompng($markerBaseDir . '/' . $markerShadow);
587
+			}
588
+			// calc position
589
+			$destX = floor(
590
+				($this->width / 2) -
591
+				$this->tileSize * ($this->centerX - $this->lonToTile($markerLon, $this->zoom))
592
+			);
593
+			$destY = floor(
594
+				($this->height / 2) -
595
+				$this->tileSize * ($this->centerY - $this->latToTile($markerLat, $this->zoom))
596
+			);
597
+			// copy shadow on basemap
598
+			if($markerShadow && $markerShadowImg) {
599
+				imagecopy(
600
+					$this->image,
601
+					$markerShadowImg,
602
+					$destX + (int) $markerShadowOffsetX,
603
+					$destY + (int) $markerShadowOffsetY,
604
+					0,
605
+					0,
606
+					imagesx($markerShadowImg),
607
+					imagesy($markerShadowImg)
608
+				);
609
+			}
610
+			// copy marker on basemap above shadow
611
+			imagecopy(
612
+				$this->image,
613
+				$markerImg,
614
+				$destX + (int) $markerImageOffsetX,
615
+				$destY + (int) $markerImageOffsetY,
616
+				0,
617
+				0,
618
+				imagesx($markerImg),
619
+				imagesy($markerImg)
620
+			);
621
+			// add label
622
+			imagestring(
623
+				$this->image,
624
+				3,
625
+				$destX - imagesx($markerImg) + 1,
626
+				$destY + (int) $markerImageOffsetY + 1,
627
+				++$count,
628
+				$bgcolor
629
+			);
630
+			imagestring(
631
+				$this->image,
632
+				3,
633
+				$destX - imagesx($markerImg),
634
+				$destY + (int) $markerImageOffsetY,
635
+				$count,
636
+				$color
637
+			);
638
+		}
639
+	}
640
+
641
+	/**
642
+	 * Draw kml trace on the map.
643
+	 */
644
+	public function drawKML(): void {
645
+		// TODO get colour from kml node (not currently supported in geoPHP)
646
+		$col     = imagecolorallocatealpha($this->image, 255, 0, 0, .4 * 127);
647
+		$kmlgeom = geoPHP::load(file_get_contents($this->kmlFileName), 'kml');
648
+		$this->drawGeometry($kmlgeom, $col);
649
+	}
650
+
651
+	/**
652
+	 * Draw geometry or geometry collection on the map.
653
+	 *
654
+	 * @param Geometry $geom
655
+	 * @param int      $colour
656
+	 *            drawing colour
657
+	 */
658
+	private function drawGeometry(Geometry $geom, int $colour): void {
659
+		if(empty($geom)) {
660
+			return;
661
+		}
662
+
663
+		switch($geom->geometryType()) {
664
+			case 'GeometryCollection' :
665
+				// recursively draw part of the collection
666
+				for($i = 1; $i < $geom->numGeometries() + 1; $i++) {
667
+					$_geom = $geom->geometryN($i);
668
+					$this->drawGeometry($_geom, $colour);
669
+				}
670
+				break;
671
+			case 'MultiPolygon' :
672
+			case 'MultiLineString' :
673
+			case 'MultiPoint' :
674
+				// TODO implement / do nothing
675
+				break;
676
+			case 'Polygon' :
677
+				$this->drawPolygon($geom, $colour);
678
+				break;
679
+			case 'LineString' :
680
+				$this->drawLineString($geom, $colour);
681
+				break;
682
+			case 'Point' :
683
+				$this->drawPoint($geom, $colour);
684
+				break;
685
+			default :
686
+				// draw nothing
687
+				break;
688
+		}
689
+	}
690
+
691
+	/**
692
+	 * Draw a polygon on the map.
693
+	 *
694
+	 * @param Polygon $polygon
695
+	 * @param int     $colour
696
+	 *            drawing colour
697
+	 */
698
+	private function drawPolygon($polygon, int $colour) {
699
+		// TODO implementation of drawing holes,
700
+		// maybe draw the polygon to an in-memory image and use imagecopy, draw polygon in col., draw holes in bgcol?
701
+
702
+		// print_r('Polygon:<br />');
703
+		// print_r($polygon);
704
+		$extPoints = array();
705
+		// extring is a linestring actually..
706
+		$extRing = $polygon->exteriorRing();
707
+
708
+		for($i = 1; $i < $extRing->numGeometries(); $i++) {
709
+			$p1           = $extRing->geometryN($i);
710
+			$x            = floor(
711
+				($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))
712
+			);
713
+			$y            = floor(
714
+				($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p1->y(), $this->zoom))
715
+			);
716
+			$extPoints [] = $x;
717
+			$extPoints [] = $y;
718
+		}
719
+		// print_r('points:('.($i-1).')<br />');
720
+		// print_r($extPoints);
721
+		// imagepolygon ($this->image, $extPoints, $i-1, $colour );
722
+		imagefilledpolygon($this->image, $extPoints, $i - 1, $colour);
723
+	}
724
+
725
+	/**
726
+	 * Draw a line on the map.
727
+	 *
728
+	 * @param LineString $line
729
+	 * @param int        $colour
730
+	 *            drawing colour
731
+	 */
732
+	private function drawLineString($line, $colour) {
733
+		imagesetthickness($this->image, 2);
734
+		for($p = 1; $p < $line->numGeometries(); $p++) {
735
+			// get first pair of points
736
+			$p1 = $line->geometryN($p);
737
+			$p2 = $line->geometryN($p + 1);
738
+			// translate to paper space
739
+			$x1 = floor(
740
+				($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p1->x(), $this->zoom))
741
+			);
742
+			$y1 = floor(
743
+				($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p1->y(), $this->zoom))
744
+			);
745
+			$x2 = floor(
746
+				($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($p2->x(), $this->zoom))
747
+			);
748
+			$y2 = floor(
749
+				($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($p2->y(), $this->zoom))
750
+			);
751
+			// draw to image
752
+			imageline($this->image, $x1, $y1, $x2, $y2, $colour);
753
+		}
754
+		imagesetthickness($this->image, 1);
755
+	}
756
+
757
+	/**
758
+	 * Draw a point on the map.
759
+	 *
760
+	 * @param Point $point
761
+	 * @param int   $colour
762
+	 *            drawing colour
763
+	 */
764
+	private function drawPoint($point, $colour) {
765
+		imagesetthickness($this->image, 2);
766
+		// translate to paper space
767
+		$cx = floor(
768
+			($this->width / 2) - $this->tileSize * ($this->centerX - $this->lonToTile($point->x(), $this->zoom))
769
+		);
770
+		$cy = floor(
771
+			($this->height / 2) - $this->tileSize * ($this->centerY - $this->latToTile($point->y(), $this->zoom))
772
+		);
773
+		$r  = 5;
774
+		// draw to image
775
+		// imageellipse($this->image, $cx, $cy,$r, $r, $colour);
776
+		imagefilledellipse($this->image, $cx, $cy, $r, $r, $colour);
777
+		// don't use imageellipse because the imagesetthickness function has
778
+		// no effect. So the better workaround is to use imagearc.
779
+		imagearc($this->image, $cx, $cy, $r, $r, 0, 359, $colour);
780
+		imagesetthickness($this->image, 1);
781
+	}
782
+
783
+	/**
784
+	 * Draw gpx trace on the map.
785
+	 */
786
+	public function drawGPX() {
787
+		$col     = imagecolorallocatealpha($this->image, 0, 0, 255, .4 * 127);
788
+		$gpxgeom = geoPHP::load(file_get_contents($this->gpxFileName), 'gpx');
789
+		$this->drawGeometry($gpxgeom, $col);
790
+	}
791
+
792
+	/**
793
+	 * Draw geojson on the map.
794
+	 */
795
+	public function drawGeojson() {
796
+		$col     = imagecolorallocatealpha($this->image, 255, 0, 255, .4 * 127);
797
+		$gpxgeom = geoPHP::load(file_get_contents($this->geojsonFileName), 'json');
798
+		$this->drawGeometry($gpxgeom, $col);
799
+	}
800
+
801
+	/**
802
+	 * add copyright and origin notice and icons to the map.
803
+	 */
804
+	public function drawCopyright() {
805
+		$logoBaseDir = dirname(__FILE__) . '/' . 'logo/';
806
+		$logoImg     = imagecreatefrompng($logoBaseDir . $this->tileInfo ['openstreetmap'] ['logo']);
807
+		$textcolor   = imagecolorallocate($this->image, 0, 0, 0);
808
+		$bgcolor     = imagecolorallocate($this->image, 200, 200, 200);
809
+
810
+		imagecopy(
811
+			$this->image,
812
+			$logoImg,
813
+			0,
814
+			imagesy($this->image) - imagesy($logoImg),
815
+			0,
816
+			0,
817
+			imagesx($logoImg),
818
+			imagesy($logoImg)
819
+		);
820
+		imagestring(
821
+			$this->image,
822
+			1,
823
+			imagesx($logoImg) + 2,
824
+			imagesy($this->image) - imagesy($logoImg) + 1,
825
+			$this->tileInfo ['openstreetmap'] ['txt'],
826
+			$bgcolor
827
+		);
828
+		imagestring(
829
+			$this->image,
830
+			1,
831
+			imagesx($logoImg) + 1,
832
+			imagesy($this->image) - imagesy($logoImg),
833
+			$this->tileInfo ['openstreetmap'] ['txt'],
834
+			$textcolor
835
+		);
836
+
837
+		// additional tile source info, ie. who created/hosted the tiles
838
+		$xIconOffset = 0;
839
+		if($this->maptype === 'openstreetmap') {
840
+			$mapAuthor = "(c) OpenStreetMap maps/CC BY-SA";
841
+		} else {
842
+			$mapAuthor   = $this->tileInfo [$this->maptype] ['txt'];
843
+			$iconImg     = imagecreatefrompng($logoBaseDir . $this->tileInfo [$this->maptype] ['logo']);
844
+			$xIconOffset = imagesx($iconImg);
845
+			imagecopy(
846
+				$this->image,
847
+				$iconImg, imagesx($logoImg) + 1,
848
+				imagesy($this->image) - imagesy($iconImg),
849
+				0,
850
+				0,
851
+				imagesx($iconImg), imagesy($iconImg)
852
+			);
853
+		}
854
+		imagestring(
855
+			$this->image,
856
+			1, imagesx($logoImg) + $xIconOffset + 4,
857
+			imagesy($this->image) - ceil(imagesy($logoImg) / 2) + 1,
858
+			$mapAuthor,
859
+			$bgcolor
860
+		);
861
+		imagestring(
862
+			$this->image,
863
+			1, imagesx($logoImg) + $xIconOffset + 3,
864
+			imagesy($this->image) - ceil(imagesy($logoImg) / 2),
865
+			$mapAuthor,
866
+			$textcolor
867
+		);
868
+
869
+	}
870 870
 }
Please login to merge, or discard this patch.
action.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -24,43 +24,43 @@
 block discarded – undo
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("_data" => "document.documentElement.className += ' olCSSsupported';");
65
-    }
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("_data" => "document.documentElement.className += ' olCSSsupported';");
65
+	}
66 66
 }
Please login to merge, or discard this patch.
syntax/osmlayer.php 1 patch
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -22,110 +22,110 @@
 block discarded – undo
22 22
  */
23 23
 class syntax_plugin_openlayersmap_osmlayer extends DokuWiki_Syntax_Plugin
24 24
 {
25
-    private $dflt = array(
26
-        'id'          => 'olmap',
27
-        'name'        => '',
28
-        'url'         => '',
29
-        'opacity'     => 0.8,
30
-        'attribution' => '',
31
-        'visible'     => false,
32
-        'cors'        => null
33
-    );
25
+	private $dflt = array(
26
+		'id'          => 'olmap',
27
+		'name'        => '',
28
+		'url'         => '',
29
+		'opacity'     => 0.8,
30
+		'attribution' => '',
31
+		'visible'     => false,
32
+		'cors'        => null
33
+	);
34 34
 
35
-    /**
36
-     * (non-PHPdoc)
37
-     *
38
-     * @see DokuWiki_Syntax_Plugin::getPType()
39
-     */
40
-    public function getPType(): string
41
-    {
42
-        return 'block';
43
-    }
35
+	/**
36
+	 * (non-PHPdoc)
37
+	 *
38
+	 * @see DokuWiki_Syntax_Plugin::getPType()
39
+	 */
40
+	public function getPType(): string
41
+	{
42
+		return 'block';
43
+	}
44 44
 
45
-    /**
46
-     * (non-PHPdoc)
47
-     *
48
-     * @see DokuWiki_Syntax_Plugin::getType()
49
-     */
50
-    public function getType(): string
51
-    {
52
-        // return 'FIXME: container|baseonly|formatting|substition|protected|disabled|paragraphs';
53
-        return 'baseonly';
54
-    }
45
+	/**
46
+	 * (non-PHPdoc)
47
+	 *
48
+	 * @see DokuWiki_Syntax_Plugin::getType()
49
+	 */
50
+	public function getType(): string
51
+	{
52
+		// return 'FIXME: container|baseonly|formatting|substition|protected|disabled|paragraphs';
53
+		return 'baseonly';
54
+	}
55 55
 
56
-    /**
57
-     * (non-PHPdoc)
58
-     *
59
-     * @see Doku_Parser_Mode::getSort()
60
-     */
61
-    public function getSort(): int
62
-    {
63
-        return 902;
64
-    }
56
+	/**
57
+	 * (non-PHPdoc)
58
+	 *
59
+	 * @see Doku_Parser_Mode::getSort()
60
+	 */
61
+	public function getSort(): int
62
+	{
63
+		return 902;
64
+	}
65 65
 
66
-    /**
67
-     * Connect to our special pattern.
68
-     *
69
-     * @see Doku_Parser_Mode::connectTo()
70
-     */
71
-    public function connectTo($mode): void
72
-    {
73
-        // look for: <olmap_osmlayer id="olmap" name="sport" url="http://tiles.openseamap.org/sport/${z}/${x}/${y}.png"
74
-        // visible="false" opacity=0.6 attribution="Some attribution"></olmap_osmlayer>
75
-        $this->Lexer->addSpecialPattern(
76
-            '<olmap_osmlayer ?[^>\n]*>.*?</olmap_osmlayer>',
77
-            $mode,
78
-            'plugin_openlayersmap_osmlayer'
79
-        );
80
-    }
66
+	/**
67
+	 * Connect to our special pattern.
68
+	 *
69
+	 * @see Doku_Parser_Mode::connectTo()
70
+	 */
71
+	public function connectTo($mode): void
72
+	{
73
+		// look for: <olmap_osmlayer id="olmap" name="sport" url="http://tiles.openseamap.org/sport/${z}/${x}/${y}.png"
74
+		// visible="false" opacity=0.6 attribution="Some attribution"></olmap_osmlayer>
75
+		$this->Lexer->addSpecialPattern(
76
+			'<olmap_osmlayer ?[^>\n]*>.*?</olmap_osmlayer>',
77
+			$mode,
78
+			'plugin_openlayersmap_osmlayer'
79
+		);
80
+	}
81 81
 
82
-    /**
83
-     * (non-PHPdoc)
84
-     *
85
-     * @see DokuWiki_Syntax_Plugin::handle()
86
-     */
87
-    public function handle($match, $state, $pos, Doku_Handler $handler): array
88
-    {
89
-        $param = array();
90
-        $data  = $this->dflt;
82
+	/**
83
+	 * (non-PHPdoc)
84
+	 *
85
+	 * @see DokuWiki_Syntax_Plugin::handle()
86
+	 */
87
+	public function handle($match, $state, $pos, Doku_Handler $handler): array
88
+	{
89
+		$param = array();
90
+		$data  = $this->dflt;
91 91
 
92
-        preg_match_all('/(\w*)="(.*?)"/us', $match, $param, PREG_SET_ORDER);
92
+		preg_match_all('/(\w*)="(.*?)"/us', $match, $param, PREG_SET_ORDER);
93 93
 
94
-        foreach ($param as $kvpair) {
95
-            list ($matched, $key, $val) = $kvpair;
96
-            if (isset ($data [$key])) {
97
-                $key         = strtolower($key);
98
-                $data [$key] = $val;
99
-            }
100
-        }
101
-        // dbglog($data,'syntax_plugin_overlayer::handle: parsed data is:');
102
-        return $data;
103
-    }
94
+		foreach ($param as $kvpair) {
95
+			list ($matched, $key, $val) = $kvpair;
96
+			if (isset ($data [$key])) {
97
+				$key         = strtolower($key);
98
+				$data [$key] = $val;
99
+			}
100
+		}
101
+		// dbglog($data,'syntax_plugin_overlayer::handle: parsed data is:');
102
+		return $data;
103
+	}
104 104
 
105
-    /**
106
-     * (non-PHPdoc)
107
-     *
108
-     * @see DokuWiki_Syntax_Plugin::render()
109
-     */
110
-    public function render($format, Doku_Renderer $renderer, $data): bool
111
-    {
112
-        if ($format !== 'xhtml') {
113
-            return false;
114
-        }
105
+	/**
106
+	 * (non-PHPdoc)
107
+	 *
108
+	 * @see DokuWiki_Syntax_Plugin::render()
109
+	 */
110
+	public function render($format, Doku_Renderer $renderer, $data): bool
111
+	{
112
+		if ($format !== 'xhtml') {
113
+			return false;
114
+		}
115 115
 
116
-        // incremented for each olmap_osmlayer tag in the page source
117
-        static $overlaynumber = 0;
116
+		// incremented for each olmap_osmlayer tag in the page source
117
+		static $overlaynumber = 0;
118 118
 
119
-        list ($id, $url, $name, $visible) = $data;
120
-        $renderer->doc .= DOKU_LF . '<script defer="defer" src="data:text/javascript;base64,';
121
-        $str           = '{';
122
-        foreach ($data as $key => $val) {
123
-            $str .= "'" . $key . "' : '" . $val . "',";
124
-        }
125
-        $str           .= '"type":"osm"}';
126
-        $renderer->doc .= base64_encode("olMapOverlays['osm" . $overlaynumber . "'] = " . $str . ";")
127
-            . '"></script>';
128
-        $overlaynumber++;
129
-        return true;
130
-    }
119
+		list ($id, $url, $name, $visible) = $data;
120
+		$renderer->doc .= DOKU_LF . '<script defer="defer" src="data:text/javascript;base64,';
121
+		$str           = '{';
122
+		foreach ($data as $key => $val) {
123
+			$str .= "'" . $key . "' : '" . $val . "',";
124
+		}
125
+		$str           .= '"type":"osm"}';
126
+		$renderer->doc .= base64_encode("olMapOverlays['osm" . $overlaynumber . "'] = " . $str . ";")
127
+			. '"></script>';
128
+		$overlaynumber++;
129
+		return true;
130
+	}
131 131
 }
Please login to merge, or discard this patch.
syntax/agslayer.php 1 patch
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -22,114 +22,114 @@
 block discarded – undo
22 22
  */
23 23
 class syntax_plugin_openlayersmap_agslayer extends DokuWiki_Syntax_Plugin
24 24
 {
25
-    private $dflt = array(
26
-        'id'          => 'olmap',
27
-        'name'        => '',
28
-        'url'         => '',
29
-        'opacity'     => 0.8,
30
-        'attribution' => '',
31
-        'visible'     => false,
32
-        'layers'      => '',
33
-        'format'      => 'png',
34
-        'transparent' => 'true'
35
-    );
25
+	private $dflt = array(
26
+		'id'          => 'olmap',
27
+		'name'        => '',
28
+		'url'         => '',
29
+		'opacity'     => 0.8,
30
+		'attribution' => '',
31
+		'visible'     => false,
32
+		'layers'      => '',
33
+		'format'      => 'png',
34
+		'transparent' => 'true'
35
+	);
36 36
 
37
-    /**
38
-     * (non-PHPdoc)
39
-     *
40
-     * @see DokuWiki_Syntax_Plugin::getPType()
41
-     */
42
-    public function getPType(): string
43
-    {
44
-        return 'block';
45
-    }
37
+	/**
38
+	 * (non-PHPdoc)
39
+	 *
40
+	 * @see DokuWiki_Syntax_Plugin::getPType()
41
+	 */
42
+	public function getPType(): string
43
+	{
44
+		return 'block';
45
+	}
46 46
 
47
-    /**
48
-     * (non-PHPdoc)
49
-     *
50
-     * @see DokuWiki_Syntax_Plugin::getType()
51
-     */
52
-    public function getType(): string
53
-    {
54
-        // return 'FIXME: container|baseonly|formatting|substition|protected|disabled|paragraphs';
55
-        return 'baseonly';
56
-    }
47
+	/**
48
+	 * (non-PHPdoc)
49
+	 *
50
+	 * @see DokuWiki_Syntax_Plugin::getType()
51
+	 */
52
+	public function getType(): string
53
+	{
54
+		// return 'FIXME: container|baseonly|formatting|substition|protected|disabled|paragraphs';
55
+		return 'baseonly';
56
+	}
57 57
 
58
-    /**
59
-     * (non-PHPdoc)
60
-     *
61
-     * @see Doku_Parser_Mode::getSort()
62
-     */
63
-    public function getSort(): int
64
-    {
65
-        return 904;
66
-    }
58
+	/**
59
+	 * (non-PHPdoc)
60
+	 *
61
+	 * @see Doku_Parser_Mode::getSort()
62
+	 */
63
+	public function getSort(): int
64
+	{
65
+		return 904;
66
+	}
67 67
 
68
-    /**
69
-     * Connect to our special pattern.
70
-     *
71
-     * @see Doku_Parser_Mode::connectTo()
72
-     */
73
-    public function connectTo($mode): void
74
-    {
75
-        // look for: <olmap_agslayer id="olmap" name="cloud"
76
-        // url="http://geoservices2.wallonie.be/arcgis/rest/services/APP_KAYAK/KAYAK/MapServer/export"
77
-        // attribution="wallonie.be" visible="true" layers="show:0,1,2,3,4,7"></olmap_agslayer>
78
-        // sample:
79
-        // http://geoservices2.wallonie.be/arcgis/rest/services/APP_KAYAK/KAYAK/MapServer/export?LAYERS=show%3A0%2C1%2C2%2C3%2C4%2C7&TRANSPARENT=true&FORMAT=png&BBOX=643294.029959%2C6467184.088252%2C645740.014863%2C6469630.073157&SIZE=256%2C256&F=html&BBOXSR=3857&IMAGESR=3857
80
-        $this->Lexer->addSpecialPattern(
81
-            '<olmap_agslayer ?[^>\n]*>.*?</olmap_agslayer>',
82
-            $mode,
83
-            'plugin_openlayersmap_agslayer'
84
-        );
85
-    }
68
+	/**
69
+	 * Connect to our special pattern.
70
+	 *
71
+	 * @see Doku_Parser_Mode::connectTo()
72
+	 */
73
+	public function connectTo($mode): void
74
+	{
75
+		// look for: <olmap_agslayer id="olmap" name="cloud"
76
+		// url="http://geoservices2.wallonie.be/arcgis/rest/services/APP_KAYAK/KAYAK/MapServer/export"
77
+		// attribution="wallonie.be" visible="true" layers="show:0,1,2,3,4,7"></olmap_agslayer>
78
+		// sample:
79
+		// http://geoservices2.wallonie.be/arcgis/rest/services/APP_KAYAK/KAYAK/MapServer/export?LAYERS=show%3A0%2C1%2C2%2C3%2C4%2C7&TRANSPARENT=true&FORMAT=png&BBOX=643294.029959%2C6467184.088252%2C645740.014863%2C6469630.073157&SIZE=256%2C256&F=html&BBOXSR=3857&IMAGESR=3857
80
+		$this->Lexer->addSpecialPattern(
81
+			'<olmap_agslayer ?[^>\n]*>.*?</olmap_agslayer>',
82
+			$mode,
83
+			'plugin_openlayersmap_agslayer'
84
+		);
85
+	}
86 86
 
87
-    /**
88
-     * (non-PHPdoc)
89
-     *
90
-     * @see DokuWiki_Syntax_Plugin::handle()
91
-     */
92
-    public function handle($match, $state, $pos, Doku_Handler $handler): array
93
-    {
94
-        $param = array();
95
-        $data  = $this->dflt;
87
+	/**
88
+	 * (non-PHPdoc)
89
+	 *
90
+	 * @see DokuWiki_Syntax_Plugin::handle()
91
+	 */
92
+	public function handle($match, $state, $pos, Doku_Handler $handler): array
93
+	{
94
+		$param = array();
95
+		$data  = $this->dflt;
96 96
 
97
-        preg_match_all('/(\w*)="(.*?)"/us', $match, $param, PREG_SET_ORDER);
97
+		preg_match_all('/(\w*)="(.*?)"/us', $match, $param, PREG_SET_ORDER);
98 98
 
99
-        foreach ($param as $kvpair) {
100
-            list ($matched, $key, $val) = $kvpair;
101
-            if (isset ($data [$key])) {
102
-                $key         = strtolower($key);
103
-                $data [$key] = $val;
104
-            }
105
-        }
106
-        return $data;
107
-    }
99
+		foreach ($param as $kvpair) {
100
+			list ($matched, $key, $val) = $kvpair;
101
+			if (isset ($data [$key])) {
102
+				$key         = strtolower($key);
103
+				$data [$key] = $val;
104
+			}
105
+		}
106
+		return $data;
107
+	}
108 108
 
109
-    /**
110
-     * (non-PHPdoc)
111
-     *
112
-     * @see DokuWiki_Syntax_Plugin::render()
113
-     */
114
-    public function render($format, Doku_Renderer $renderer, $data): bool
115
-    {
116
-        if ($format !== 'xhtml') {
117
-            return false;
118
-        }
109
+	/**
110
+	 * (non-PHPdoc)
111
+	 *
112
+	 * @see DokuWiki_Syntax_Plugin::render()
113
+	 */
114
+	public function render($format, Doku_Renderer $renderer, $data): bool
115
+	{
116
+		if ($format !== 'xhtml') {
117
+			return false;
118
+		}
119 119
 
120
-        // incremented for each olmap_agslayer tag in the page source
121
-        static $overlaynumber = 0;
120
+		// incremented for each olmap_agslayer tag in the page source
121
+		static $overlaynumber = 0;
122 122
 
123
-        list ($id, $url, $name, $visible) = $data;
124
-        $renderer->doc .= DOKU_LF . '<script defer="defer" src="data:text/javascript;base64,';
125
-        $str           = '{';
126
-        foreach ($data as $key => $val) {
127
-            $str .= "'" . $key . "' : '" . $val . "',";
128
-        }
129
-        $str           .= "'type':'ags'}";
130
-        $renderer->doc .= base64_encode("olMapOverlays['ags" . $overlaynumber . "'] = " . $str . ";")
131
-            . '"></script>';
132
-        $overlaynumber++;
133
-        return true;
134
-    }
123
+		list ($id, $url, $name, $visible) = $data;
124
+		$renderer->doc .= DOKU_LF . '<script defer="defer" src="data:text/javascript;base64,';
125
+		$str           = '{';
126
+		foreach ($data as $key => $val) {
127
+			$str .= "'" . $key . "' : '" . $val . "',";
128
+		}
129
+		$str           .= "'type':'ags'}";
130
+		$renderer->doc .= base64_encode("olMapOverlays['ags" . $overlaynumber . "'] = " . $str . ";")
131
+			. '"></script>';
132
+		$overlaynumber++;
133
+		return true;
134
+	}
135 135
 }
Please login to merge, or discard this patch.