-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.ts
100 lines (90 loc) · 3.01 KB
/
map.ts
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
interface Point {
latitude: number;
longitude: number;
number: string;
line: string;
}
interface TargeoMapOptions {
container: string;
z: number;
c: { y: number; x: number };
modArguments: Record<string, any>;
}
declare const Targeo: any;
// Globalne zmienne
let Mapa: any;
let PointsOnMap: any[] = [];
let PointsToRemove: any[] = [];
// Inicjalizacja mapy
function TargeoMapInitialize(): void {
const mapOptions: TargeoMapOptions = {
container: 'TargeoMapContainer',
z: 25,
c: { y: 52.2565055, x: 21.0464574 },
modArguments: {
Ribbon: { controls: ['MapMenu', 'FTS', 'FindRoute'] },
Buildings3D: { disabled: false, on: true },
POI: { disabled: false, submit: true, correct: true, visible: true },
FTS: { disabled: false },
FindRoute: { disabled: false },
Traffic: { disabled: false, visible: false },
Layers: { modes: ['map', 'satellite'] },
},
};
Mapa = new Targeo.Map(mapOptions);
Mapa.initialize();
}
function refreshMap(): void {
fetch('/ajax.php')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
PointsToRemove = PointsOnMap;
PointsOnMap = [];
return response.json();
})
.then((points: Point[]) => {
points.forEach(point => {
const mapPoint = new Targeo.MapObject.Point(
{ y: point.latitude / 1000000, x: point.longitude / 1000000 },
{
imageUrl: 'https://mapa.targeo.pl/i/icons/pins/pin-r.png',
w: 27,
h: 28,
coordsAnchor: { x: 9, y: 25 },
z: {
24: { imageUrl: 'https://mapa.targeo.pl/i/icons/pins/pinbig-r.png', w: 38, h: 39, coordsAnchor: { x: 12, y: 36 } },
},
},
point.number, // ID punktu
{
name: `Linia: ${point.line}, Numer: ${point.number}`,
zIndex: parseInt(point.number, 10),
draggable: false,
balloon: { body: `Linia: ${point.line}, Numer: ${point.number}` },
}
);
PointsOnMap.push(mapPoint);
});
removeAllPoints();
addPointsToMap();
})
.catch(error => console.error('Błąd podczas odświeżania mapy:', error));
}
function addPointsToMap(): void {
PointsOnMap.forEach(point => {
Mapa.getObjectManager().add(point);
});
}
function removeAllPoints(): void {
PointsToRemove.forEach(point => {
Mapa.getObjectManager().remove(point.id);
});
PointsToRemove = [];
}
window.onload = (): void => {
TargeoMapInitialize();
refreshMap();
setInterval(refreshMap, 15000);
};