neo.mjs 4.4.10 → 4.4.12

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.
@@ -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
 
@@ -23,8 +24,12 @@ class MainContainer extends Viewport {
23
24
  markerStoreConfig: {
24
25
  data: [{
25
26
  id : '1',
26
- position: {lat: -34.397, lng: 150.644},
27
+ position: {lat: -33.397, lng: 150.644},
27
28
  title : 'Hello neo'
29
+ }, {
30
+ id : '2',
31
+ position: {lat: -34.397, lng: 150.644},
32
+ title : 'Hello Max'
28
33
  }]
29
34
  }
30
35
  }, {
@@ -34,8 +39,28 @@ class MainContainer extends Viewport {
34
39
  items : [{
35
40
  module : Button,
36
41
  handler: 'onFlyToButtonClick',
42
+ height : 27,
37
43
  iconCls: 'fa-solid fa-plane',
38
44
  text : 'Fly to San Fran'
45
+ }, {
46
+ module : NumberField,
47
+ clearToOriginalValue: true,
48
+ labelPosition : 'inline',
49
+ labelText : 'zoom',
50
+ listeners : {change: 'onZoomFieldChange'},
51
+ minValue : 0,
52
+ maxValue : 10,
53
+ style : {marginLeft: '10px'},
54
+ value : 8,
55
+ width : 100
56
+ }, {
57
+ module : Button,
58
+ handler: 'onRemoveMarkerButtonClick',
59
+ height : 27,
60
+ iconCls: 'fa-solid fa-trash',
61
+ mode : 'hide',
62
+ style : {marginLeft: '10px'},
63
+ text : 'Hide marker 1'
39
64
  }]
40
65
  }]
41
66
  }}
