1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright (c) 2016 Mark C. Prins <[email protected]> |
4
|
|
|
* |
5
|
|
|
* Permission to use, copy, modify, and distribute this software for any |
6
|
|
|
* purpose with or without fee is hereby granted, provided that the above |
7
|
|
|
* copyright notice and this permission notice appear in all copies. |
8
|
|
|
* |
9
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
10
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
11
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
12
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
13
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
14
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
15
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
16
|
|
|
*/ |
17
|
|
|
if (! defined ( 'DOKU_INC' )) |
18
|
|
|
die (); |
19
|
|
|
|
20
|
|
|
if (! defined ( 'DOKU_LF' )) |
21
|
|
|
define ( 'DOKU_LF', "\n" ); |
22
|
|
|
if (! defined ( 'DOKU_TAB' )) |
23
|
|
|
define ( 'DOKU_TAB', "\t" ); |
24
|
|
|
if (! defined ( 'DOKU_PLUGIN' )) |
25
|
|
|
define ( 'DOKU_PLUGIN', DOKU_INC . 'lib/plugins/' ); |
|
|
|
|
26
|
|
|
|
27
|
|
|
require_once DOKU_PLUGIN . 'syntax.php'; |
28
|
|
|
/** |
29
|
|
|
* adds a WMS 1.1.1 layer to your map. |
30
|
|
|
*/ |
31
|
|
|
class syntax_plugin_openlayersmapoverlays_searchlayer extends DokuWiki_Syntax_Plugin { |
|
|
|
|
32
|
|
|
private $dflt = array ( |
33
|
|
|
'id' => 'olmap', |
34
|
|
|
'name' => '', |
35
|
|
|
'search' => '', |
36
|
|
|
'opacity' => 0.8, |
37
|
|
|
'attribution' => '', |
38
|
|
|
'visible' => false, |
39
|
|
|
'layers' => '', |
40
|
|
|
'version' => '1.1.1', |
41
|
|
|
'format' => 'image/png', |
42
|
|
|
'transparent' => 'true' |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* (non-PHPdoc) |
47
|
|
|
* |
48
|
|
|
* @see DokuWiki_Syntax_Plugin::getPType() |
49
|
|
|
*/ |
50
|
|
|
public function getPType() { |
51
|
|
|
return 'block'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* (non-PHPdoc) |
56
|
|
|
* |
57
|
|
|
* @see DokuWiki_Syntax_Plugin::getType() |
58
|
|
|
*/ |
59
|
|
|
public function getType() { |
60
|
|
|
// return 'FIXME: container|baseonly|formatting|substition|protected|disabled|paragraphs'; |
61
|
|
|
return 'baseonly'; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* (non-PHPdoc) |
66
|
|
|
* |
67
|
|
|
* @see Doku_Parser_Mode::getSort() |
68
|
|
|
*/ |
69
|
|
|
public function getSort() { |
70
|
|
|
return 902; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Connect to our special pattern. |
75
|
|
|
* |
76
|
|
|
* @see Doku_Parser_Mode::connectTo() |
77
|
|
|
*/ |
78
|
|
|
public function connectTo($mode) { |
79
|
|
|
$this->Lexer->addSpecialPattern ( '<olmap_searchlayer ?[^>\n]*>.*?</olmap_searchlayer>', |
80
|
|
|
$mode, 'plugin_openlayersmapoverlays_searchlayer' ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* (non-PHPdoc) |
85
|
|
|
* |
86
|
|
|
* @see DokuWiki_Syntax_Plugin::handle() |
87
|
|
|
*/ |
88
|
|
|
public function handle($match, $state, $pos, Doku_Handler $handler) { |
|
|
|
|
89
|
|
|
$param = array (); |
90
|
|
|
$data = $this->dflt; |
91
|
|
|
|
92
|
|
|
preg_match_all ( '/(\w*)="(.*?)"/us', $match, $param, PREG_SET_ORDER ); |
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
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* (non-PHPdoc) |
107
|
|
|
* |
108
|
|
|
* @see DokuWiki_Syntax_Plugin::render() |
109
|
|
|
*/ |
110
|
|
|
public function render($mode, Doku_Renderer $renderer, $data) { |
|
|
|
|
111
|
|
|
if ($mode != 'xhtml') |
112
|
|
|
return false; |
113
|
|
|
|
114
|
|
|
static $loadedOLlib = false; |
115
|
|
|
if (! $loadedOLlib) { |
116
|
|
|
$renderer->doc .= DOKU_LF . '<script type="text/javascript" src="' . DOKU_BASE . 'lib/plugins/openlayersmapoverlays/lib/layers.js' . '"></script>'; |
|
|
|
|
117
|
|
|
$loadedOLlib = true; |
118
|
|
|
} |
119
|
|
|
// incremented for each olmap_wmslayer tag in the page source |
120
|
|
|
static $overlaynumber = 0; |
121
|
|
|
|
122
|
|
|
list ( $id, $url, $name, $visible ) = $data; |
|
|
|
|
123
|
|
|
$renderer->doc .= DOKU_LF . "<script type='text/javascript'><!--//--><![CDATA[//><!--" . DOKU_LF; |
124
|
|
|
$str = '{'; |
125
|
|
|
foreach ( $data as $key => $val ) { |
126
|
|
|
$str .= "'" . $key . "' : '" . $val . "',"; |
127
|
|
|
} |
128
|
|
|
$str .= "'type':'wms'}"; |
129
|
|
|
$renderer->doc .= "olMapOverlays['wms" . $overlaynumber . "'] = " . $str . ";" . DOKU_LF . "//--><!]]></script>"; |
130
|
|
|
$overlaynumber ++; |
131
|
|
|
return true; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|