Last active
February 19, 2019 10:57
-
-
Save donjajo/692f5600b7a0f04b6ab3cf4520f2a538 to your computer and use it in GitHub Desktop.
Reactjs Datamap wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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