kopia lustrzana https://github.com/OpenDroneMap/WebODM
Moar annotations stuff
rodzic
6a69f1e534
commit
3021849e21
|
@ -19,12 +19,16 @@ export default {
|
||||||
endpoints: [
|
endpoints: [
|
||||||
["willAddControls", leafletPreCheck],
|
["willAddControls", leafletPreCheck],
|
||||||
["didAddControls", layersControlPreCheck],
|
["didAddControls", layersControlPreCheck],
|
||||||
["addActionButton", leafletPreCheck],
|
["addActionButton", leafletPreCheck]
|
||||||
["didAddAnnotation"]
|
|
||||||
],
|
],
|
||||||
|
|
||||||
functions: [
|
functions: [
|
||||||
"handleClick"
|
"handleClick",
|
||||||
|
"addAnnotation",
|
||||||
|
"updateAnnotation",
|
||||||
|
"deleteAnnotation",
|
||||||
|
"toggleAnnotation",
|
||||||
|
"annotationDeleted"
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import '../css/LayersControlAnnotations.scss';
|
import '../css/LayersControlAnnotations.scss';
|
||||||
|
import PluginsAPI from '../classes/plugins/API';
|
||||||
import { Checkbox, ExpandButton } from './Toggle';
|
import { Checkbox, ExpandButton } from './Toggle';
|
||||||
import { _ } from '../classes/gettext';
|
import { _ } from '../classes/gettext';
|
||||||
|
|
||||||
class AnnotationLayer extends React.Component{
|
class AnnotationLayer extends React.Component{
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
|
parent: PropTypes.object,
|
||||||
layer: PropTypes.object
|
layer: PropTypes.object
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,8 +19,32 @@ class AnnotationLayer extends React.Component{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps, prevState){
|
||||||
|
if (prevState.visible !== this.state.visible && this.props.parent.state.visible){
|
||||||
|
PluginsAPI.Map.toggleAnnotation(this.props.layer, this.state.visible);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount(){
|
||||||
|
PluginsAPI.Map.onUpdateAnnotation(this.handleUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount(){
|
||||||
|
PluginsAPI.Map.offUpdateAnnotation(this.handleUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleUpdate = (layer, name) => {
|
||||||
|
if (this.props.layer === layer){
|
||||||
|
const meta = layer[Symbol.for("meta")];
|
||||||
|
meta.name = name;
|
||||||
|
this.forceUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleFocus = () => {
|
handleFocus = () => {
|
||||||
const { layer } = this.props;
|
const { layer } = this.props;
|
||||||
|
if (!layer._map) return;
|
||||||
|
|
||||||
if (layer.options.bounds || layer.getBounds){
|
if (layer.options.bounds || layer.getBounds){
|
||||||
const bounds = layer.options.bounds !== undefined ?
|
const bounds = layer.options.bounds !== undefined ?
|
||||||
layer.options.bounds :
|
layer.options.bounds :
|
||||||
|
@ -32,7 +58,9 @@ class AnnotationLayer extends React.Component{
|
||||||
}
|
}
|
||||||
|
|
||||||
handleDelete = () => {
|
handleDelete = () => {
|
||||||
|
if (window.confirm(_('Are you sure you want to delete this?'))){
|
||||||
|
PluginsAPI.Map.deleteAnnotation(this.props.layer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render(){
|
render(){
|
||||||
|
@ -51,13 +79,13 @@ export default class LayersControlAnnotations extends React.Component {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
expanded: true,
|
expanded: true,
|
||||||
visible: true
|
visible: true
|
||||||
|
};
|
||||||
};
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
expanded: PropTypes.bool,
|
expanded: PropTypes.bool,
|
||||||
visible: PropTypes.bool,
|
visible: PropTypes.bool,
|
||||||
layers: PropTypes.array
|
layers: PropTypes.array
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props){
|
constructor(props){
|
||||||
super(props);
|
super(props);
|
||||||
|
@ -66,11 +94,21 @@ export default class LayersControlAnnotations extends React.Component {
|
||||||
visible: props.visible,
|
visible: props.visible,
|
||||||
expanded: props.expanded
|
expanded: props.expanded
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.annRefs = new Array(props.layers.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleAnnotationsClick = () => {
|
||||||
|
this.setState({expanded: !this.state.expanded});
|
||||||
|
}
|
||||||
|
|
||||||
handleLayerClick = () => {
|
componentDidUpdate(prevProps, prevState){
|
||||||
console.log("TODO")
|
if (prevState.visible !== this.state.visible){
|
||||||
|
this.annRefs.forEach(ann => {
|
||||||
|
let visible = this.state.visible ? ann.state.visible : false;
|
||||||
|
PluginsAPI.Map.toggleAnnotation(ann.props.layer, visible);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,12 +119,12 @@ export default class LayersControlAnnotations extends React.Component {
|
||||||
return (<div className="layers-control-layer">
|
return (<div className="layers-control-layer">
|
||||||
<div className="layer-control-title">
|
<div className="layer-control-title">
|
||||||
<ExpandButton bind={[this, 'expanded']} /><Checkbox bind={[this, 'visible']}/>
|
<ExpandButton bind={[this, 'expanded']} /><Checkbox bind={[this, 'visible']}/>
|
||||||
<a title={_("Annotations")} className="layer-label" href="javascript:void(0);" onClick={this.handleLayerClick}><div className="layer-title"><i className="layer-icon fa fa-sticky-note fa-fw"></i> {_("Annotations")}</div></a>
|
<a title={_("Annotations")} className="layer-label" href="javascript:void(0);" onClick={this.handleAnnotationsClick}><div className="layer-title"><i className="layer-icon fa fa-sticky-note fa-fw"></i> {_("Annotations")}</div></a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{this.state.expanded ?
|
{this.state.expanded ?
|
||||||
<div className="layer-expanded">
|
<div className="layer-expanded">
|
||||||
{layers.map((layer, i) => <AnnotationLayer key={i} layer={layer} />)}
|
{layers.map((layer, i) => <AnnotationLayer parent={this} ref={domNode => this.annRefs[i] = domNode} key={i} layer={layer} />)}
|
||||||
</div> : ""}
|
</div> : ""}
|
||||||
</div>);
|
</div>);
|
||||||
|
|
||||||
|
|
|
@ -433,6 +433,9 @@ class Map extends React.Component {
|
||||||
// leaflet bug?
|
// leaflet bug?
|
||||||
$(this.container).addClass("leaflet-touch");
|
$(this.container).addClass("leaflet-touch");
|
||||||
|
|
||||||
|
PluginsAPI.Map.onAddAnnotation(this.handleAddAnnotation);
|
||||||
|
PluginsAPI.Map.onAnnotationDeleted(this.handleDeleteAnnotation);
|
||||||
|
|
||||||
PluginsAPI.Map.triggerWillAddControls({
|
PluginsAPI.Map.triggerWillAddControls({
|
||||||
map: this.map,
|
map: this.map,
|
||||||
tiles,
|
tiles,
|
||||||
|
@ -641,22 +644,25 @@ _('Example:'),
|
||||||
pluginActionButtons: {$push: [button]}
|
pluginActionButtons: {$push: [button]}
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
PluginsAPI.Map.didAddAnnotation([], (opts) => {
|
handleAddAnnotation = (layer, name, task) => {
|
||||||
const layer = opts.layer;
|
|
||||||
const meta = {
|
const meta = {
|
||||||
name: opts.name || "",
|
name: name || "",
|
||||||
icon: opts.icon || "fa fa-sticky-note fa-fw"
|
icon: "fa fa-sticky-note fa-fw"
|
||||||
};
|
};
|
||||||
if (this.props.tiles.length > 1 && opts.task){
|
if (this.props.tiles.length > 1 && opts.task){
|
||||||
meta.group = {id: opts.task.id, name: opts.task.name};
|
meta.group = {id: task.id, name: task.name};
|
||||||
}
|
}
|
||||||
layer[Symbol.for("meta")] = meta;
|
layer[Symbol.for("meta")] = meta;
|
||||||
|
|
||||||
this.setState(update(this.state, {
|
this.setState(update(this.state, {
|
||||||
annotations: {$push: [layer]}
|
annotations: {$push: [layer]}
|
||||||
}));
|
}));
|
||||||
});
|
}
|
||||||
|
|
||||||
|
handleDeleteAnnotation = (layer) => {
|
||||||
|
this.setState({annotations: this.state.annotations.filter(l => l !== layer)});
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps, prevState) {
|
componentDidUpdate(prevProps, prevState) {
|
||||||
|
@ -683,6 +689,10 @@ _('Example:'),
|
||||||
this.tileJsonRequests.forEach(tileJsonRequest => tileJsonRequest.abort());
|
this.tileJsonRequests.forEach(tileJsonRequest => tileJsonRequest.abort());
|
||||||
this.tileJsonRequests = [];
|
this.tileJsonRequests = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PluginsAPI.Map.offAddAnnotation(this.handleAddAnnotation);
|
||||||
|
PluginsAPI.Map.offAnnotationDeleted(this.handleAddAnnotation);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMapMouseDown(e){
|
handleMapMouseDown(e){
|
||||||
|
|
Ładowanie…
Reference in New Issue