kopia lustrzana https://github.com/OpenDroneMap/WebODM
Expand Map JS API
rodzic
04af329f78
commit
6f5d68d6ed
|
@ -15,13 +15,6 @@ export default class ApiFactory{
|
|||
// are more robust as we can detect more easily if
|
||||
// things break
|
||||
|
||||
// TODO: we should consider refactoring this code
|
||||
// to use functions instead of events. Originally
|
||||
// we chose to use events because that would have
|
||||
// decreased coupling, but since all API pubsub activity
|
||||
// evolved to require a call to the PluginsAPI object, we might have
|
||||
// added a bunch of complexity for no real advantage here.
|
||||
|
||||
const addEndpoint = (obj, eventName, preTrigger = () => {}) => {
|
||||
const emitResponse = response => {
|
||||
// Timeout needed for modules that have no dependencies
|
||||
|
@ -99,6 +92,26 @@ export default class ApiFactory{
|
|||
obj = Object.assign(obj, api.helpers);
|
||||
}
|
||||
|
||||
// Handle syncronous function on/off/export
|
||||
(api.functions || []).forEach(func => {
|
||||
let callbacks = [];
|
||||
obj[func] = (...args) => {
|
||||
for (let i = 0; i < callbacks.length; i++){
|
||||
if ((callbacks[i])(...args)) return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const onName = "on" + func[0].toUpperCase() + func.slice(1);
|
||||
const offName = "off" + func[0].toUpperCase() + func.slice(1);
|
||||
obj[onName] = f => {
|
||||
callbacks.push(f);
|
||||
};
|
||||
obj[offName] = f => {
|
||||
callbacks = callbacks.filter(cb => cb !== f);
|
||||
};
|
||||
});
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,11 @@ export default {
|
|||
endpoints: [
|
||||
["willAddControls", leafletPreCheck],
|
||||
["didAddControls", layersControlPreCheck],
|
||||
["addActionButton", leafletPreCheck],
|
||||
["addActionButton", leafletPreCheck]
|
||||
],
|
||||
|
||||
functions: [
|
||||
"handleClick"
|
||||
]
|
||||
};
|
||||
|
||||
|
|
|
@ -397,7 +397,8 @@ class Map extends React.Component {
|
|||
|
||||
PluginsAPI.Map.triggerWillAddControls({
|
||||
map: this.map,
|
||||
tiles
|
||||
tiles,
|
||||
mapView: this
|
||||
});
|
||||
|
||||
let scaleControl = Leaflet.control.scale({
|
||||
|
@ -524,6 +525,8 @@ _('Example:'),
|
|||
this.map.fitBounds(this.mapBounds);
|
||||
|
||||
this.map.on('click', e => {
|
||||
if (PluginsAPI.Map.handleClick(e)) return;
|
||||
|
||||
// Find first tile layer at the selected coordinates
|
||||
for (let layer of this.state.imageryLayers){
|
||||
if (layer._map && layer.options.bounds.contains(e.latlng)){
|
||||
|
|
Ładowanie…
Reference in New Issue