-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/custom-area' into develop
- Loading branch information
Showing
19 changed files
with
581 additions
and
60 deletions.
There are no files selected for viewing
Binary file not shown.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import React from 'react' | ||
import { Paper, TextField } from '@material-ui/core' | ||
import { withStyles } from '@material-ui/core/styles' | ||
import PropTypes from 'prop-types' | ||
import store from '../stores/poi-store' | ||
import selection from './App.selection' | ||
|
||
class AOIProperties extends React.Component { | ||
constructor (props) { | ||
super(props) | ||
|
||
// FIXME: provide all properties to that we don't have to query store | ||
// Must set name if undefined in order for name TextField to be controlled. | ||
const aoi = store.state()[props.uuid] | ||
if (!aoi.name) aoi.name = '' | ||
this.state = { ...aoi } | ||
} | ||
|
||
handleNameChange (value) { | ||
store.rename(this.props.uuid, value) | ||
this.setState({ ...this.state, name: value }) | ||
} | ||
|
||
handleKeyDown (event) { | ||
switch (event.key) { | ||
case 'Escape': return selection.deselect() | ||
case 'Enter': | ||
if (event.target.tagName !== 'TEXTAREA') selection.deselect() | ||
break | ||
} | ||
} | ||
|
||
handleCommentChange (value) { | ||
this.setState({ ...this.state, comment: value }) | ||
} | ||
|
||
handleCommentBlur (value) { | ||
store.comment(this.props.uuid, value) | ||
} | ||
|
||
render () { | ||
const { name, comment, hidden } = this.state | ||
const style = { | ||
display: hidden ? 'none' : 'grid' | ||
} | ||
|
||
return ( | ||
<Paper | ||
className={ this.props.classes.paper } | ||
style={ style } | ||
elevation={ 4 } | ||
onKeyDown={ event => this.handleKeyDown(event) } | ||
> | ||
<TextField | ||
className={ this.props.classes.name } | ||
label={ 'Name' } | ||
value={ name } | ||
onChange={ event => this.handleNameChange(event.target.value) } | ||
/> | ||
<TextField | ||
className={ this.props.classes.comment } | ||
label={ 'Comment '} | ||
value={ comment } | ||
multiline | ||
onChange={ event => this.handleCommentChange(event.target.value) } | ||
onBlur={ event => this.handleCommentBlur(event.target.value) } | ||
> | ||
</TextField> | ||
</Paper> | ||
) | ||
} | ||
} | ||
|
||
const styles = theme => ({ | ||
paper: { | ||
padding: theme.spacing.unit * 4, | ||
height: 'auto', | ||
pointerEvents: 'auto', | ||
gridArea: 'R', | ||
background: 'rgba(252, 252, 255, 0.9)', | ||
|
||
display: 'grid', | ||
gridTemplateRows: 'max-content max-content max-content', | ||
gridTemplatecolumns: 'auto auto', | ||
gridGap: '2em', | ||
gridTemplateAreas: ` | ||
"name name" | ||
"comment comment" | ||
` | ||
}, | ||
name: { | ||
gridArea: 'name' | ||
}, | ||
comment: { | ||
gridArea: 'comment', | ||
overflow: 'auto' | ||
} | ||
}) | ||
|
||
AOIProperties.propTypes = { | ||
classes: PropTypes.any.isRequired, | ||
uuid: PropTypes.any.isRequired | ||
} | ||
|
||
export default withStyles(styles)(AOIProperties) |
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
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import L from 'leaflet' | ||
import { K } from '../../shared/combinators' | ||
|
||
L.Area = L.Polygon.extend({ | ||
initialize (latlngs, options) { | ||
L.setOptions(this, options) | ||
L.Polygon.prototype.initialize.call(this, latlngs, options) | ||
}, | ||
|
||
onAdd (map) { | ||
L.Polygon.prototype.onAdd.call(this, map) | ||
|
||
this.label = K(L.SVG.create('text'))(text => { | ||
const lines = [] | ||
if (this.options.type) lines.push(this.options.type) | ||
if (this.options.t) lines.push(this.options.t) | ||
|
||
const point = this.centerOfMass() | ||
text.textContent = lines[0] | ||
text.setAttribute('x', point[0]) | ||
text.setAttribute('y', point[1]) | ||
text.setAttribute('text-anchor', 'middle') | ||
|
||
lines.splice(1).forEach(line => { | ||
const tspan = L.SVG.create('tspan') | ||
tspan.textContent = line | ||
tspan.setAttribute('text-anchor', 'middle') | ||
tspan.setAttribute('dy', '1.2em') | ||
tspan.setAttribute('x', point[0]) | ||
text.appendChild(tspan) | ||
}) | ||
|
||
const group = this._path.parentElement | ||
group.appendChild(text) | ||
}) | ||
|
||
this.updateLabelPosition() | ||
}, | ||
|
||
onRemove (map) { | ||
const group = this._path.parentElement | ||
if (this.label) group.removeChild(this.label) | ||
L.Polygon.prototype.onRemove.call(this, map) | ||
}, | ||
|
||
redraw () { | ||
L.Polygon.prototype.redraw.call(this) | ||
this.updateLabelPosition() | ||
}, | ||
|
||
updateLabelPosition () { | ||
if (!this.label) return | ||
const point = this.centerOfMass() | ||
this.label.setAttribute('x', point[0]) | ||
this.label.setAttribute('y', point[1]) | ||
|
||
Array.from(this.label.childNodes) | ||
.splice(1) | ||
.forEach(child => child.setAttribute('x', point[0])) | ||
}, | ||
|
||
_project () { | ||
L.Polygon.prototype._project.call(this) | ||
this.updateLabelPosition() | ||
}, | ||
|
||
/** | ||
* Optimization. | ||
* Mostly Polygon.getCenter() without layerPointToLatLng(). | ||
* | ||
* @returns layer point instead of latlng | ||
*/ | ||
centerOfMass () { | ||
const points = this._rings[0] | ||
const len = points.length | ||
if (!len) return null | ||
|
||
// polygon centroid algorithm; only uses the first ring if there are multiple | ||
let area = 0 | ||
let x = 0 | ||
let y = 0 | ||
|
||
for (let i = 0, j = len - 1; i < len; j = i++) { | ||
const f = points[i].y * points[j].x - points[j].y * points[i].x | ||
x += (points[i].x + points[j].x) * f | ||
y += (points[i].y + points[j].y) * f | ||
area += f * 3 | ||
} | ||
|
||
if (area === 0) return [points[0].x, points[0].y] | ||
else return [x / area, y / area] | ||
} | ||
}) |
Oops, something went wrong.