forked from jbelien/MapFile-Generator
/
layer.php
230 lines (206 loc) · 16.2 KB
/
layer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php
session_start();
$settings = parse_ini_file('settings.ini');
$mapscript = extension_loaded('mapscript');
$tmp = sys_get_temp_dir();
if (!file_exists($tmp.'/mapserver') || !is_dir($tmp.'/mapserver')) mkdir($tmp.'/mapserver');
if (isset($settings['library']) && file_exists($settings['library']) && is_dir($settings['library'])) {
require($settings['library'].'/map.php');
require($settings['library'].'/legend.php');
require($settings['library'].'/scalebar.php');
require($settings['library'].'/layer.php');
require($settings['library'].'/class.php');
require($settings['library'].'/style.php');
require($settings['library'].'/label.php');
}
if (!$mapscript && !class_exists('MapFile\Map')) $error = 'This application needs <a href="http://www.mapserver.org/mapscript/php/" target="_blank">MapScript</a> or <a href="https://github.com/jbelien/MapFile-PHP-Library" target="_blank">MapFile-PHP-Library</a> ! Enable MapScript or download and link MapFile-PHP-Library (see <a href="https://github.com/jbelien/MapFile-Generator#libraries" target="_blank">documentation</a>).';
require_once('fn.php');
$source = NULL; $mapfile = NULL;
if (isset($_SESSION['mapfile-generator']['source']) && file_exists($_SESSION['mapfile-generator']['source'])) $source = $_SESSION['mapfile-generator']['source'];
if (isset($_SESSION['mapfile-generator']['mapfile']) && file_exists($_SESSION['mapfile-generator']['mapfile'])) $mapfile = $_SESSION['mapfile-generator']['mapfile'];
if (/*is_null($source) || */is_null($mapfile)) { header('Location:index.php'); exit(); }
$meta = mapfile_getmeta($mapfile);
$layers = mapfile_getlayers($mapfile);
if (isset($_GET['layer'])) $layer = $layers[intval($_GET['layer'])];
if ($mapscript && isset($_POST['action']) && $_POST['action'] == 'save') {
try {
$map = new mapObj($mapfile);
if (isset($_GET['layer']))
$layer = $map->getLayer(intval($_GET['layer']));
else
$layer = new layerObj($map);
$layer->tileitem = NULL;
$layer->type = intval($_POST['type']);
$layer->name = trim($_POST['name']);
$layer->setProjection($_POST['projection']);
$layer->setConnectionType($_POST['connectiontype']);
$layer->connection = $_POST['connection'];
$layer->data = $_POST['data'];
$layer->filteritem = $_POST['filteritem'];
$layer->setFilter($_POST['filter']);
$layer->group = $_POST['group'];
$layer->free(); unset($layer);
$map->save($mapfile);
$map->free(); unset($map);
header('Location: index.php');
exit();
} catch (MapScriptException $e) {
$error = $e->getMessage();
}
}
else if (isset($_POST['action']) && $_POST['action'] == 'save') {
try {
$map = new MapFile\Map($mapfile);
if (isset($_GET['layer']))
$layer = $map->getLayer(intval($_GET['layer']));
else {
$layer = new MapFile\Layer();
$map->addLayer($layer);
}
$layer->type = intval($_POST['type']);
$layer->name = trim($_POST['name']);
$layer->projection = $_POST['projection'];
$layer->connectiontype = $_POST['connectiontype'];
$layer->connection = $_POST['connection'];
$layer->data = $_POST['data'];
$layer->filteritem = $_POST['filteritem'];
$layer->filter = $_POST['filter'];
$layer->group = $_POST['group'];
$map->save($mapfile);
header('Location: index.php');
exit();
} catch (MapFile\Exception $e) {
$error = $e->getMessage();
}
}
page_header((isset($layer) ? 'Layer: '.$layer['name'] : 'New layer'));
?>
<div class="container">
<h1>Map: <a href="index.php"><?= htmlentities($meta['name']) ?></a></h1>
<h2><?= (isset($layer) ? 'Layer: '.htmlentities($layer['name']) : 'New layer') ?></h2>
<?php if (isset($error)) echo '<div class="alert alert-danger" role="alert"><strong>Error :</strong> '.$error.'</div>'; ?>
<form class="form-horizontal" action="layer.php<?= (isset($layer) ? '?layer='.intval($_GET['layer']) : '') ?>" method="post">
<div class="form-group">
<label for="inputName" class="col-sm-2 control-label">Name</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="inputName" name="name"<?= (isset($layer) ? ' value="'.htmlentities($layer['name']).'"' : '') ?>>
</div>
<label for="inputGroup" class="col-sm-1 control-label">Group</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="inputGroup" name="group"<?= (isset($layer) ? ' value="'.htmlentities($layer['group']).'"' : '') ?>>
</div>
</div>
<div class="form-group">
<label for="selectStatus" class="col-sm-2 control-label">Status</label>
<div class="col-sm-10">
<select class="form-control" id="selectStatus" name="status">
<option value="<?= ($mapscript ? MS_DEFAULT : MapFile\Layer::STATUS_DEFAULT) ?>"<?= (isset($layer) && $layer['status'] == ($mapscript ? MS_DEFAULT : MapFile\Layer::STATUS_DEFAULT) ? ' selected="selected"' : '') ?>>DEFAULT</option>
<option value="<?= ($mapscript ? MS_ON : MapFile\Layer::STATUS_ON ) ?>"<?= (isset($layer) && $layer['status'] == ($mapscript ? MS_ON : MapFile\Layer::STATUS_ON ) ? ' selected="selected"' : '') ?>>ON</option>
<option value="<?= ($mapscript ? MS_OFF : MapFile\Layer::STATUS_OFF ) ?>"<?= (isset($layer) && $layer['status'] == ($mapscript ? MS_OFF : MapFile\Layer::STATUS_OFF ) ? ' selected="selected"' : '') ?>>OFF</option>
</select>
</div>
</div>
<div class="form-group">
<label for="selectType" class="col-sm-2 control-label">Type</label>
<div class="col-sm-10">
<select class="form-control" id="selectType" name="type">
<?php if ($mapscript) { ?>
<option value="<?= MS_LAYER_CHART ?>"<?= (isset($layer) && $layer['type'] == MS_LAYER_CHART ? ' selected="selected"' : '') ?> disabled="disabled">Chart (not yet supported)</option>
<option value="<?= MS_LAYER_CIRCLE ?>"<?= (isset($layer) && $layer['type'] == MS_LAYER_CIRCLE ? ' selected="selected"' : '') ?> disabled="disabled">Circle (not yet supported)</option>
<option value="<?= MS_LAYER_LINE ?>"<?= (isset($layer) && $layer['type'] == MS_LAYER_LINE ? ' selected="selected"' : '') ?>>Line</option>
<option value="<?= MS_LAYER_POINT ?>"<?= (isset($layer) && $layer['type'] == MS_LAYER_POINT ? ' selected="selected"' : '') ?>>Point</option>
<option value="<?= MS_LAYER_POLYGON ?>"<?= (isset($layer) && $layer['type'] == MS_LAYER_POLYGON ? ' selected="selected"' : '') ?>>Polygon</option>
<option value="<?= MS_LAYER_QUERY ?>"<?= (isset($layer) && $layer['type'] == MS_LAYER_QUERY ? ' selected="selected"' : '') ?> disabled="disabled">Query (not yet supported)</option>
<option value="<?= MS_LAYER_RASTER ?>"<?= (isset($layer) && $layer['type'] == MS_LAYER_RASTER ? ' selected="selected"' : '') ?>>Raster</option>
<option value="<?= MS_LAYER_TILEINDEX ?>"<?= (isset($layer) && $layer['type'] == MS_LAYER_TILEINDEX ? ' selected="selected"' : '') ?> disabled="disabled">Tile index (not yet supported)</option>
<?php } else { ?>
<option value="<?= MapFile\Layer::TYPE_CHART ?>"<?= (isset($layer) && $layer['type'] == MapFile\Layer::TYPE_CHART ? ' selected="selected"' : '') ?> disabled="disabled">Chart (not yet supported)</option>
<option value="<?= MapFile\Layer::TYPE_CIRCLE ?>"<?= (isset($layer) && $layer['type'] == MapFile\Layer::TYPE_CIRCLE ? ' selected="selected"' : '') ?> disabled="disabled">Circle (not yet supported)</option>
<option value="<?= MapFile\Layer::TYPE_LINE ?>"<?= (isset($layer) && $layer['type'] == MapFile\Layer::TYPE_LINE ? ' selected="selected"' : '') ?>>Line</option>
<option value="<?= MapFile\Layer::TYPE_POINT ?>"<?= (isset($layer) && $layer['type'] == MapFile\Layer::TYPE_POINT ? ' selected="selected"' : '') ?>>Point</option>
<option value="<?= MapFile\Layer::TYPE_POLYGON ?>"<?= (isset($layer) && $layer['type'] == MapFile\Layer::TYPE_POLYGON ? ' selected="selected"' : '') ?>>Polygon</option>
<option value="<?= MapFile\Layer::TYPE_QUERY ?>"<?= (isset($layer) && $layer['type'] == MapFile\Layer::TYPE_QUERY ? ' selected="selected"' : '') ?> disabled="disabled">Query (not yet supported)</option>
<option value="<?= MapFile\Layer::TYPE_RASTER ?>"<?= (isset($layer) && $layer['type'] == MapFile\Layer::TYPE_RASTER ? ' selected="selected"' : '') ?>>Raster</option>
<option value="<?= MapFile\Layer::TYPE_TILEINDEX ?>"<?= (isset($layer) && $layer['type'] == MapFile\Layer::TYPE_TILEINDEX ? ' selected="selected"' : '') ?> disabled="disabled">Tile index (not yet supported)</option>
<?php } ?>
</select>
</div>
</div>
<div class="form-group">
<label for="selectProjection" class="col-sm-2 control-label">Projection</label>
<div class="col-sm-10">
<select class="form-control" id="selectProjection" name="projection">
<option value="epsg:3857" <?= (isset($layer) && $layer['projection'] == 'epsg:3857' ? ' selected="selected"' : '') ?>>EPSG:3857 - Spherical Mercator</option>
<option value="epsg:4326" <?= (isset($layer) && $layer['projection'] == 'epsg:4326' ? ' selected="selected"' : '') ?>>EPSG:4326 - WGS 84</option>
<option value="epsg:31370" <?= (isset($layer) && $layer['projection'] == 'epsg:31370' ? ' selected="selected"' : '') ?>>EPSG:31370 - Belge 1972 / Belgian Lambert 72</option>
<option value="epsg:900913"<?= (isset($layer) && $layer['projection'] == 'epsg:900913' ? ' selected="selected"' : '') ?>>EPSG:900913 - Spherical Mercator</option>
</select>
</div>
</div>
<div class="form-group">
<label for="selectConnectionType" class="col-sm-2 control-label">Connection Type</label>
<div class="col-sm-10">
<select class="form-control" id="selectConnectionType" name="connectiontype">
<?php if ($mapscript) { ?>
<option value="<?= MS_INLINE ?>"<?= (isset($layer) && $layer['connectiontype'] == MS_INLINE ? ' selected="selected"' : '') ?>>Inline</option>
<option value="<?= MS_GRATICULE ?>"<?= (isset($layer) && $layer['connectiontype'] == MS_GRATICULE ? ' selected="selected"' : '') ?> disabled="disabled">Graticule (not yet supported)</option>
<option value="<?= MS_OGR ?>"<?= (isset($layer) && $layer['connectiontype'] == MS_OGR ? ' selected="selected"' : '') ?>>OGR</option>
<option value="<?= MS_ORACLESPATIAL ?>"<?= (isset($layer) && $layer['connectiontype'] == MS_ORACLESPATIAL ? ' selected="selected"' : '') ?> disabled="disabled">OracleSpatial (not yet supported)</option>
<option value="<?= MS_PLUGIN ?>"<?= (isset($layer) && $layer['connectiontype'] == MS_PLUGIN ? ' selected="selected"' : '') ?> disabled="disabled">Plugin (not yet supported)</option>
<option value="<?= MS_POSTGIS ?>"<?= (isset($layer) && $layer['connectiontype'] == MS_POSTGIS ? ' selected="selected"' : '') ?> disabled="disabled">PostGIS (not yet supported)</option>
<option value="<?= MS_RASTER ?>"<?= (isset($layer) && $layer['connectiontype'] == MS_RASTER ? ' selected="selected"' : '') ?> disabled="disabled">Raster (not yet supported)</option>
<option value="<?= MS_SDE ?>"<?= (isset($layer) && $layer['connectiontype'] == MS_SDE ? ' selected="selected"' : '') ?> disabled="disabled">SDE (not yet supported)</option>
<option value="<?= MS_SHAPEFILE ?>"<?= (isset($layer) && $layer['connectiontype'] == MS_SHAPEFILE ? ' selected="selected"' : '') ?>>Shapefile</option>
<?php /*<option value="<?= MS_TILED_OGR ?>"<?= (isset($layer) && $layer['connectiontype'] == MS_TILED_OGR ? ' selected="selected"' : '') ?>>Tiled OGR</option> */ ?>
<option value="<?= MS_TILED_SHAPEFILE ?>"<?= (isset($layer) && $layer['connectiontype'] == MS_TILED_SHAPEFILE ? ' selected="selected"' : '') ?>>Tiled shapefile</option>
<option value="<?= MS_UNION ?>"<?= (isset($layer) && $layer['connectiontype'] == MS_UNION ? ' selected="selected"' : '') ?> disabled="disabled">Union (not yet supported)</option>
<option value="<?= MS_WFS ?>"<?= (isset($layer) && $layer['connectiontype'] == MS_WFS ? ' selected="selected"' : '') ?>>WFS</option>
<option value="<?= MS_WMS ?>"<?= (isset($layer) && $layer['connectiontype'] == MS_WMS ? ' selected="selected"' : '') ?>>WMS</option>
<?php } else { ?>
<option value="<?= MapFile\Layer::CONNECTIONTYPE_CONTOUR ?>"<?= (isset($layer) && $layer['connectiontype'] == MapFile\Layer::CONNECTIONTYPE_CONTOUR ? ' selected="selected"' : '') ?> disabled="disabled">Contour (not yet supported)</option>
<option value="<?= MapFile\Layer::CONNECTIONTYPE_LOCAL ?>"<?= (isset($layer) && $layer['connectiontype'] == MapFile\Layer::CONNECTIONTYPE_LOCAL ? ' selected="selected"' : '') ?>>Local</option>
<option value="<?= MapFile\Layer::CONNECTIONTYPE_OGR ?>"<?= (isset($layer) && $layer['connectiontype'] == MapFile\Layer::CONNECTIONTYPE_OGR ? ' selected="selected"' : '') ?>>OGR</option>
<option value="<?= MapFile\Layer::CONNECTIONTYPE_ORACLESPATIAL ?>"<?= (isset($layer) && $layer['connectiontype'] == MapFile\Layer::CONNECTIONTYPE_ORACLESPATIAL ? ' selected="selected"' : '') ?> disabled="disabled">OracleSpatial (not yet supported)</option>
<option value="<?= MapFile\Layer::CONNECTIONTYPE_PLUGIN ?>"<?= (isset($layer) && $layer['connectiontype'] == MapFile\Layer::CONNECTIONTYPE_PLUGIN ? ' selected="selected"' : '') ?> disabled="disabled">Plugin (not yet supported)</option>
<option value="<?= MapFile\Layer::CONNECTIONTYPE_POSTGIS ?>"<?= (isset($layer) && $layer['connectiontype'] == MapFile\Layer::CONNECTIONTYPE_POSTGIS ? ' selected="selected"' : '') ?> disabled="disabled">PostGIS (not yet supported)</option>
<option value="<?= MapFile\Layer::CONNECTIONTYPE_SDE ?>"<?= (isset($layer) && $layer['connectiontype'] == MapFile\Layer::CONNECTIONTYPE_CONTOUR ? ' selected="selected"' : '') ?> disabled="disabled">SDE (not yet supported)</option>
<option value="<?= MapFile\Layer::CONNECTIONTYPE_UNION ?>"<?= (isset($layer) && $layer['connectiontype'] == MapFile\Layer::CONNECTIONTYPE_SDE ? ' selected="selected"' : '') ?> disabled="disabled">Union (not yet supported)</option>
<option value="<?= MapFile\Layer::CONNECTIONTYPE_UVRASTER ?>"<?= (isset($layer) && $layer['connectiontype'] == MapFile\Layer::CONNECTIONTYPE_UVRASTER ? ' selected="selected"' : '') ?> disabled="disabled">UV Raster (not yet supported)</option>
<option value="<?= MapFile\Layer::CONNECTIONTYPE_WFS ?>"<?= (isset($layer) && $layer['connectiontype'] == MapFile\Layer::CONNECTIONTYPE_WFS ? ' selected="selected"' : '') ?>>WFS</option>
<option value="<?= MapFile\Layer::CONNECTIONTYPE_WMS ?>"<?= (isset($layer) && $layer['connectiontype'] == MapFile\Layer::CONNECTIONTYPE_WMS ? ' selected="selected"' : '') ?>>WMS</option>
<?php } ?>
</select>
</div>
</div>
<div class="form-group">
<label for="inputConnection" class="col-sm-2 control-label">Connection</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputConnection" name="connection"<?= (isset($layer) ? ' value="'.htmlentities($layer['connection']).'"' : '') ?>>
</div>
</div>
<div class="form-group">
<label for="inputData" class="col-sm-2 control-label">Data</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputData" name="data"<?= (isset($layer) ? ' value="'.htmlentities($layer['data']).'"' : '') ?>>
</div>
</div>
<div class="form-group">
<label for="inputFilterItem" class="col-sm-2 control-label">Filter Item</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputFilterItem" name="filteritem"<?= (isset($layer) ? ' value="'.htmlentities($layer['filteritem']).'"' : '') ?>>
</div>
</div>
<div class="form-group">
<label for="inputFilter" class="col-sm-2 control-label">Filter</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputFilter" name="filter"<?= (isset($layer) ? ' value="'.htmlentities($layer['filter']).'"' : '') ?>>
</div>
</div>
<div class="form-group text-center">
<button type="submit" class="btn btn-primary" name="action" value="save"><i class="fa fa-floppy-o"></i> Save</button>
<a href="index.php" class="btn btn-default"><i class="fa fa-backward"></i> Cancel</a>
</div>
</form>
</div>
<?php
page_footer();