Last active
January 6, 2016 07:49
-
-
Save brigand/2f5c038ebb77d55b031c to your computer and use it in GitHub Desktop.
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 from 'react'; | |
import MapBox from './Map.jsx'; | |
var Component = React.createClass({ | |
getInitialState: function() { | |
return { | |
data: { | |
x: 0, | |
y: 0 | |
} | |
} | |
}, | |
handleChange(data) { | |
this.setState({data: data}); | |
}, | |
render: function () { | |
return ( | |
<div className='container'> | |
<MapBox onChange={this.handleChange} /> | |
<h3>{this.state.data.x} {this.state.data.y}</h3> | |
</div> | |
); | |
}, | |
propTypes: { | |
} | |
}); | |
export default Component; |
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
var MapBox = React.createClass({ | |
getPosition: function(ev) { | |
var x = ev.clientX; | |
var y = ev.clientY; | |
var rect = ev.target.getBoundingClientRect(); | |
x = x - rect.left | |
y = y - rect.top | |
this.props.onChange({x: x, y: y}); | |
}, | |
render: function () { | |
return ( | |
<canvas height='755' width='900' onClick={this.getPosition}></canvas> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment