From a3f41f3d212024afcdea1657e9d7d83bb62fb4bd Mon Sep 17 00:00:00 2001 From: cybice Date: Thu, 1 Oct 2015 09:46:56 +0300 Subject: [PATCH] Add onClick, onZoomAnimationStart, onZoomAnimationEnd events. onClick closes #18 onZoomAnimationStart, onZoomAnimationEnd - I need to prevent some costly updates --- src/google_map.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/google_map.js b/src/google_map.js index 6ebd533..19d483b 100644 --- a/src/google_map.js +++ b/src/google_map.js @@ -56,9 +56,12 @@ export default class GoogleMap extends Component { center: PropTypes.array.isRequired, zoom: PropTypes.number.isRequired, onBoundsChange: PropTypes.func, + onClick: PropTypes.func, onChildClick: PropTypes.func, onChildMouseEnter: PropTypes.func, onChildMouseLeave: PropTypes.func, + onZoomAnimationStart: PropTypes.func, + onZoomAnimationEnd: PropTypes.func, options: PropTypes.any, distanceToMouse: PropTypes.func, hoverDistance: PropTypes.number, @@ -104,6 +107,8 @@ export default class GoogleMap extends Component { this.geoService_.setView(this.props.center, this.props.zoom, 0); } + this.zoomAnimationInProgress_ = false; + this.state = { overlayCreated: false }; @@ -214,6 +219,11 @@ export default class GoogleMap extends Component { maps.event.addListener(map, 'zoom_changed', () => { // recalc position at zoom start if(this_.geoService_.getZoom() !== map.getZoom()) { + if (!this_.zoomAnimationInProgress_) { + this_.zoomAnimationInProgress_ = true; + this_._onZoomAnimationStart(); + } + this_.updateCounter_++; this_._onBoundsChanged(map, maps); } @@ -225,6 +235,11 @@ export default class GoogleMap extends Component { this.resetSizeOnIdle_ = false; } + if(this_.zoomAnimationInProgress_) { + this_.zoomAnimationInProgress_ = false; + this_._onZoomAnimationEnd() + } + const div = overlay.div; const overlayProjection = overlay.getProjection(); const bounds = map.getBounds(); @@ -268,6 +283,12 @@ export default class GoogleMap extends Component { }); } + _onZoomAnimationStart = (...args) => this.props.onZoomAnimationStart && + this.props.onZoomAnimationStart(...args) + + _onZoomAnimationEnd = (...args) => this.props.onZoomAnimationEnd && + this.props.onZoomAnimationEnd(...args) + _onChildClick = (...args) => { if (this.props.onChildClick) { return this.props.onChildClick(...args); @@ -371,11 +392,19 @@ export default class GoogleMap extends Component { } } - _onMapClick = () => { + _onClick = (...args) => this.props.onClick && + this.props.onClick(...args) + + _onMapClick = (event) => { if (this.markersDispatcher_) { const K_IDLE_TIMEOUT = 100; const currTime = (new Date()).getTime(); if (currTime - this.dragTime_ > K_IDLE_TIMEOUT) { + this._onClick({ + ...this.mouse_, + event, + }); + this.markersDispatcher_.emit('kON_CLICK'); } }