Skip to content

Instantly share code, notes, and snippets.

@donjajo
Last active February 19, 2019 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donjajo/692f5600b7a0f04b6ab3cf4520f2a538 to your computer and use it in GitHub Desktop.
Save donjajo/692f5600b7a0f04b6ab3cf4520f2a538 to your computer and use it in GitHub Desktop.
Reactjs Datamap wrapper
import React, { Component } from "react";
import { withScriptjs, withGoogleMap, GoogleMap, Marker } from "react-google-maps";
import Datamap from 'datamaps'
import API from '../../../../api/MapKey';
class Map extends Component {
constructor( props ) {
super( props )
this.state = {
datamap : null
}
this.datamaps = null
this.element = React.createRef()
}
componentDidMount() {
this.renderDataMaps( 'world' )
}
renderDataMaps( scope ) {
let existing = document.querySelectorAll( '.datamap' )
existing.forEach( node => node.parentNode.removeChild( node ) )
this.setState({ datamap : new Datamap({ element : this.element.current, scope }) })
}
render() {
return(
<div ref={ this.element } style={ { height : '500px', width : '500px' } }>
<button onClick={ this.renderDataMaps.bind( this, 'usa' )}>Show USA</button>
</div>
)
}
}
export default Map;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment