neo.mjs 4.4.10 → 4.4.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/examples/component/wrapper/googleMaps/MainContainer.mjs +21 -0
- package/examples/component/wrapper/googleMaps/MainContainerController.mjs +34 -6
- package/examples/component/wrapper/googleMaps/neo-config.json +1 -0
- package/package.json +1 -1
- package/src/DefaultConfig.mjs +8 -0
- package/src/component/wrapper/GoogleMaps.mjs +132 -18
- package/src/main/addon/GoogleMaps.mjs +82 -7
@@ -1,6 +1,7 @@
|
|
1
1
|
import Button from '../../../../src/button/Base.mjs';
|
2
2
|
import GoogleMapsComponent from '../../../../src/component/wrapper/GoogleMaps.mjs';
|
3
3
|
import MainContainerController from './MainContainerController.mjs';
|
4
|
+
import NumberField from '../../../../src/form/field/Number.mjs';
|
4
5
|
import Toolbar from '../../../../src/toolbar/Base.mjs';
|
5
6
|
import Viewport from '../../../../src/container/Viewport.mjs';
|
6
7
|
|
@@ -34,8 +35,28 @@ class MainContainer extends Viewport {
|
|
34
35
|
items : [{
|
35
36
|
module : Button,
|
36
37
|
handler: 'onFlyToButtonClick',
|
38
|
+
height : 27,
|
37
39
|
iconCls: 'fa-solid fa-plane',
|
38
40
|
text : 'Fly to San Fran'
|
41
|
+
}, {
|
42
|
+
module : NumberField,
|
43
|
+
clearToOriginalValue: true,
|
44
|
+
labelPosition : 'inline',
|
45
|
+
labelText : 'zoom',
|
46
|
+
listeners : {change: 'onZoomFieldChange'},
|
47
|
+
minValue : 0,
|
48
|
+
maxValue : 10,
|
49
|
+
style : {marginLeft: '10px'},
|
50
|
+
value : 8,
|
51
|
+
width : 100
|
52
|
+
}, {
|
53
|
+
module : Button,
|
54
|
+
handler: 'onRemoveMarkerButtonClick',
|
55
|
+
height : 27,
|
56
|
+
iconCls: 'fa-solid fa-trash',
|
57
|
+
mode : 'hide',
|
58
|
+
style : {marginLeft: '10px'},
|
59
|
+
text : 'Hide marker'
|
39
60
|
}]
|
40
61
|
}]
|
41
62
|
}}
|
@@ -17,12 +17,40 @@ class MainContainerController extends ComponentController {
|
|
17
17
|
* @param {Object} data
|
18
18
|
*/
|
19
19
|
onFlyToButtonClick(data) {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
this.getReference('google-maps-component').panTo({lat: 37.655, lng: -122.4175})
|
21
|
+
}
|
22
|
+
|
23
|
+
/**
|
24
|
+
* @param {Object} data
|
25
|
+
*/
|
26
|
+
onRemoveMarkerButtonClick(data) {
|
27
|
+
let button = data.component,
|
28
|
+
map = this.getReference('google-maps-component');
|
29
|
+
|
30
|
+
if (button.mode === 'hide') {
|
31
|
+
button.set({
|
32
|
+
iconCls: 'fa fa-location-dot',
|
33
|
+
mode : 'show',
|
34
|
+
text : 'Show marker'
|
35
|
+
});
|
36
|
+
|
37
|
+
map.hideMarker('1')
|
38
|
+
} else {
|
39
|
+
button.set({
|
40
|
+
iconCls: 'fa-solid fa-trash',
|
41
|
+
mode : 'hide',
|
42
|
+
text : 'Hide marker'
|
43
|
+
});
|
44
|
+
|
45
|
+
map.showMarker('1')
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
/**
|
50
|
+
* @param {Object} data
|
51
|
+
*/
|
52
|
+
onZoomFieldChange(data) {
|
53
|
+
this.getReference('google-maps-component').zoom = data.value;
|
26
54
|
}
|
27
55
|
}
|
28
56
|
|
@@ -2,6 +2,7 @@
|
|
2
2
|
"appPath" : "examples/component/wrapper/googleMaps/app.mjs",
|
3
3
|
"basePath" : "../../../../",
|
4
4
|
"environment" : "development",
|
5
|
+
"googleMapsApiKey": "AIzaSyCRj-EPE3H7PCzZtYCmDzln6sj7uPCGohA",
|
5
6
|
"mainPath" : "./Main.mjs",
|
6
7
|
"mainThreadAddons": ["GoogleMaps", "Stylesheet"]
|
7
8
|
}
|
package/package.json
CHANGED
package/src/DefaultConfig.mjs
CHANGED
@@ -52,6 +52,14 @@ const DefaultConfig = {
|
|
52
52
|
* @type String
|
53
53
|
*/
|
54
54
|
environment: 'dist/production',
|
55
|
+
/**
|
56
|
+
* In case you are using the GoogleMaps main thread addon, you can pass the API key here.
|
57
|
+
* @default ''
|
58
|
+
* @memberOf! module:Neo
|
59
|
+
* @name config.googleMapsApiKey
|
60
|
+
* @type String
|
61
|
+
*/
|
62
|
+
googleMapsApiKey: '',
|
55
63
|
/**
|
56
64
|
* In case you are using the GoogleAnalytics main thread addon or useGoogleAnalytics: true,
|
57
65
|
* you can change the gtag id here. Required for the online examples (gh pages)
|
@@ -13,6 +13,16 @@ class GoogleMaps extends Base {
|
|
13
13
|
* @protected
|
14
14
|
*/
|
15
15
|
className: 'Neo.component.wrapper.GoogleMaps',
|
16
|
+
/**
|
17
|
+
* Specify lat & lng for the current focus position
|
18
|
+
* @member {Object} center_={lat: -34.397, lng: 150.644}
|
19
|
+
*/
|
20
|
+
center_: {lat: -34.397, lng: 150.644},
|
21
|
+
/**
|
22
|
+
* false hides the default fullscreen control
|
23
|
+
* @member {Boolean} fullscreenControl=true
|
24
|
+
*/
|
25
|
+
fullscreenControl: true,
|
16
26
|
/**
|
17
27
|
* Prefer to use markerStoreConfig instead.
|
18
28
|
* @member {Neo.data.Store|Object} markerStore_
|
@@ -37,10 +47,24 @@ class GoogleMaps extends Base {
|
|
37
47
|
*/
|
38
48
|
markerStoreConfig: null,
|
39
49
|
/**
|
40
|
-
*
|
50
|
+
* null => the maximum zoom from the current map type is used instead
|
51
|
+
* @member {Number|null} maxZoom=null
|
52
|
+
*/
|
53
|
+
maxZoom: null,
|
54
|
+
/**
|
55
|
+
null => the minimum zoom from the current map type is used instead
|
56
|
+
* @member {Number|null} minZoom=null
|
57
|
+
*/
|
58
|
+
minZoom: null,
|
59
|
+
/**
|
60
|
+
* @member {Number} zoom_=8
|
41
61
|
*/
|
42
|
-
|
43
|
-
|
62
|
+
zoom_: 8,
|
63
|
+
/**
|
64
|
+
* false hides the default zoom control
|
65
|
+
* @member {Boolean} zoomControl=true
|
66
|
+
*/
|
67
|
+
zoomControl: true
|
44
68
|
}}
|
45
69
|
|
46
70
|
/**
|
@@ -51,7 +75,26 @@ class GoogleMaps extends Base {
|
|
51
75
|
* @param {String} [data.title]
|
52
76
|
*/
|
53
77
|
addMarker(data) {
|
54
|
-
Neo.main.addon.GoogleMaps.addMarker(
|
78
|
+
Neo.main.addon.GoogleMaps.addMarker({
|
79
|
+
appName: this.appName,
|
80
|
+
...data
|
81
|
+
});
|
82
|
+
}
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Triggered after the center config got changed
|
86
|
+
* @param {Object} value
|
87
|
+
* @param {Object} oldValue
|
88
|
+
* @protected
|
89
|
+
*/
|
90
|
+
afterSetCenter(value, oldValue) {
|
91
|
+
if (oldValue !== undefined) {
|
92
|
+
Neo.main.addon.GoogleMaps.setCenter({
|
93
|
+
appName: this.appName,
|
94
|
+
id : this.id,
|
95
|
+
value
|
96
|
+
})
|
97
|
+
}
|
55
98
|
}
|
56
99
|
|
57
100
|
/**
|
@@ -83,18 +126,21 @@ class GoogleMaps extends Base {
|
|
83
126
|
let me = this;
|
84
127
|
|
85
128
|
if (value === false && oldValue !== undefined) {
|
86
|
-
|
87
|
-
appName: me.appName,
|
88
|
-
id : me.id
|
89
|
-
});
|
129
|
+
me.removeMap();
|
90
130
|
}
|
91
131
|
|
92
132
|
super.afterSetMounted(value, oldValue);
|
93
133
|
|
94
134
|
if (value) {
|
95
135
|
let opts = {
|
96
|
-
appName: me.appName,
|
97
|
-
|
136
|
+
appName : me.appName,
|
137
|
+
center : me.center,
|
138
|
+
fullscreenControl: me.fullscreenControl,
|
139
|
+
id : me.id,
|
140
|
+
maxZoom : me.maxZoom,
|
141
|
+
minZoom : me.minZoom,
|
142
|
+
zoom : me.zoom,
|
143
|
+
zoomControl : me.zoomControl
|
98
144
|
};
|
99
145
|
|
100
146
|
setTimeout(() => {
|
@@ -105,6 +151,22 @@ class GoogleMaps extends Base {
|
|
105
151
|
}
|
106
152
|
}
|
107
153
|
|
154
|
+
/**
|
155
|
+
* Triggered after the zoom config got changed
|
156
|
+
* @param {Number} value
|
157
|
+
* @param {Number} oldValue
|
158
|
+
* @protected
|
159
|
+
*/
|
160
|
+
afterSetZoom(value, oldValue) {
|
161
|
+
if (oldValue !== undefined) {
|
162
|
+
Neo.main.addon.GoogleMaps.setZoom({
|
163
|
+
appName: this.appName,
|
164
|
+
id : this.id,
|
165
|
+
value
|
166
|
+
})
|
167
|
+
}
|
168
|
+
}
|
169
|
+
|
108
170
|
/**
|
109
171
|
* Triggered before the markerStore config gets changed.
|
110
172
|
* @param {Object} value
|
@@ -122,20 +184,26 @@ class GoogleMaps extends Base {
|
|
122
184
|
* @param {Boolean} silent=false
|
123
185
|
*/
|
124
186
|
destroy(updateParentVdom=false, silent=false) {
|
125
|
-
|
126
|
-
mapId: this.id
|
127
|
-
});
|
128
|
-
|
187
|
+
this.removeMap();
|
129
188
|
super.destroy(updateParentVdom, silent);
|
130
189
|
}
|
131
190
|
|
132
191
|
/**
|
133
|
-
*
|
192
|
+
* @param {String} id
|
134
193
|
*/
|
135
|
-
|
136
|
-
|
194
|
+
hideMarker(id) {
|
195
|
+
Neo.main.addon.GoogleMaps.hideMarker({
|
196
|
+
appName: this.appName,
|
197
|
+
id,
|
198
|
+
mapId : this.id
|
199
|
+
})
|
137
200
|
}
|
138
201
|
|
202
|
+
/**
|
203
|
+
* Hook to use once the map instance got rendered
|
204
|
+
*/
|
205
|
+
onComponentMounted() {}
|
206
|
+
|
139
207
|
/**
|
140
208
|
*
|
141
209
|
*/
|
@@ -144,11 +212,57 @@ class GoogleMaps extends Base {
|
|
144
212
|
|
145
213
|
me.markerStore.items.forEach(item => {
|
146
214
|
Neo.main.addon.GoogleMaps.addMarker({
|
147
|
-
|
215
|
+
appName: me.appName,
|
216
|
+
mapId : me.id,
|
148
217
|
...item
|
149
218
|
})
|
150
219
|
})
|
151
220
|
}
|
221
|
+
|
222
|
+
/**
|
223
|
+
* @param {Object} position
|
224
|
+
* @param {Number} position.lat
|
225
|
+
* @param {Number} position.lng
|
226
|
+
*/
|
227
|
+
panTo(position) {
|
228
|
+
Neo.main.addon.GoogleMaps.panTo({
|
229
|
+
appName: this.appName,
|
230
|
+
mapId : this.id,
|
231
|
+
position
|
232
|
+
})
|
233
|
+
}
|
234
|
+
|
235
|
+
/**
|
236
|
+
*
|
237
|
+
*/
|
238
|
+
removeMap() {
|
239
|
+
Neo.main.addon.GoogleMaps.removeMap({
|
240
|
+
appName: this.appName,
|
241
|
+
mapId : this.id
|
242
|
+
})
|
243
|
+
}
|
244
|
+
|
245
|
+
/**
|
246
|
+
* @param {String} id
|
247
|
+
*/
|
248
|
+
removeMarker(id) {
|
249
|
+
Neo.main.addon.GoogleMaps.removeMarker({
|
250
|
+
appName: this.appName,
|
251
|
+
id,
|
252
|
+
mapId : this.id
|
253
|
+
})
|
254
|
+
}
|
255
|
+
|
256
|
+
/**
|
257
|
+
* @param {String} id
|
258
|
+
*/
|
259
|
+
showMarker(id) {
|
260
|
+
Neo.main.addon.GoogleMaps.showMarker({
|
261
|
+
appName: this.appName,
|
262
|
+
id,
|
263
|
+
mapId : this.id
|
264
|
+
})
|
265
|
+
}
|
152
266
|
}
|
153
267
|
|
154
268
|
Neo.applyClassConfig(GoogleMaps);
|
@@ -34,7 +34,13 @@ class GoogleMaps extends Base {
|
|
34
34
|
app: [
|
35
35
|
'addMarker',
|
36
36
|
'create',
|
37
|
-
'
|
37
|
+
'hideMarker',
|
38
|
+
'panTo',
|
39
|
+
'removeMap',
|
40
|
+
'removeMarker',
|
41
|
+
'setCenter',
|
42
|
+
'setZoom',
|
43
|
+
'showMarker'
|
38
44
|
]
|
39
45
|
},
|
40
46
|
/**
|
@@ -82,14 +88,24 @@ class GoogleMaps extends Base {
|
|
82
88
|
|
83
89
|
/**
|
84
90
|
* @param {Object} data
|
91
|
+
* @param {Object} data.center
|
92
|
+
* @param {Boolean} data.fullscreenControl
|
85
93
|
* @param {String} data.id
|
94
|
+
* @param {Number} data.maxZoom
|
95
|
+
* @param {Number} data.minZoom
|
96
|
+
* @param {Number} data.zoom
|
97
|
+
* @param {Boolean} data.zoomControl
|
86
98
|
*/
|
87
99
|
create(data) {
|
88
100
|
let me = this;
|
89
101
|
|
90
102
|
me.maps[data.id] = new google.maps.Map(DomAccess.getElement(data.id), {
|
91
|
-
center:
|
92
|
-
|
103
|
+
center : data.center,
|
104
|
+
fullscreenControl: data.fullscreenControl,
|
105
|
+
maxZoom : data.maxZoom,
|
106
|
+
minZoom : data.minZoom,
|
107
|
+
zoom : data.zoom,
|
108
|
+
zoomControl : data.zoomControl
|
93
109
|
});
|
94
110
|
|
95
111
|
me.fire('mapCreated', data.id);
|
@@ -97,21 +113,80 @@ class GoogleMaps extends Base {
|
|
97
113
|
|
98
114
|
/**
|
99
115
|
* @param {Object} data
|
116
|
+
* @param {String} data.id
|
100
117
|
* @param {String} data.mapId
|
101
118
|
*/
|
102
|
-
|
103
|
-
|
104
|
-
delete this.markers[data.mapId];
|
119
|
+
hideMarker(data) {
|
120
|
+
this.markers[data.mapId][data.id].setMap(null);
|
105
121
|
}
|
106
122
|
|
107
123
|
/**
|
108
124
|
* @protected
|
109
125
|
*/
|
110
126
|
loadApi() {
|
111
|
-
|
127
|
+
let key = Neo.config.googleMapsApiKey;
|
128
|
+
|
129
|
+
DomAccess.loadScript(`https://maps.googleapis.com/maps/api/js?key=${key}&v=weekly`).then(() => {
|
112
130
|
console.log('GoogleMaps API loaded');
|
113
131
|
})
|
114
132
|
}
|
133
|
+
|
134
|
+
/**
|
135
|
+
* @param data
|
136
|
+
* @param {String} data.mapId
|
137
|
+
* @param {Object} data.position
|
138
|
+
*/
|
139
|
+
panTo(data) {
|
140
|
+
this.maps[data.mapId].panTo(data.position);
|
141
|
+
}
|
142
|
+
|
143
|
+
/**
|
144
|
+
* @param {Object} data
|
145
|
+
* @param {String} data.mapId
|
146
|
+
*/
|
147
|
+
removeMap(data) {
|
148
|
+
delete this.maps[data.mapId];
|
149
|
+
delete this.markers[data.mapId];
|
150
|
+
}
|
151
|
+
|
152
|
+
/**
|
153
|
+
* @param {Object} data
|
154
|
+
* @param {String} data.id
|
155
|
+
* @param {String} data.mapId
|
156
|
+
*/
|
157
|
+
removeMarker(data) {
|
158
|
+
let markers = this.markers[data.mapId];
|
159
|
+
|
160
|
+
markers[data.id].setMap(null);
|
161
|
+
delete markers[data.id];
|
162
|
+
}
|
163
|
+
|
164
|
+
/**
|
165
|
+
* @param {Object} data
|
166
|
+
* @param {String} data.id
|
167
|
+
* @param {Object} data.value
|
168
|
+
*/
|
169
|
+
setCenter(data) {
|
170
|
+
this.maps[data.id].setCenter(data.value);
|
171
|
+
}
|
172
|
+
|
173
|
+
/**
|
174
|
+
* @param {Object} data
|
175
|
+
* @param {String} data.id
|
176
|
+
* @param {Number} data.value
|
177
|
+
*/
|
178
|
+
setZoom(data) {
|
179
|
+
this.maps[data.id].setZoom(data.value);
|
180
|
+
}
|
181
|
+
|
182
|
+
/**
|
183
|
+
* @param {Object} data
|
184
|
+
* @param {String} data.id
|
185
|
+
* @param {String} data.mapId
|
186
|
+
*/
|
187
|
+
showMarker(data) {
|
188
|
+
this.markers[data.mapId][data.id].setMap(this.maps[data.mapId]);
|
189
|
+
}
|
115
190
|
}
|
116
191
|
|
117
192
|
Neo.applyClassConfig(GoogleMaps);
|