/
GenerateSampleData.html
357 lines (295 loc) · 10.1 KB
/
GenerateSampleData.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes">
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>Generate Tour Planning Sample Data</title>
<link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.1/mapsjs-ui.css" />
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-core.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-service.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-ui.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-mapevents.js"></script>
<body >
<input type="button" id='generateRandomData' onclick="generateRandomData()" value='Generate Random Data'>
<div id="mapContainer" style="width:93vw; height:93vh;"></div>
<script type="text/javascript" >
const initials = {
attribution: 'WaliedCheetos - © HERE 2021',
hereCredentials : {
id: 'Lrw0yF4Z4nFpEe7jJxcd',
code: '9zhfUoi6kIHQqt85SunXuw',
apikey: 'pmYeJOpIGhJHSyyizwSKKPJoAHdjJ_bj12yfckgiT4E'
},
mapCenter : {
lat: 24.67684,
lng: 46.69142,
zoom: 7,
text: 'Riyadh, KSA'
}
}
var pickUp = {
"times": [
[
"2021-11-11T07:00:00Z",
"2021-11-11T07:30:00Z"
]
],
"location": {
"lat": 0,
"lng": 0
},
"duration": 180,
"demand": [1],
"tag": "WaliedCheetos"
};
var tourPlanning_Job = {
"id": "job_00",
"places": {
"pickups":[
{
"times":[
[
"2021-11-11T07:00:00Z",
"2021-11-11T07:30:00Z"
]
],
"location":{
"lat":0,
"lng":0
},
"duration":180,
"demand":[
1
],
"tag":"WaliedCheetos"
}
],
"deliveries": [
{
"times": [
[
"2021-11-11T07:30:00Z",
"2021-11-11T08:00:00Z"
]
],
"location": {
"lat": 24.6892,
"lng": 46.69947
},
"duration": 10,
"demand": [
1
],
"tag":"WaliedCheetos"
}
]
},
"skills": [
"students"
],
"priority": 2
};
/**
* An event listener is added to listen to tap events on the map.
* Clicking on the map displays an alert box containing the latitude and longitude
* of the location pressed.
* @param {H.Map} map A HERE Map instance within the application
*/
function setUpClickListener(map) {
// Attach an event listener to map display
// obtain the coordinates and display in an alert box.
map.addEventListener('tap', function (evt) {
var coord = map.screenToGeo(evt.currentPointer.viewportX,
evt.currentPointer.viewportY);
pickUp.location.lat= Math.abs(coord.lat.toFixed(4));
pickUp.location.lng = Math.abs(coord.lng.toFixed(4));
var x = JSON.stringify(pickUp);
logEvent('Clicked at ' + Math.abs(coord.lat.toFixed(4)) +
((coord.lat > 0) ? 'N' : 'S') +
' ' + Math.abs(coord.lng.toFixed(4)) +
((coord.lng > 0) ? 'E' : 'W'));
});
}
/**
* Boilerplate map initialization code starts below:
*/
//Step 1: initialize communication with the platform
// In your own code, replace variable window.apikey with your own apikey
var platform = new H.service.Platform({
apikey: initials.hereCredentials.apikey
});
var defaultLayers = platform.createDefaultLayers();
//Step 2: initialize a map
var map = new H.Map(document.getElementById('mapContainer'),
defaultLayers.vector.normal.map,{
center: {lat: initials.mapCenter.lat, lng: initials.mapCenter.lng},
zoom: initials.mapCenter.zoom,
pixelRatio: window.devicePixelRatio || 1
});
// add a resize listener to make sure that the map occupies the whole container
window.addEventListener('resize', () => map.getViewPort().resize());
//Step 3: make the map interactive
// MapEvents enables the event system
// Behavior implements default interactions for pan/zoom (also on mobile touch environments)
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
// Create the default UI components
var ui = H.ui.UI.createDefault(map, defaultLayers);
var markers = [];
var pickUps = [];
var tourPlanning_Jobs = [];
// create the icon that's reused for any point features to be added on the map
var svg =
'<svg xmlns="http://www.w3.org/2000/svg" width="28px" height="36px">' +
'<path d="M 19 31 C 19 32.7 16.3 34 13 34 C 9.7 34 7 32.7 7 31 C 7 29.3 9.7 28 13 28 C 16.3 28 19' +
' 29.3 19 31 Z" fill="#000" fill-opacity=".2"/>' +
'<path d="M 13 0 C 9.5 0 6.3 1.3 3.8 3.8 C 1.4 7.8 0 9.4 0 12.8 C 0 16.3 1.4 19.5 3.8 21.9 L 13 31 L 22.2' +
' 21.9 C 24.6 19.5 25.9 16.3 25.9 12.8 C 25.9 9.4 24.6 6.1 22.1 3.8 C 19.7 1.3 16.5 0 13 0 Z" fill="#fff"/>' +
'<path d="M 13 2.2 C 6 2.2 2.3 7.2 2.1 12.8 C 2.1 16.1 3.1 18.4 5.2 20.5 L 13 28.2 L 20.8 20.5 C' +
' 22.9 18.4 23.8 16.2 23.8 12.8 C 23.6 7.07 20 2.2 13 2.2 Z" fill="#090"/>' +
'</svg>';
var options = {
'size': new H.math.Size(28, 36),
'anchor': new H.math.Point(14, 32),
'hitArea': new H.map.HitArea(
H.map.HitArea.ShapeType.POLYGON, [0, 16, 0, 7, 8, 0, 18, 0, 26, 7, 26, 16, 18, 34, 8, 34])
};
icon = new H.map.Icon(svg, options);
icon2 = new H.map.Icon(svg.replace('#090', '#009'), options);
function isPrime(value) {
for(var i = 2; i < value; i++) {
if(value % i === 0) {
return false;
}
}
return value > 1;
}
function generateRandomData(){
try {
// create SVG Dom Icon
var svg = `<svg xmlns="http://www.w3.org/2000/svg" class="svg-icon" width="10px" height="10px">
<circle cx="5" cy="5" r="4" fill="rgb(250, 127, 0)" stroke-width="1" stroke="black" opacity="1"/>
</svg>`;
var domIcon = new H.map.DomIcon(svg);
if (markers.length > 0) {
map.removeObjects(markers);
}
var geojson = {};
geojson['type'] = 'FeatureCollection';
geojson['features'] = [];
for (let index = 0; index < 60; index++) {
// get random position 0 - 30km from map's center in random direction
let randomPoint = map.getCenter().walk(Math.random() * 360, Math.random() * 17000);
// // get random position 0 - 1.3km from map's center in random direction
// let randomPoint = map.getCenter().walk(Math.random() * 360, Math.random() * 1300);
markers.push(new H.map.DomMarker(randomPoint, {
icon: domIcon
// icon: icon
}));
//#region tour planning jobs
var x = {
"id": "job_00",
"places": {
"pickups":[
{
"times":[
[
"2021-11-11T07:00:00Z",
"2021-11-11T07:30:00Z"
]
],
"location":{
"lat":0,
"lng":0
},
"duration":120,
"demand":[
1
],
"tag":"WaliedCheetos"
}
],
"deliveries": [
{
"times": [
[
"2021-11-11T07:30:00Z",
"2021-11-11T08:00:00Z"
]
],
"location": {
"lat": 24.6892,
"lng": 46.69947
},
"duration": 13,
"demand": [
1
],
"tag":"WaliedCheetos"
}
]
},
"skills": [
"students"
],
"priority": 2
};
x.id = `students_Home_2_School_${index+1}`;
x.places["pickups"][0].location.lat = parseFloat(randomPoint.lat);
x.places["pickups"][0].location.lng = parseFloat(randomPoint.lng);
tourPlanning_Jobs.push(x);
//#endregion
//#region geojson feature
var observationType;
if (isPrime(index)) {
observationType = 'fine';
} else if( index % 2 == 0) {
observationType = 'warning';
}else{
observationType = 'paid';
}
var datatimeCurrent = new Date();
var newFeature = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [parseFloat(randomPoint.lat), parseFloat(randomPoint.lng)]
},
"properties": {
'id': index,
'name' : 'WaliedCheetos',
'datetime' : datatimeCurrent.toISOString(),
'type' : observationType,
'officer' : 'WaliedCheetos',
'zone_number' : 'xyz',
'plate' : 'x-xyz',
'start' : '',
'end' : ''
}
}
geojson['features'].push(newFeature);
//#endregion
}
// add markers to map
map.addObjects(markers);
console.log(JSON.stringify(tourPlanning_Jobs));
//console.log(JSON.stringify(geojson));
} catch (error) {
console.error(`WaliedCheetos - Exception: ${error}`);
}
}
// Step 4: create custom logging facilities
// var logContainer = document.createElement('ul');
// logContainer.className ='log';
// logContainer.innerHTML = '<li class="log-entry">Try clicking on the map</li>';
// map.getElement().appendChild(logContainer);
// Helper for logging events
function logEvent(str) {
// var entry = document.createElement('li');
// entry.className = 'log-entry';
// entry.textContent = str;
// logContainer.insertBefore(entry, logContainer.firstChild);
}
// setUpClickListener(map);
</script>
</body>
</html>