-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirst-version.js
101 lines (80 loc) · 2.33 KB
/
first-version.js
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
const points = [{
points: {
lat: 49.1944522,
lon: 16.5995939
},
title: 'Hrad Špilberk'
},
{
points: {
lat: 49.1905822,
lon: 16.6128025
},
title: 'Brno hlavní nádraží'
}
];
let actualLayer;
const center = SMap.Coords.fromWGS84(16.5957639, 49.1994337);
let m = new SMap(JAK.gel("m"), center, 14);
m.addDefaultLayer(SMap.DEF_BASE).enable();
m.addDefaultControls();
let layer = new SMap.Layer.Marker();
m.redraw();
points.forEach((e, i) => {
let c = SMap.Coords.fromWGS84(e.points.lon, e.points.lat);
let pointMarker = new SMap.Marker(c, i, {
title: e.title
});
layer.addMarker(pointMarker);
})
m.addLayer(layer);
layer.enable();
var signals = m.getSignals();
m.setCursor("pointer");
let selectedCoords = []
let geoLayer = new SMap.Layer.Geometry();
m.addLayer(geoLayer);
geoLayer.enable();
let hintLayer = new SMap.Layer.Geometry();
m.addLayer(hintLayer);
hintLayer.enable();
const kliknuto = function (signal) {
if (actualLayer == null) {
const event = signal.data.event;
const coords = SMap.Coords.fromEvent(event, m);
new SMap.Geocoder.Reverse(coords, odpoved);
}
}
const odpoved = function (geocoder) {
const geo = geocoder.getResults();
selectedCoords.push(SMap.Coords.fromWGS84(geo.coords.x, geo.coords.y));
const polyOptions = {
color: "#0f0"
};
geoLayer.clear();
geoLayer.removeAll();
/*CREATE POLYGON*/
const polygon = new SMap.Geometry(SMap.GEOMETRY_POLYGON, null, selectedCoords, polyOptions);
geoLayer.addGeometry(polygon);
/* HINT PATH */
JAK.Events.addListener(JAK.gel("m"), "mousemove", (event) => {
var tmpData = SMap.Coords.fromEvent(event, m);
hintLayer.clear();
hintLayer.removeAll();
hintLayer.redraw();
const lastPoints = [selectedCoords[selectedCoords.length - 1], tmpData]
const hintPolygon = new SMap.Geometry(SMap.GEOMETRY_POLYGON, null, lastPoints, polyOptions);
hintLayer.addGeometry(hintPolygon);
});
signals.addListener(window, "map-click", kliknuto);
if (selectedCoords.length > 2) {
points.forEach((e) => {
const editedPoints = SMap.Coords.fromWGS84(e.points.lon, e.points.lat);
if (SMap.Util.pointInPolygon([editedPoints.x, editedPoints.y], selectedCoords.map(Object
.values))) {
alert(e.title + " PATŘÍ")
}
})
}
}
signals.addListener(window, "map-click", kliknuto);