Skip to content

Commit e593b99

Browse files
committed
component.wrapper.GoogleMaps: zoomChange event #3725
1 parent c0e46ce commit e593b99

4 files changed

Lines changed: 50 additions & 7 deletions

File tree

examples/component/wrapper/googleMaps/MainContainer.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ class MainContainer extends Viewport {
2121
flex : 1,
2222
reference: 'google-maps-component',
2323

24+
listeners: {
25+
zoomChange: 'onMapZoomChance'
26+
},
27+
2428
markerStoreConfig: {
2529
data: [{
2630
id : '1',
@@ -50,6 +54,7 @@ class MainContainer extends Viewport {
5054
listeners : {change: 'onZoomFieldChange'},
5155
minValue : 0,
5256
maxValue : 10,
57+
reference : 'zoom-field',
5358
style : {marginLeft: '10px'},
5459
value : 8,
5560
width : 100

examples/component/wrapper/googleMaps/MainContainerController.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ class MainContainerController extends ComponentController {
2020
this.getReference('google-maps-component').panTo({lat: 37.655, lng: -122.4175})
2121
}
2222

23+
/**
24+
* @param {Object} data
25+
*/
26+
onMapZoomChance(data) {
27+
this.getReference('zoom-field').value = data.value;
28+
}
29+
2330
/**
2431
* @param {Object} data
2532
*/

src/component/wrapper/GoogleMaps.mjs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ class GoogleMaps extends Base {
8282
let me = this;
8383

8484
me.addDomListeners({
85-
googleMarkerClick: me.parseMarkerClick,
86-
local : false,
87-
scope : me
85+
googleMapZoomChange: me.onMapZoomChange,
86+
googleMarkerClick : me.parseMarkerClick,
87+
local : false,
88+
scope : me
8889
})
8990
}
9091

@@ -181,9 +182,16 @@ class GoogleMaps extends Base {
181182
*/
182183
afterSetZoom(value, oldValue) {
183184
if (oldValue !== undefined) {
185+
let me = this;
186+
184187
Neo.main.addon.GoogleMaps.setZoom({
185-
appName: this.appName,
186-
id : this.id,
188+
appName: me.appName,
189+
id : me.id,
190+
value
191+
});
192+
193+
me.fire('zoomChange', {
194+
id: me.id,
187195
value
188196
})
189197
}
@@ -226,6 +234,13 @@ class GoogleMaps extends Base {
226234
*/
227235
onComponentMounted() {}
228236

237+
/**
238+
* @param {Object} data
239+
*/
240+
onMapZoomChange(data) {
241+
this.zoom = data.value;
242+
}
243+
229244
/**
230245
* @param {Object} record
231246
*/

src/main/addon/GoogleMaps.mjs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,10 @@ class GoogleMaps extends Base {
107107
*/
108108
create(data) {
109109
let me = this,
110-
id = data.id;
110+
id = data.id,
111+
map;
111112

112-
me.maps[id] = new google.maps.Map(DomAccess.getElement(id), {
113+
me.maps[id] = map = new google.maps.Map(DomAccess.getElement(id), {
113114
center : data.center,
114115
fullscreenControl: data.fullscreenControl,
115116
maxZoom : data.maxZoom,
@@ -119,6 +120,8 @@ class GoogleMaps extends Base {
119120
...data.mapOptions
120121
});
121122

123+
map.addListener('zoom_changed', me.onMapZoomChange.bind(me, map, id));
124+
122125
me.fire('mapCreated', id);
123126
}
124127

@@ -142,6 +145,19 @@ class GoogleMaps extends Base {
142145
})
143146
}
144147

148+
/**
149+
* @param {google.maps.Map} map
150+
* @param {String} mapId
151+
*/
152+
onMapZoomChange(map, mapId){
153+
DomEvents.sendMessageToApp({
154+
id : mapId,
155+
path : [{cls: [], id: mapId}],
156+
type : 'googleMapZoomChange',
157+
value: map.zoom
158+
})
159+
}
160+
145161
/**
146162
* @param {google.maps.Marker} marker
147163
* @param {Object} event

0 commit comments

Comments
 (0)