Skip to content

Commit

Permalink
Add prop onTilesLoaded (#615)
Browse files Browse the repository at this point in the history
* Add prop `onTilesLoaded`

* (Adjust package name

* Increase version

* Make linter happy

* Remove scope from package name and reset version number

* Add description for new prop

* Remove "directories" entry

* Correct changelog

* Remove section header

* v2.0.0

* Revert version number

* Only listen to event if prop is used
  • Loading branch information
jonathanweiss authored and itsmichaeldiego committed Aug 3, 2018
1 parent 55f134c commit 6d142cb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ When the user changes the map type (HYBRID, ROADMAP, SATELLITE, TERRAIN) this fi
#### onGoogleApiLoaded (func)
Directly access the maps API - *use at your own risk!*
#### onTilesLoaded (func)
This function is called when the visible tiles have finished loading.
```javascript
<GoogleMap onGoogleApiLoaded={({map, maps}) => console.log(map, maps)} />
```
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Add [google-map-clustering-example](https://github.com/istarkov/google-map-clustering-example)

Add prop `onTilesLoaded` to react on the `tilesloaded` event

###0.9v

Add: `bootstrapURLKeys` (object) instead of `apiKey` prop
Expand Down
11 changes: 9 additions & 2 deletions src/google_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export default class GoogleMap extends Component {
onZoomAnimationEnd: PropTypes.func,
onDrag: PropTypes.func,
onMapTypeIdChange: PropTypes.func,
onTilesLoaded: PropTypes.func,
options: PropTypes.any,
distanceToMouse: PropTypes.func,
hoverDistance: PropTypes.number,
Expand Down Expand Up @@ -255,7 +256,6 @@ export default class GoogleMap extends Component {
}

window.addEventListener('mouseup', this._onChildMouseUp, false);

const bootstrapURLKeys = {
...(this.props.apiKey && { key: this.props.apiKey }),
...this.props.bootstrapURLKeys,
Expand Down Expand Up @@ -601,7 +601,6 @@ export default class GoogleMap extends Component {
maps,
overlay.getProjection()
);

ReactDOM.unstable_renderSubtreeIntoContainer(
this_,
<GoogleMapMarkers
Expand Down Expand Up @@ -663,6 +662,12 @@ export default class GoogleMap extends Component {
this.heatmap.setMap(map);
}

if (this.props.onTilesLoaded) {
maps.event.addListener(map, 'tilesloaded', () => {
this_._onTilesLoaded();
});
}

maps.event.addListener(map, 'zoom_changed', () => {
// recalc position at zoom start
if (this_.geoService_.getZoom() !== map.getZoom()) {
Expand Down Expand Up @@ -797,6 +802,8 @@ export default class GoogleMap extends Component {
_onZoomAnimationEnd = (...args) =>
this.props.onZoomAnimationEnd && this.props.onZoomAnimationEnd(...args);

_onTilesLoaded = () => this.props.onTilesLoaded && this.props.onTilesLoaded();

_onChildClick = (...args) => {
if (this.props.onChildClick) {
return this.props.onChildClick(...args);
Expand Down

0 comments on commit 6d142cb

Please sign in to comment.