neo.mjs 4.4.9 → 4.4.10
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 +9 -1
- package/package.json +1 -1
- package/src/component/Base.mjs +2 -2
- package/src/component/Splitter.mjs +1 -1
- package/src/component/wrapper/GoogleMaps.mjs +94 -1
- package/src/container/Base.mjs +10 -0
- package/src/main/addon/GoogleMaps.mjs +57 -5
- package/src/manager/Component.mjs +6 -2
@@ -18,7 +18,15 @@ class MainContainer extends Viewport {
|
|
18
18
|
items: [{
|
19
19
|
module : GoogleMapsComponent,
|
20
20
|
flex : 1,
|
21
|
-
reference: 'google-maps-component'
|
21
|
+
reference: 'google-maps-component',
|
22
|
+
|
23
|
+
markerStoreConfig: {
|
24
|
+
data: [{
|
25
|
+
id : '1',
|
26
|
+
position: {lat: -34.397, lng: 150.644},
|
27
|
+
title : 'Hello neo'
|
28
|
+
}]
|
29
|
+
}
|
22
30
|
}, {
|
23
31
|
module: Toolbar,
|
24
32
|
flex : 'none',
|
package/package.json
CHANGED
package/src/component/Base.mjs
CHANGED
@@ -974,8 +974,8 @@ class Base extends CoreBase {
|
|
974
974
|
|
975
975
|
/**
|
976
976
|
* Unregisters this instance from the ComponentManager
|
977
|
-
* @param {Boolean}
|
978
|
-
* @param {Boolean}
|
977
|
+
* @param {Boolean} updateParentVdom=false true to remove the component from the parent vdom => real dom
|
978
|
+
* @param {Boolean} silent=false true to update the vdom silently (useful for destroying multiple child items in a row)
|
979
979
|
* todo: unregister events
|
980
980
|
*/
|
981
981
|
destroy(updateParentVdom=false, silent=false) {
|
@@ -1,4 +1,6 @@
|
|
1
|
-
import Base
|
1
|
+
import Base from '../../component/Base.mjs';
|
2
|
+
import ClassSystemUtil from '../../util/ClassSystem.mjs';
|
3
|
+
import Store from '../../data/Store.mjs';
|
2
4
|
|
3
5
|
/**
|
4
6
|
* @class Neo.component.wrapper.GoogleMaps
|
@@ -11,6 +13,29 @@ class GoogleMaps extends Base {
|
|
11
13
|
* @protected
|
12
14
|
*/
|
13
15
|
className: 'Neo.component.wrapper.GoogleMaps',
|
16
|
+
/**
|
17
|
+
* Prefer to use markerStoreConfig instead.
|
18
|
+
* @member {Neo.data.Store|Object} markerStore_
|
19
|
+
* @protected
|
20
|
+
*/
|
21
|
+
markerStore_: {
|
22
|
+
model: {
|
23
|
+
fields: [{
|
24
|
+
name: 'id',
|
25
|
+
type: 'String'
|
26
|
+
}, {
|
27
|
+
name: 'position',
|
28
|
+
type: 'Object'
|
29
|
+
}, {
|
30
|
+
name: 'title',
|
31
|
+
type: 'String'
|
32
|
+
}]
|
33
|
+
}
|
34
|
+
},
|
35
|
+
/**
|
36
|
+
* @member {Object} markerStoreConfig: null
|
37
|
+
*/
|
38
|
+
markerStoreConfig: null,
|
14
39
|
/**
|
15
40
|
* @member {Object} _vdom
|
16
41
|
*/
|
@@ -18,6 +43,36 @@ class GoogleMaps extends Base {
|
|
18
43
|
{}
|
19
44
|
}}
|
20
45
|
|
46
|
+
/**
|
47
|
+
* @param {Object} data
|
48
|
+
* @param {String} data.id
|
49
|
+
* @param {String} data.mapId
|
50
|
+
* @param {Object} data.position
|
51
|
+
* @param {String} [data.title]
|
52
|
+
*/
|
53
|
+
addMarker(data) {
|
54
|
+
Neo.main.addon.GoogleMaps.addMarker(data);
|
55
|
+
}
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Triggered after the markerStore config got changed
|
59
|
+
* @param {Object} value
|
60
|
+
* @param {Object} oldValue
|
61
|
+
* @protected
|
62
|
+
*/
|
63
|
+
afterSetMarkerStore(value, oldValue) {
|
64
|
+
let me = this;
|
65
|
+
|
66
|
+
value.on({
|
67
|
+
load : me.onMarkerStoreLoad,
|
68
|
+
scope: me
|
69
|
+
});
|
70
|
+
|
71
|
+
if (value.items.length > 0) {
|
72
|
+
me.onMarkerStoreLoad();
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
21
76
|
/**
|
22
77
|
* Triggered after the mounted config got changed
|
23
78
|
* @param {Boolean} value
|
@@ -50,12 +105,50 @@ class GoogleMaps extends Base {
|
|
50
105
|
}
|
51
106
|
}
|
52
107
|
|
108
|
+
/**
|
109
|
+
* Triggered before the markerStore config gets changed.
|
110
|
+
* @param {Object} value
|
111
|
+
* @param {Object} oldValue
|
112
|
+
* @protected
|
113
|
+
*/
|
114
|
+
beforeSetMarkerStore(value, oldValue) {
|
115
|
+
oldValue?.destroy();
|
116
|
+
|
117
|
+
return ClassSystemUtil.beforeSetInstance(value, Store, this.markerStoreConfig);
|
118
|
+
}
|
119
|
+
|
120
|
+
/**
|
121
|
+
* @param {Boolean} updateParentVdom=false
|
122
|
+
* @param {Boolean} silent=false
|
123
|
+
*/
|
124
|
+
destroy(updateParentVdom=false, silent=false) {
|
125
|
+
Neo.main.addon.GoogleMaps.removeMap({
|
126
|
+
mapId: this.id
|
127
|
+
});
|
128
|
+
|
129
|
+
super.destroy(updateParentVdom, silent);
|
130
|
+
}
|
131
|
+
|
53
132
|
/**
|
54
133
|
*
|
55
134
|
*/
|
56
135
|
onComponentMounted() {
|
57
136
|
console.log('onComponentMounted', this.id);
|
58
137
|
}
|
138
|
+
|
139
|
+
/**
|
140
|
+
*
|
141
|
+
*/
|
142
|
+
onMarkerStoreLoad() {
|
143
|
+
let me = this;
|
144
|
+
|
145
|
+
me.markerStore.items.forEach(item => {
|
146
|
+
Neo.main.addon.GoogleMaps.addMarker({
|
147
|
+
mapId: me.id,
|
148
|
+
...item
|
149
|
+
})
|
150
|
+
})
|
151
|
+
}
|
59
152
|
}
|
60
153
|
|
61
154
|
Neo.applyClassConfig(GoogleMaps);
|
package/src/container/Base.mjs
CHANGED
@@ -191,6 +191,16 @@ class Base extends Component {
|
|
191
191
|
defaults = me.itemDefaults,
|
192
192
|
lazyLoadItem, module;
|
193
193
|
|
194
|
+
if (defaults) {
|
195
|
+
if (item.module) {
|
196
|
+
delete defaults.ntype;
|
197
|
+
}
|
198
|
+
|
199
|
+
if (item.ntype) {
|
200
|
+
delete defaults.module;
|
201
|
+
}
|
202
|
+
}
|
203
|
+
|
194
204
|
switch (Neo.typeOf(item)) {
|
195
205
|
case 'NeoClass': {
|
196
206
|
item = Neo.create({
|
@@ -1,5 +1,6 @@
|
|
1
|
-
import Base
|
2
|
-
import DomAccess
|
1
|
+
import Base from '../../core/Base.mjs';
|
2
|
+
import DomAccess from '../DomAccess.mjs';
|
3
|
+
import Observable from '../../core/Observable.mjs';
|
3
4
|
|
4
5
|
/**
|
5
6
|
* @class Neo.main.addon.GoogleMaps
|
@@ -17,13 +18,23 @@ class GoogleMaps extends Base {
|
|
17
18
|
* @member {Object} maps={}
|
18
19
|
*/
|
19
20
|
maps: {},
|
21
|
+
/**
|
22
|
+
* @member {Object} markers={}
|
23
|
+
*/
|
24
|
+
markers: {},
|
25
|
+
/**
|
26
|
+
* @member {Neo.core.Base[]} mixins=[Observable]
|
27
|
+
*/
|
28
|
+
mixins: [Observable],
|
20
29
|
/**
|
21
30
|
* @member {Object} remote
|
22
31
|
* @protected
|
23
32
|
*/
|
24
33
|
remote: {
|
25
34
|
app: [
|
26
|
-
'
|
35
|
+
'addMarker',
|
36
|
+
'create',
|
37
|
+
'removeMap'
|
27
38
|
]
|
28
39
|
},
|
29
40
|
/**
|
@@ -41,15 +52,56 @@ class GoogleMaps extends Base {
|
|
41
52
|
this.loadApi();
|
42
53
|
}
|
43
54
|
|
55
|
+
/**
|
56
|
+
* @param {Object} data
|
57
|
+
* @param {String} data.id
|
58
|
+
* @param {String} data.mapId
|
59
|
+
* @param {Object} data.position
|
60
|
+
* @param {String} [data.title]
|
61
|
+
*/
|
62
|
+
addMarker(data) {
|
63
|
+
let me = this;
|
64
|
+
|
65
|
+
if (!me.maps[data.mapId]) {
|
66
|
+
let listenerId = me.on('mapCreated', mapId => {
|
67
|
+
if (data.mapId === mapId) {
|
68
|
+
me.un(listenerId);
|
69
|
+
me.addMarker(data);
|
70
|
+
}
|
71
|
+
})
|
72
|
+
} else {
|
73
|
+
Neo.ns(`${data.mapId}`, true, me.markers);
|
74
|
+
|
75
|
+
me.markers[data.mapId][data.id] = new google.maps.Marker({
|
76
|
+
position: data.position,
|
77
|
+
map : me.maps[data.mapId],
|
78
|
+
title : data.title,
|
79
|
+
});
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
44
83
|
/**
|
45
84
|
* @param {Object} data
|
46
85
|
* @param {String} data.id
|
47
86
|
*/
|
48
87
|
create(data) {
|
49
|
-
|
88
|
+
let me = this;
|
89
|
+
|
90
|
+
me.maps[data.id] = new google.maps.Map(DomAccess.getElement(data.id), {
|
50
91
|
center: { lat: -34.397, lng: 150.644 },
|
51
92
|
zoom: 8,
|
52
93
|
});
|
94
|
+
|
95
|
+
me.fire('mapCreated', data.id);
|
96
|
+
}
|
97
|
+
|
98
|
+
/**
|
99
|
+
* @param {Object} data
|
100
|
+
* @param {String} data.mapId
|
101
|
+
*/
|
102
|
+
removeMap(data) {
|
103
|
+
delete this.maps[data.mapId];
|
104
|
+
delete this.markers[data.mapId];
|
53
105
|
}
|
54
106
|
|
55
107
|
/**
|
@@ -58,7 +110,7 @@ class GoogleMaps extends Base {
|
|
58
110
|
loadApi() {
|
59
111
|
DomAccess.loadScript('https://maps.googleapis.com/maps/api/js?key=AIzaSyCRj-EPE3H7PCzZtYCmDzln6sj7uPCGohA&v=weekly').then(() => {
|
60
112
|
console.log('GoogleMaps API loaded');
|
61
|
-
})
|
113
|
+
})
|
62
114
|
}
|
63
115
|
}
|
64
116
|
|
@@ -184,11 +184,15 @@ class Component extends Base {
|
|
184
184
|
}
|
185
185
|
|
186
186
|
/**
|
187
|
-
* Returns an Array containing all parent components for a given component
|
188
|
-
* @param {Neo.component.Base} component
|
187
|
+
* Returns an Array containing all parent components for a given component or component id
|
188
|
+
* @param {Neo.component.Base|String} component
|
189
189
|
* @returns {Neo.component.Base[]} parents
|
190
190
|
*/
|
191
191
|
getParents(component) {
|
192
|
+
if (Neo.isString(component)) {
|
193
|
+
component = this.getById(component);
|
194
|
+
}
|
195
|
+
|
192
196
|
let parents = [];
|
193
197
|
|
194
198
|
while (component?.parentId) {
|