1
1
<template >
2
- <div :class =" { inactive: store.isColored }" class =" mapcontainer" id =" map" ></div >
3
- <Footer :currentProvider =" provider" :canHistory =" historyready" @history =" historyhandler" :measuretype =" measuretype" >
4
- <button class =" popovercontrol" v-if =" geoavailable" @click.prevent =" resetgeo" :area-label =" $t('showlocation')" :title =" $t('showlocation')" ><font-awesome-icon icon =" fa-solid fa-location-arrow" /></button >
2
+ <div
3
+ :class =" { inactive: store.isColored }"
4
+ class =" mapcontainer"
5
+ id =" map"
6
+ ></div >
7
+ <Footer
8
+ :currentProvider =" provider"
9
+ :canHistory =" historyready"
10
+ @history =" historyhandler"
11
+ :measuretype =" measuretype"
12
+ >
13
+ <button
14
+ class =" popovercontrol"
15
+ v-if =" geoavailable"
16
+ @click.prevent =" resetgeo"
17
+ :area-label =" $t('showlocation')"
18
+ :title =" $t('showlocation')"
19
+ >
20
+ <font-awesome-icon icon =" fa-solid fa-location-arrow" />
21
+ </button >
5
22
</Footer >
6
23
</template >
7
24
8
25
<script >
9
26
import { useStore } from " @/store" ;
27
+ import Footer from " ../components/footer/Footer.vue" ;
10
28
import config from " ../config" ;
11
- import { init , removeMap , setTheme , setview , drawuser } from " ../utils/map/instance" ;
29
+ import {
30
+ drawuser ,
31
+ init ,
32
+ removeMap ,
33
+ setTheme ,
34
+ setview ,
35
+ } from " ../utils/map/instance" ;
12
36
import { init as initMarkers } from " ../utils/map/marker" ;
13
37
import { init as initWind } from " ../utils/map/wind" ;
14
- import Footer from " ../components/footer/Footer.vue" ;
15
38
16
39
export default {
17
40
emits: [" city" , " clickMarker" , " close" ],
18
41
props: [" measuretype" , " historyready" , " historyhandler" ],
19
- components: {Footer},
42
+ components: { Footer },
20
43
data () {
21
44
return {
22
45
store: useStore (),
23
46
locale: localStorage .getItem (" locale" ) || this .$i18n .locale || " en" ,
24
- theme: window ? .matchMedia (" (prefers-color-scheme: light)" ).matches ? " light" : " dark" ,
47
+ theme: window ? .matchMedia (" (prefers-color-scheme: light)" ).matches
48
+ ? " light"
49
+ : " dark" ,
25
50
userposition: null ,
26
51
geoavailable: false ,
27
52
};
28
53
},
29
54
30
55
computed: {
31
- zoom () { return this .store .mapposition .zoom },
32
- lat () { return this .store .mapposition .lat },
33
- lng () { return this .store .mapposition .lng },
34
- provider () { return config .DEFAUL_TYPE_PROVIDER || this .$route .params .provider },
56
+ zoom () {
57
+ return this .store .mapposition .zoom ;
58
+ },
59
+ lat () {
60
+ return this .store .mapposition .lat ;
61
+ },
62
+ lng () {
63
+ return this .store .mapposition .lng ;
64
+ },
65
+ provider () {
66
+ return this .$route .params .provider || config .DEFAUL_TYPE_PROVIDER ;
67
+ },
35
68
},
36
69
37
70
methods: {
@@ -52,66 +85,83 @@ export default {
52
85
53
86
relocatemap (lat , lng , zoom , type ) {
54
87
const options = {
55
- name: " main" ,
56
- params: {
57
- provider: this .provider || config .DEFAUL_TYPE_PROVIDER ,
58
- type: this .$route .params .type || " pm10" ,
59
- zoom: zoom,
60
- lat: lat,
61
- lng: lng,
62
- sensor: this .$route .params .sensor ,
63
- },
64
- }
65
-
88
+ name: " main" ,
89
+ params: {
90
+ provider: this .provider || config .DEFAUL_TYPE_PROVIDER ,
91
+ type: this .$route .params .type || " pm10" ,
92
+ zoom: zoom,
93
+ lat: lat,
94
+ lng: lng,
95
+ sensor: this .$route .params .sensor ,
96
+ },
97
+ };
98
+
66
99
if (this .$router .currentRoute .value .name === " main" ) {
100
+ console .log (options);
67
101
/* added here check for current route is map (main), as it caused problems with other pages */
68
- if (type === ' reload' ) {
69
- this .$router .push (options).catch (e => { console .warn (e) });
102
+ if (type === " reload" ) {
103
+ this .$router .push (options).catch ((e ) => {
104
+ console .warn (e);
105
+ });
70
106
setview ([lat, lng], zoom);
71
107
} else {
72
- this .$router .replace (options).catch (e => { console .warn (e) });
108
+ this .$router .replace (options).catch ((e ) => {
109
+ console .warn (e);
110
+ });
73
111
}
74
112
}
75
113
},
76
114
77
115
getlocalmappos () {
78
- if (localStorage .getItem (" map-position" )) {
116
+ if (localStorage .getItem (" map-position" )) {
79
117
const lastsettings = localStorage .getItem (" map-position" );
80
- this .store .setmapposition (JSON .parse (lastsettings).lat , JSON .parse (lastsettings).lng , JSON .parse (lastsettings).zoom );
118
+ this .store .setmapposition (
119
+ JSON .parse (lastsettings).lat ,
120
+ JSON .parse (lastsettings).lng ,
121
+ JSON .parse (lastsettings).zoom
122
+ );
81
123
}
82
124
},
83
125
84
126
setgeo () {
85
127
return new Promise ((resolve ) => {
86
128
if (" geolocation" in navigator ) {
87
129
navigator .geolocation .getCurrentPosition (
88
- position => {
89
- this .userposition = [position .coords .latitude , position .coords .longitude ];
130
+ (position ) => {
131
+ this .userposition = [
132
+ position .coords .latitude ,
133
+ position .coords .longitude ,
134
+ ];
90
135
/* setting for the app globally user's geo position and zoom 20 for better view */
91
- this .store .setmapposition (this .userposition [0 ], this .userposition [1 ], 20 );
136
+ this .store .setmapposition (
137
+ this .userposition [0 ],
138
+ this .userposition [1 ],
139
+ 20
140
+ );
92
141
this .geoavailable = true ;
93
142
resolve ();
94
143
},
95
- e => {
144
+ ( e ) => {
96
145
console .warn (` ERROR(${ e .code } ): ${ e .message } ` );
97
146
/* Если не удалось получить позицию юзера, то проверяем локальное хранилище */
98
147
this .getlocalmappos ();
99
148
resolve ();
100
- });
149
+ }
150
+ );
101
151
} else {
102
152
/* Если нет возможности "geolocation", то проверяем локальное хранилище */
103
153
this .getlocalmappos ();
104
154
resolve ();
105
155
}
106
- })
156
+ });
107
157
},
108
158
109
159
resetgeo () {
110
160
const waitcoords = this .setgeo ();
111
- waitcoords .then ( () => {
112
- this .relocatemap (this .lat , this .lng , this .zoom , ' reload' );
113
- })
114
- }
161
+ waitcoords .then (() => {
162
+ this .relocatemap (this .lat , this .lng , this .zoom , " reload" );
163
+ });
164
+ },
115
165
},
116
166
117
167
unmounted () {
@@ -134,31 +184,46 @@ export default {
134
184
const waitcoords = this .setgeo ();
135
185
/* - retrieve coordinates */
136
186
137
-
138
187
/* + Operate with a map */
139
- waitcoords .then ( async () => {
188
+ waitcoords .then (async () => {
140
189
const map = init ([this .lat , this .lng ], this .zoom , this .theme );
141
- this .relocatemap (this .lat , this .lng , this .zoom , ' reload' );
190
+ this .relocatemap (this .lat , this .lng , this .zoom , " reload" );
142
191
143
- if (this .userposition ) {
192
+ if (this .userposition ) {
144
193
drawuser (this .userposition , this .zoom );
145
194
}
146
195
147
196
map .on (" zoomend" , (e ) => {
148
- this .relocatemap (e .target .getCenter ().lat .toFixed (4 ), e .target .getCenter ().lng .toFixed (4 ), e .target .getZoom ());
149
- this .store .setmapposition (e .target .getCenter ().lat .toFixed (4 ), e .target .getCenter ().lng .toFixed (4 ), e .target .getZoom ());
197
+ this .relocatemap (
198
+ e .target .getCenter ().lat .toFixed (4 ),
199
+ e .target .getCenter ().lng .toFixed (4 ),
200
+ e .target .getZoom ()
201
+ );
202
+ this .store .setmapposition (
203
+ e .target .getCenter ().lat .toFixed (4 ),
204
+ e .target .getCenter ().lng .toFixed (4 ),
205
+ e .target .getZoom ()
206
+ );
150
207
});
151
208
152
209
map .on (" moveend" , (e ) => {
153
- this .relocatemap (e .target .getCenter ().lat .toFixed (4 ), e .target .getCenter ().lng .toFixed (4 ), e .target .getZoom ());
154
- this .store .setmapposition (e .target .getCenter ().lat .toFixed (4 ), e .target .getCenter ().lng .toFixed (4 ), e .target .getZoom ());
210
+ this .relocatemap (
211
+ e .target .getCenter ().lat .toFixed (4 ),
212
+ e .target .getCenter ().lng .toFixed (4 ),
213
+ e .target .getZoom ()
214
+ );
215
+ this .store .setmapposition (
216
+ e .target .getCenter ().lat .toFixed (4 ),
217
+ e .target .getCenter ().lng .toFixed (4 ),
218
+ e .target .getZoom ()
219
+ );
155
220
});
156
221
157
222
initMarkers (map, this .measuretype , (data ) => {
158
223
this .$emit (" clickMarker" , data);
159
224
});
160
225
161
- if (this .provider === ' realtime' ) {
226
+ if (this .provider === " realtime" ) {
162
227
await initWind ();
163
228
}
164
229
});
0 commit comments