Added ability for JS plugins API to return values upon initialization, osm-quickedit mock

pull/444/head
Piero Toffanin 2018-04-29 16:39:57 -04:00
rodzic f7b5161a43
commit cd7ba253cf
9 zmienionych plików z 59 dodań i 13 usunięć

Wyświetl plik

@ -8,7 +8,6 @@ export default class ApiFactory{
// @param api {Object}
create(api){
// Adds two functions to obj
// - eventName
// - triggerEventName
@ -16,6 +15,10 @@ export default class ApiFactory{
// are more robust as we can detect more easily if
// things break
const addEndpoint = (obj, eventName, preTrigger = () => {}) => {
const askForResponse = (...args) => {
this.events.emit(`${api.namespace}::${eventName}::Response`, ...args);
};
obj[eventName] = (callbackOrDeps, callbackOrUndef) => {
if (Array.isArray(callbackOrDeps)){
// Deps
@ -24,20 +27,23 @@ export default class ApiFactory{
this.events.addListener(`${api.namespace}::${eventName}`, (...args) => {
Promise.all(callbackOrDeps.map(dep => SystemJS.import(dep)))
.then((...deps) => {
callbackOrUndef(...(Array.from(args).concat(...deps)));
askForResponse(callbackOrUndef(...(Array.from(args).concat(...deps))));
});
});
}else{
// 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);
obj[triggerEventName] = (...args) => {
preTrigger(...args);
this.events.emit(`${api.namespace}::${eventName}`, ...args);
obj[triggerEventName] = (params, responseCb) => {
preTrigger(params, responseCb);
this.events.emit(`${api.namespace}::${eventName}`, params);
if (responseCb) this.events.addListener(`${api.namespace}::${eventName}::Response`, responseCb);
};
}

Wyświetl plik

@ -12,7 +12,8 @@ export default {
endpoints: [
["willAddControls", leafletPreCheck],
["didAddControls", leafletPreCheck]
["didAddControls", leafletPreCheck],
["addActionButtons", leafletPreCheck],
]
};

Wyświetl plik

@ -14,6 +14,7 @@ import ShareButton from './ShareButton';
import AssetDownloads from '../classes/AssetDownloads';
import PropTypes from 'prop-types';
import PluginsAPI from '../classes/plugins/API';
import update from 'immutability-helper';
class Map extends React.Component {
static defaultProps = {
@ -40,7 +41,8 @@ class Map extends React.Component {
this.state = {
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 = [];
@ -236,12 +238,17 @@ class Map extends React.Component {
});
});
// PluginsAPI.events.addListener('Map::AddPanel', (e) => {
// console.log("Received response: " + e);
// });
PluginsAPI.Map.triggerDidAddControls({
map: this.map
});
PluginsAPI.Map.triggerAddActionButtons({
map: this.map
}, (button) => {
this.setState(update(this.state, {
pluginActionButtons: {$push: [button]}
}));
});
}
componentDidUpdate(prevProps) {
@ -285,6 +292,7 @@ class Map extends React.Component {
<div className="actionButtons">
{this.state.pluginActionButtons.map((button, i) => <div key={i}>{button}</div>)}
{(!this.props.public && this.state.singleTask !== null) ?
<ShareButton
ref={(ref) => { this.shareButton = ref; }}

Wyświetl plik

@ -36,8 +36,6 @@ module.exports = class MeasurePopup extends React.Component {
lastCoord.dd.x
));
console.log(layers);
// Did we select a layer?
if (layers.length > 0){
const layer = layers[layers.length - 1];

Wyświetl plik

@ -0,0 +1 @@
from .plugin import *

Wyświetl plik

@ -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
}

Wyświetl plik

@ -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']

Wyświetl plik

@ -0,0 +1,7 @@
PluginsAPI.Map.addActionButtons([
'osm-quickedit/main.css'
], function(options){
console.log("PLUGIN INIT!");
return React.createElement("div", null, "HELLO");
});