-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathevent-search-along-path.html
243 lines (216 loc) · 8.94 KB
/
event-search-along-path.html
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
231
232
233
234
235
236
237
238
239
240
241
242
243
<!--/* NODE-RED-CONTRIB-SNAP4CITY-USER
Copyright (C) 2018 DISIT Lab http://www.disit.org - University of Florence
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */-->
<script type="text/javascript">
RED.nodes.registerType('event-search-along-path', {
category: 'S4CSearch',
color: '#FDD0A2',
defaults: {
name: {
value: ""
},
authentication: {
type: "snap4city-authentication",
required: false
},
path: {
value: "",
required: false
},
range: {
value: "",
required: false
},
maxresults: {
value: 100,
required: false,
validate: RED.validators.number()
}
},
outputs: 2,
inputs: 1,
outputLabels: ["service uri array", "geojson result"],
icon: "white-globe.png",
label: function () {
return this.name || "event-search-along-path";
},
oneditprepare: function () {
$.ajax({
url: "s4c/js/leaflet.js",
async: false,
dataType: "script"
});
$.ajax({
url: "s4c/js/leaflet.draw.js",
async: false,
dataType: "script"
});
node = this;
map = L.map('node-input-map').setView([43.78, 11.23], 9);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
window.node_input_map = map;
var mapLayers = {};
drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);
var editControl = new L.Control.Draw({
draw: false,
edit: {
featureGroup: drawnItems
}
});
map.addControl(editControl);
drawControl = new L.Control.Draw({
draw: {
position: 'topleft',
polygon: false,
rectangle: false,
marker: false,
circlemarker: false,
circle: false
}
});
map.addControl(drawControl);
L.control.layers(mapLayers, {
'drawlayer': drawnItems
}, {
collapsed: true
}).addTo(map);
map.on(L.Draw.Event.CREATED, function (e) {
var fence = e.layer;
fence.nodeID = node.id;
if (drawnItems.hasLayer(fence) == false) {
drawnItems.addLayer(fence);
}
drawControl.remove();
polygons = {};
drawnItems.eachLayer(function (layer) {
polygons[layer.nodeID] = layer.toGeoJSON();
});
$("#node-input-path").val(polygons[node.id].geometry.type.toUpperCase() + JSON.stringify(
polygons[node.id].geometry.coordinates).replace(/\],\[/g, "&").replace(
/,/g, " ").replace(/\[\[/g, "(").replace(/\]\]/g, ")").replace(/&/g,
","));
});
map.on('draw:edited', function (e) {
var fences = e.layers;
fences.eachLayer(function (fence) {
fence.shape = "geofence";
if (drawnItems.hasLayer(fence) == false) {
drawnItems.addLayer(fence);
}
});
polygons = {};
drawnItems.eachLayer(function (layer) {
polygons[layer.nodeID] = layer.toGeoJSON();
});
$("#node-input-path").val(polygons[node.id].geometry.type.toUpperCase() + JSON.stringify(
polygons[node.id].geometry.coordinates).replace(/\],\[/g, "&").replace(
/,/g, " ").replace(/\[\[/g, "(").replace(/\]\]/g, ")").replace(/&/g,
","));
});
map.on('draw:deleted', function (e) {
drawControl.addTo(map);
$("#node-input-path").val("");
});
},
oneditresize: function () {
if (window.node_input_map) {
window.node_input_map.invalidateSize(true);
}
}
});
</script>
<script type="text/x-red" data-template-name="event-search-along-path">
<div class="form-row" id="rowAuthentication">
<label for="node-input-authentication">Authentication</label>
<input type="text" id="node-input-authentication">
</div>
<div class="form-tips" id="tipAuthentication" style="margin-bottom: 10px;">
If you have private data and you want to access them, you must have to insert you account data. You can register for one account
<a href="https://www.snap4city.org"
target="_blank">here</a>.
</div>
<div class="form-row">
<label for="node-input-name">Name</label>
<input type="text" autocomplete="off" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-range">Range</label>
<select id="node-input-range">
<option value="day">Day</option>
<option value="week">Week</option>
<option value="month">Month</option>
</select>
</div>
<div class="form-row">
<label for="node-input-maxresults">Max Results</label>
<select id="node-input-maxresults">
<option value="100">100</option>
<option value="200">200</option>
<option value="500">500</option>
<option value="1000">1000</option>
<option value="2000">2000</option>
<option value="0">All</option>
</select>
</div>
<div class="form-row">
<label for="node-input-path">Path</label>
<input type="text" autocomplete="off" id="node-input-path" placeholder="Path" disabled>
</div>
<div class="form-row">
<link rel="stylesheet" href="s4c/css/leaflet.css" />
<link rel="stylesheet" href="s4c/css/leaflet.draw.css" />
<div id="node-input-map" style="width: 80%; height: 300px"></div>
</div>
</script>
<script type="text/x-red" data-help-name="event-search-along-path">
<p>It allows to retrieve the geolocated events in a given temporal range (day, week or month).</p>
<h3>Inputs</h3>
A JSON with these parameters:
<dl class="message-properties">
<dt>path
<span class="property-type">string</span>
</dt>
<dd> "<WKT_string>” a described as Well Known Text</dd>
<dt>range
<span class="property-type">string</span>
</dt>
<dd> time range for the events to be retrieved, it can be ‘day’ for the events of the day of the request, ‘week’ for the
events in the next 7 days or ‘month’ for the events in the next 30 days (if omitted ‘day’ is assumed).
<dt>maxresults
<span class="property-type">number</span>
</dt>
<dd> maximum number of results to be returned (if parameter is missing 100 is assumed), if it is 0 all results are
returned
</dd>
</dl>
<h3>Outputs</h3>
<ol class="node-ports">
<li>ServiceUri Array
<dl class="message-properties">
<dd> Returns an array containing the servicesUri of each service found</dd>
</dl>
</li>
<li>GeoJSON Results
<dl class="message-properties">
<dd> the results format is a GeoJSON “FeatureCollection” with the matching events. For each “Feature” a set of
properties is provided.d</dd>
</dl>
</li>
</ol>
<h3>Details</h3>
<p>The node can receive a JSON with the parameters described in the Inputs section and with them generate the output JSON.
If the values are not present in the input JSON, these are read by those in the configuration. If they are not present
in either part, an error is generated for the necessary parameters.</p>
</script>