kopia lustrzana https://github.com/OpenDroneMap/WebODM
Added ability for JS plugins API to return values upon initialization, osm-quickedit mock
rodzic
f7b5161a43
commit
cd7ba253cf
|
@ -8,7 +8,6 @@ export default class ApiFactory{
|
||||||
|
|
||||||
// @param api {Object}
|
// @param api {Object}
|
||||||
create(api){
|
create(api){
|
||||||
|
|
||||||
// Adds two functions to obj
|
// Adds two functions to obj
|
||||||
// - eventName
|
// - eventName
|
||||||
// - triggerEventName
|
// - triggerEventName
|
||||||
|
@ -16,6 +15,10 @@ export default class ApiFactory{
|
||||||
// are more robust as we can detect more easily if
|
// are more robust as we can detect more easily if
|
||||||
// things break
|
// things break
|
||||||
const addEndpoint = (obj, eventName, preTrigger = () => {}) => {
|
const addEndpoint = (obj, eventName, preTrigger = () => {}) => {
|
||||||
|
const askForResponse = (...args) => {
|
||||||
|
this.events.emit(`${api.namespace}::${eventName}::Response`, ...args);
|
||||||
|
};
|
||||||
|
|
||||||
obj[eventName] = (callbackOrDeps, callbackOrUndef) => {
|
obj[eventName] = (callbackOrDeps, callbackOrUndef) => {
|
||||||
if (Array.isArray(callbackOrDeps)){
|
if (Array.isArray(callbackOrDeps)){
|
||||||
// Deps
|
// Deps
|
||||||
|
@ -24,20 +27,23 @@ export default class ApiFactory{
|
||||||
this.events.addListener(`${api.namespace}::${eventName}`, (...args) => {
|
this.events.addListener(`${api.namespace}::${eventName}`, (...args) => {
|
||||||
Promise.all(callbackOrDeps.map(dep => SystemJS.import(dep)))
|
Promise.all(callbackOrDeps.map(dep => SystemJS.import(dep)))
|
||||||
.then((...deps) => {
|
.then((...deps) => {
|
||||||
callbackOrUndef(...(Array.from(args).concat(...deps)));
|
askForResponse(callbackOrUndef(...(Array.from(args).concat(...deps))));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
// Callback
|
// Callback
|
||||||
this.events.addListener(`${api.namespace}::${eventName}`, callbackOrDeps);
|
this.events.addListener(`${api.namespace}::${eventName}`, (...args) => {
|
||||||
|
askForResponse(callbackOrDeps(...args));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const triggerEventName = "trigger" + eventName[0].toUpperCase() + eventName.slice(1);
|
const triggerEventName = "trigger" + eventName[0].toUpperCase() + eventName.slice(1);
|
||||||
|
|
||||||
obj[triggerEventName] = (...args) => {
|
obj[triggerEventName] = (params, responseCb) => {
|
||||||
preTrigger(...args);
|
preTrigger(params, responseCb);
|
||||||
this.events.emit(`${api.namespace}::${eventName}`, ...args);
|
this.events.emit(`${api.namespace}::${eventName}`, params);
|
||||||
|
if (responseCb) this.events.addListener(`${api.namespace}::${eventName}::Response`, responseCb);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,8 @@ export default {
|
||||||
|
|
||||||
endpoints: [
|
endpoints: [
|
||||||
["willAddControls", leafletPreCheck],
|
["willAddControls", leafletPreCheck],
|
||||||
["didAddControls", leafletPreCheck]
|
["didAddControls", leafletPreCheck],
|
||||||
|
["addActionButtons", leafletPreCheck],
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import ShareButton from './ShareButton';
|
||||||
import AssetDownloads from '../classes/AssetDownloads';
|
import AssetDownloads from '../classes/AssetDownloads';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import PluginsAPI from '../classes/plugins/API';
|
import PluginsAPI from '../classes/plugins/API';
|
||||||
|
import update from 'immutability-helper';
|
||||||
|
|
||||||
class Map extends React.Component {
|
class Map extends React.Component {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
|
@ -40,7 +41,8 @@ class Map extends React.Component {
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
error: "",
|
error: "",
|
||||||
singleTask: null // When this is set to a task, show a switch mode button to view the 3d model
|
singleTask: null, // When this is set to a task, show a switch mode button to view the 3d model
|
||||||
|
pluginActionButtons: []
|
||||||
};
|
};
|
||||||
|
|
||||||
this.imageryLayers = [];
|
this.imageryLayers = [];
|
||||||
|
@ -236,12 +238,17 @@ class Map extends React.Component {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// PluginsAPI.events.addListener('Map::AddPanel', (e) => {
|
|
||||||
// console.log("Received response: " + e);
|
|
||||||
// });
|
|
||||||
PluginsAPI.Map.triggerDidAddControls({
|
PluginsAPI.Map.triggerDidAddControls({
|
||||||
map: this.map
|
map: this.map
|
||||||
});
|
});
|
||||||
|
|
||||||
|
PluginsAPI.Map.triggerAddActionButtons({
|
||||||
|
map: this.map
|
||||||
|
}, (button) => {
|
||||||
|
this.setState(update(this.state, {
|
||||||
|
pluginActionButtons: {$push: [button]}
|
||||||
|
}));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
|
@ -285,6 +292,7 @@ class Map extends React.Component {
|
||||||
|
|
||||||
|
|
||||||
<div className="actionButtons">
|
<div className="actionButtons">
|
||||||
|
{this.state.pluginActionButtons.map((button, i) => <div key={i}>{button}</div>)}
|
||||||
{(!this.props.public && this.state.singleTask !== null) ?
|
{(!this.props.public && this.state.singleTask !== null) ?
|
||||||
<ShareButton
|
<ShareButton
|
||||||
ref={(ref) => { this.shareButton = ref; }}
|
ref={(ref) => { this.shareButton = ref; }}
|
||||||
|
|
|
@ -36,8 +36,6 @@ module.exports = class MeasurePopup extends React.Component {
|
||||||
lastCoord.dd.x
|
lastCoord.dd.x
|
||||||
));
|
));
|
||||||
|
|
||||||
console.log(layers);
|
|
||||||
|
|
||||||
// Did we select a layer?
|
// Did we select a layer?
|
||||||
if (layers.length > 0){
|
if (layers.length > 0){
|
||||||
const layer = layers[layers.length - 1];
|
const layer = layers[layers.length - 1];
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
from .plugin import *
|
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"name": "OSM Quick Editor Button",
|
||||||
|
"webodmMinVersion": "0.5.2",
|
||||||
|
"description": "A plugin to add a button for quickly opening OpenStreetMap's iD editor and setup a TMS basemap.",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"author": "Piero Toffanin",
|
||||||
|
"email": "pt@masseranolabs.com",
|
||||||
|
"repository": "https://github.com/OpenDroneMap/WebODM",
|
||||||
|
"tags": ["osm", "editor"],
|
||||||
|
"homepage": "https://github.com/OpenDroneMap/WebODM",
|
||||||
|
"experimental": true,
|
||||||
|
"deprecated": false
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
from app.plugins import PluginBase, Menu, MountPoint
|
||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
class Plugin(PluginBase):
|
||||||
|
def include_js_files(self):
|
||||||
|
return ['main.js']
|
||||||
|
|
||||||
|
# def include_css_files(self):
|
||||||
|
# return ['test.css']
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
PluginsAPI.Map.addActionButtons([
|
||||||
|
'osm-quickedit/main.css'
|
||||||
|
], function(options){
|
||||||
|
|
||||||
|
console.log("PLUGIN INIT!");
|
||||||
|
return React.createElement("div", null, "HELLO");
|
||||||
|
});
|
Ładowanie…
Reference in New Issue