Skip to content

Instantly share code, notes, and snippets.

@brigand
Last active January 6, 2016 07:49
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 brigand/2f5c038ebb77d55b031c to your computer and use it in GitHub Desktop.
Save brigand/2f5c038ebb77d55b031c to your computer and use it in GitHub Desktop.
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;
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