@@ -17,12 +17,40 @@ class MainContainerController extends ComponentController {
17
17
  * @param {Object} data
18
18
  */
19
19
  onFlyToButtonClick(data) {
20
- // todo
21
- /*this.getReference('google-maps-component').flyTo({
22
- destination: [-122.4175, 37.655, 400],
23
- heading : 0.0,
24
- pitch : -15.0
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 1'
35
+ });
36
+
37
+ map.hideMarker('1')
38
+ } else {
39
+ button.set({
40
+ iconCls: 'fa-solid fa-trash',
41
+ mode : 'hide',
42
+ text : 'Hide marker 1'
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo.mjs",
3
- "version": "4.4.10",
3
+ "version": "4.4.12",
4
4
  "description": "The webworkers driven UI framework",
5
5
  "type": "module",
6
6
  "repository": {
@@ -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)
@@ -7,12 +7,47 @@ import Store from '../../data/Store.mjs';
7
7
  * @extends Neo.component.Base
8
8
  */
9
9
  class GoogleMaps extends Base {
10
+ /**
11
+ * false hides the default fullscreen control
12
+ * @member {Boolean} fullscreenControl=true
13
+ */
14
+ fullscreenControl = true
15
+ /**
16
+ * @member {Object} markerStoreConfig=null
17
+ */
18
+ markerStoreConfig = null
19
+ /**
20
+ * Pass any options to the map instance which are not explicitly defined here
21
+ * @member {Object} mapOptions={}
22
+ */
23
+ mapOptions = {}
24
+ /**
25
+ * null => the maximum zoom from the current map type is used instead
26
+ * @member {Number|null} maxZoom=null
27
+ */
28
+ maxZoom = null
29
+ /**
30
+ null => the minimum zoom from the current map type is used instead
31
+ * @member {Number|null} minZoom=null
32
+ */
33
+ minZoom = null
34
+ /**
35
+ * false hides the default zoom control
36
+ * @member {Boolean} zoomControl=true
37
+ */
38
+ zoomControl = true
39
+
10
40
  static getConfig() {return {
11
41
  /**
12
42
  * @member {String} className='Neo.component.wrapper.GoogleMaps'
13
43
  * @protected
14
44
  */
15
45
  className: 'Neo.component.wrapper.GoogleMaps',
46
+ /**
47
+ * Specify lat & lng for the current focus position
48
+ * @member {Object} center_={lat: -34.397, lng: 150.644}
49
+ */
50
+ center_: {lat: -34.397, lng: 150.644},
16
51
  /**
17
52
  * Prefer to use markerStoreConfig instead.
18
53
  * @member {Neo.data.Store|Object} markerStore_
@@ -33,16 +68,26 @@ class GoogleMaps extends Base {
33
68
  }
34
69
  },
35
70
  /**
36
- * @member {Object} markerStoreConfig: null
37
- */
38
- markerStoreConfig: null,
39
- /**
40
- * @member {Object} _vdom
71
+ * @member {Number} zoom_=8
41
72
  */
42
- _vdom:
43
- {}
73
+ zoom_: 8
44
74
  }}
45
75
 
76
+ /**
77
+ * @param {Object} config
78
+ */
79
+ construct(config) {
80
+ super.construct(config);
81
+
82
+ let me = this;
83
+
84
+ me.addDomListeners({
85
+ googleMarkerClick: me.parseMarkerClick,
86
+ local : false,
87
+ scope : me
88
+ })
89
+ }
90
+
46
91
  /**
47
92
  * @param {Object} data
48
93
  * @param {String} data.id
@@ -51,7 +96,26 @@ class GoogleMaps extends Base {
51
96
  * @param {String} [data.title]
52
97
  */
53
98
  addMarker(data) {
54
- Neo.main.addon.GoogleMaps.addMarker(data);
99
+ Neo.main.addon.GoogleMaps.addMarker({
100
+ appName: this.appName,
101
+ ...data
102
+ });
103
+ }
104
+
105
+ /**
106
+ * Triggered after the center config got changed
107
+ * @param {Object} value
108
+ * @param {Object} oldValue
109
+ * @protected
110
+ */
111
+ afterSetCenter(value, oldValue) {
112
+ if (oldValue !== undefined) {
113
+ Neo.main.addon.GoogleMaps.setCenter({
114
+ appName: this.appName,
115
+ id : this.id,
116
+ value
117
+ })
118
+ }
55
119
  }
56
120
 
57
121
  /**
@@ -83,18 +147,22 @@ class GoogleMaps extends Base {
83
147
  let me = this;
84
148
 
85
149
  if (value === false && oldValue !== undefined) {
86
- Neo.main.addon.GoogleMaps.destroy({
87
- appName: me.appName,
88
- id : me.id
89
- });
150
+ me.removeMap();
90
151
  }
91
152
 
92
153
  super.afterSetMounted(value, oldValue);
93
154
 
94
155
  if (value) {
95
156
  let opts = {
96
- appName: me.appName,
97
- id : me.id
157
+ appName : me.appName,
158
+ center : me.center,
159
+ fullscreenControl: me.fullscreenControl,
160
+ id : me.id,
161
+ mapOptions : me.mapOptions,
162
+ maxZoom : me.maxZoom,
163
+ minZoom : me.minZoom,
164
+ zoom : me.zoom,
165
+ zoomControl : me.zoomControl
98
166
  };
99
167
 
100
168
  setTimeout(() => {
@@ -105,6 +173,22 @@ class GoogleMaps extends Base {
105
173
  }
106
174
  }
107
175
 
176
+ /**
177
+ * Triggered after the zoom config got changed
178
+ * @param {Number} value
179
+ * @param {Number} oldValue
180
+ * @protected
181
+ */
182
+ afterSetZoom(value, oldValue) {
183
+ if (oldValue !== undefined) {
184
+ Neo.main.addon.GoogleMaps.setZoom({
185
+ appName: this.appName,
186
+ id : this.id,
187
+ value
188
+ })
189
+ }
190
+ }
191
+
108
192
  /**
109
193
  * Triggered before the markerStore config gets changed.
110
194
  * @param {Object} value
@@ -122,18 +206,31 @@ class GoogleMaps extends Base {
122
206
  * @param {Boolean} silent=false
123
207
  */
124
208
  destroy(updateParentVdom=false, silent=false) {
125
- Neo.main.addon.GoogleMaps.removeMap({
126
- mapId: this.id
127
- });
128
-
209
+ this.removeMap();
129
210
  super.destroy(updateParentVdom, silent);
130
211
  }
131
212
 
132
213
  /**
133
- *
214
+ * @param {String} id
215
+ */
216
+ hideMarker(id) {
217
+ Neo.main.addon.GoogleMaps.hideMarker({
218
+ appName: this.appName,
219
+ id,
220
+ mapId : this.id
221
+ })
222
+ }
223
+
224
+ /**
225
+ * Hook to use once the map instance got rendered
226
+ */
227
+ onComponentMounted() {}
228
+
229
+ /**
230
+ * @param {Object} record
134
231
  */
135
- onComponentMounted() {
136
- console.log('onComponentMounted', this.id);
232
+ onMarkerClick(record) {
233
+ console.log('onMarkerClick', record);
137
234
  }
138
235
 
139
236
  /**
@@ -144,11 +241,74 @@ class GoogleMaps extends Base {
144
241
 
145
242
  me.markerStore.items.forEach(item => {
146
243
  Neo.main.addon.GoogleMaps.addMarker({
147
- mapId: me.id,
244
+ appName: me.appName,
245
+ mapId : me.id,
148
246
  ...item
149
247
  })
150
248
  })
151
249
  }
250
+
251
+ /**
252
+ * @param {Object} position
253
+ * @param {Number} position.lat
254
+ * @param {Number} position.lng
255
+ */
256
+ panTo(position) {
257
+ Neo.main.addon.GoogleMaps.panTo({
258
+ appName: this.appName,
259
+ mapId : this.id,
260
+ position
261
+ })
262
+ }
263
+
264
+ /**
265
+ * Internal function. Use onMarkerClick() or the markerClick event instead
266
+ * @param {Object} data
267
+ * @protected
268
+ */
269
+ parseMarkerClick(data) {
270
+ let me = this,
271
+ record = me.markerStore.get(data.id);
272
+
273
+ me.onMarkerClick(record);
274
+
275
+ me.fire('markerClick', {
276
+ id: me.id,
277
+ record
278
+ })
279
+ }
280
+
281
+ /**
282
+ *
283
+ */
284
+ removeMap() {
285
+ Neo.main.addon.GoogleMaps.removeMap({
286
+ appName: this.appName,
287
+ mapId : this.id
288
+ })
289
+ }
290
+
291
+ /**
292
+ * @param {String} id
293
+ */
294
+ removeMarker(id) {
295
+ Neo.main.addon.GoogleMaps.removeMarker({
296
+ appName: this.appName,
297
+ id,
298
+ mapId : this.id
299
+ })
300
+ }
301
+
302
+ /**
303
+ * @param {String} id
304
+ */
305
+ showMarker(id) {
306
+ Neo.main.addon.GoogleMaps.showMarker({
307
+ appName: this.appName,
308
+ id,
309
+ mapId : this.id
310
+ })
311
+ }
152
312
  }
153
313
 
154
314
  Neo.applyClassConfig(GoogleMaps);
@@ -1,5 +1,6 @@
1
1
  import Base from '../../core/Base.mjs';
2
2
  import DomAccess from '../DomAccess.mjs';
3
+ import DomEvents from '../DomEvents.mjs';
3
4
  import Observable from '../../core/Observable.mjs';
4
5
 
5
6
  /**
@@ -8,20 +9,21 @@ import Observable from '../../core/Observable.mjs';
8
9
  * @singleton
9
10
  */
10
11
  class GoogleMaps extends Base {
12
+ /**
13
+ * @member {Object} maps={}
14
+ */
15
+ maps = {}
16
+ /**
17
+ * @member {Object} markers={}
18
+ */
19
+ markers = {}
20
+
11
21
  static getConfig() {return {
12
22
  /**
13
23
  * @member {String} className='Neo.main.addon.GoogleMaps'
14
24
  * @protected
15
25
  */
16
26
  className: 'Neo.main.addon.GoogleMaps',
17
- /**
18
- * @member {Object} maps={}
19
- */
20
- maps: {},
21
- /**
22
- * @member {Object} markers={}
23
- */
24
- markers: {},
25
27
  /**
26
28
  * @member {Neo.core.Base[]} mixins=[Observable]
27
29
  */
@@ -34,7 +36,13 @@ class GoogleMaps extends Base {
34
36
  app: [
35
37
  'addMarker',
36
38
  'create',
37
- 'removeMap'
39
+ 'hideMarker',
40
+ 'panTo',
41
+ 'removeMap',
42
+ 'removeMarker',
43
+ 'setCenter',
44
+ 'setZoom',
45
+ 'showMarker'
38
46
  ]
39
47
  },
40
48
  /**
@@ -60,10 +68,11 @@ class GoogleMaps extends Base {
60
68
  * @param {String} [data.title]
61
69
  */
62
70
  addMarker(data) {
63
- let me = this;
71
+ let me = this,
72
+ listenerId, marker;
64
73
 
65
74
  if (!me.maps[data.mapId]) {
66
- let listenerId = me.on('mapCreated', mapId => {
75
+ listenerId = me.on('mapCreated', mapId => {
67
76
  if (data.mapId === mapId) {
68
77
  me.un(listenerId);
69
78
  me.addMarker(data);
@@ -72,24 +81,40 @@ class GoogleMaps extends Base {
72
81
  } else {
73
82
  Neo.ns(`${data.mapId}`, true, me.markers);
74
83
 
75
- me.markers[data.mapId][data.id] = new google.maps.Marker({
76
- position: data.position,
84
+ me.markers[data.mapId][data.id] = marker = new google.maps.Marker({
77
85
  map : me.maps[data.mapId],
86
+ neoId : data.id, // custom property
87
+ neoMapId: data.mapId, // custom property
88
+ position: data.position,
78
89
  title : data.title,
79
90
  });
91
+
92
+ marker.addListener('click', me.onMarkerClick.bind(me, marker));
80
93
  }
81
94
  }
82
95
 
83
96
  /**
84
97
  * @param {Object} data
98
+ * @param {Object} data.center
99
+ * @param {Boolean} data.fullscreenControl
85
100
  * @param {String} data.id
101
+ * @param {Object} data.mapOptions // Pass any options which are not explicitly defined here
102
+ * @param {Number} data.maxZoom
103
+ * @param {Number} data.minZoom
104
+ * @param {Number} data.zoom
105
+ * @param {Boolean} data.zoomControl
86
106
  */
87
107
  create(data) {
88
108
  let me = this;
89
109
 
90
110
  me.maps[data.id] = new google.maps.Map(DomAccess.getElement(data.id), {
91
- center: { lat: -34.397, lng: 150.644 },
92
- zoom: 8,
111
+ center : data.center,
112
+ fullscreenControl: data.fullscreenControl,
113
+ maxZoom : data.maxZoom,
114
+ minZoom : data.minZoom,
115
+ zoom : data.zoom,
116
+ zoomControl : data.zoomControl,
117
+ ...data.mapOptions
93
118
  });
94
119
 
95
120
  me.fire('mapCreated', data.id);
@@ -97,21 +122,96 @@ class GoogleMaps extends Base {
97
122
 
98
123
  /**
99
124
  * @param {Object} data
125
+ * @param {String} data.id
100
126
  * @param {String} data.mapId
101
127
  */
102
- removeMap(data) {
103
- delete this.maps[data.mapId];
104
- delete this.markers[data.mapId];
128
+ hideMarker(data) {
129
+ this.markers[data.mapId][data.id].setMap(null);
105
130
  }
106
131
 
107
132
  /**
108
133
  * @protected
109
134
  */
110
135
  loadApi() {
111
- DomAccess.loadScript('https://maps.googleapis.com/maps/api/js?key=AIzaSyCRj-EPE3H7PCzZtYCmDzln6sj7uPCGohA&v=weekly').then(() => {
136
+ let key = Neo.config.googleMapsApiKey;
137
+
138
+ DomAccess.loadScript(`https://maps.googleapis.com/maps/api/js?key=${key}&v=weekly`).then(() => {
112
139
  console.log('GoogleMaps API loaded');
113
140
  })
114
141
  }
142
+
143
+ /**
144
+ * @param {google.maps.Marker} marker
145
+ * @param {Object} event
146
+ * @param {Object} event.domEvent
147
+ */
148
+ onMarkerClick(marker, event) {
149
+ // in theory, we could parse and pass the entire DOM event.
150
+ // feel free to open a feature request ticket, in case you need more data into the app worker.
151
+
152
+ DomEvents.sendMessageToApp({
153
+ id : marker.neoId,
154
+ path: [{cls: [], id: marker.neoMapId}],
155
+ type: 'googleMarkerClick'
156
+ })
157
+ }
158
+
159
+ /**
160
+ * @param data
161
+ * @param {String} data.mapId
162
+ * @param {Object} data.position
163
+ */
164
+ panTo(data) {
165
+ this.maps[data.mapId].panTo(data.position);
166
+ }
167
+
168
+ /**
169
+ * @param {Object} data
170
+ * @param {String} data.mapId
171
+ */
172
+ removeMap(data) {
173
+ delete this.maps[data.mapId];
174
+ delete this.markers[data.mapId];
175
+ }
176
+
177
+ /**
178
+ * @param {Object} data
179
+ * @param {String} data.id
180
+ * @param {String} data.mapId
181
+ */
182
+ removeMarker(data) {
183
+ let markers = this.markers[data.mapId];
184
+
185
+ markers[data.id].setMap(null);
186
+ delete markers[data.id];
187
+ }
188
+
189
+ /**
190
+ * @param {Object} data
191
+ * @param {String} data.id
192
+ * @param {Object} data.value
193
+ */
194
+ setCenter(data) {
195
+ this.maps[data.id].setCenter(data.value);
196
+ }
197
+
198
+ /**
199
+ * @param {Object} data
200
+ * @param {String} data.id
201
+ * @param {Number} data.value
202
+ */
203
+ setZoom(data) {
204
+ this.maps[data.id].setZoom(data.value);
205
+ }
206
+
207
+ /**
208
+ * @param {Object} data
209
+ * @param {String} data.id
210
+ * @param {String} data.mapId
211
+ */
212
+ showMarker(data) {
213
+ this.markers[data.mapId][data.id].setMap(this.maps[data.mapId]);
214
+ }
115
215
  }
116
216
 
117
217
  Neo.applyClassConfig(GoogleMaps);