Created
December 24, 2016 01:55
-
-
Save AndrewLipscomb/6a15e4f1ad2653ee23d1d15132f46a8f to your computer and use it in GitHub Desktop.
editcontrol.js with bug triggers
This file contains 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 { Map, TileLayer, Circle, FeatureGroup } from 'react-leaflet'; | |
import { EditControl } from '../src'; | |
let polyline; | |
const subs = [ 'a', 'b', 'c', 'd' ]; | |
export default class EditControlExample extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
showEdits: false, | |
}; | |
} | |
_onEditPath(e) { | |
console.log('Path edited !'); | |
} | |
_onCreate(e) { | |
polyline = e.layer; | |
// To edit this polyline call : polyline.handler.enable() | |
console.log('Path created !'); | |
} | |
_onDeleted(e) { | |
console.log('Path deleted !'); | |
} | |
_mounted(drawControl) { | |
console.log('Component mounted !'); | |
} | |
_onEditStart() { | |
console.log('Edit is starting !'); | |
} | |
_onEditStop() { | |
console.log('Edit is stopping !'); | |
} | |
_onDeleteStart() { | |
console.log('Delete is starting !'); | |
} | |
_onDeleteStop() { | |
console.log('Delete is stopping !'); | |
} | |
_onToggleEdits() { | |
this.setState({showEdits: !this.state.showEdits}); | |
console.log("Edit controls are now " + this.state.showEdits); | |
} | |
showEditControls() { | |
if (this.state.showEdits) { | |
return (<FeatureGroup> | |
<EditControl | |
position='topright' | |
onEdited={this._onEditPath} | |
onCreated={this._onCreate} | |
onDeleted={this._onDeleted} | |
onMounted={this._mounted} | |
onEditStart={this._onEditStart} | |
onEditStop={this._onEditStop} | |
onDeleteStart={this._onDeleteStart} | |
onDeleteStop={this._onDeleteStop} | |
draw={{ | |
rectangle: false | |
}} | |
/> | |
<Circle center={[51.51, -0.06]} radius={200} /> | |
</FeatureGroup>); | |
} else { | |
return null; | |
} | |
} | |
render() { | |
return ( | |
<div> | |
<button onClick={this._onToggleEdits.bind(this)}>Toggle Edits</button> | |
<Map center={[51.505, -0.09]} zoom={13} zoomControl={false}> | |
<TileLayer | |
attribution='© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' | |
url="https://{s}.tiles.mapbox.com/v4/{mapId}/{z}/{x}/{y}.png?access_token={token}" | |
mapId="mapbox.edf947b8" | |
token="pk.eyJ1IjoiYWxleDMxNjUiLCJhIjoiYWZ2b0ctdyJ9.8hDqOD5GlLfBfIxjHaa0qQ" | |
subdomains={subs} | |
/> | |
{this.showEditControls()} | |
</Map> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment