Skip to content

Commit

Permalink
Swipe tool to publisher.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aho Henri committed Dec 20, 2023
1 parent 7d7e838 commit 3a05363
Show file tree
Hide file tree
Showing 17 changed files with 630 additions and 1 deletion.
37 changes: 37 additions & 0 deletions bundles/framework/publisher2/handler/AdditionalToolsHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { controllerMixin } from 'oskari-ui/util';
import { ToolPanelHandler } from './ToolPanelHandler';
import '../tools/SwipeTool.js';

class UIHandler extends ToolPanelHandler {
constructor (tools, sandbox, consumer) {
// ToolPanelHandler adds tools to state so we can reference it here
super(tools, consumer);
this.sandbox = sandbox;
this.updateState({
tools: []
});
};

init (data) {
const hasTools = super.init(data);
return hasTools;
}

stop () {
const { tools } = this.getState();
tools.forEach(tool => {
try {
tool.publisherTool.stop();
} catch (e) {
Oskari.log('Publisher.AdditionalToolsHandler')
.error('Error stopping publisher tool:', tool.getTool().id);
}
});
}
}

const wrapped = controllerMixin(UIHandler, [
'setToolEnabled'
]);

export { wrapped as AdditionalToolsHandler };
50 changes: 50 additions & 0 deletions bundles/framework/publisher2/handler/SwipeToolHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { StateHandler, controllerMixin } from 'oskari-ui/util';

class UIHandler extends StateHandler {
constructor (tool) {
super();
this.tool = tool;
this.sandbox = tool.getSandbox();
this.setState({
autoStart: false,
hideUI: false
});
};
init (pluginConfig) {
this.updateState({
...pluginConfig
});
}

clearState () {
// plugin is created again on startup, so it's state doesn't need to be cleare
this.setState({
autoStart: false,
hideUI: false
});
}

setAutoStart (value) {
this.tool.getPlugin().setAutoStart(value);
this.updateConfig2State();
}

setHideUI (value) {
this.tool.getPlugin().setHideUI(value);
this.updateConfig2State();
}

updateConfig2State () {
const newConfig = this.tool?.getPlugin()?.getConfig() || {};
this.updateState({
...newConfig
});
}
}

const wrapped = controllerMixin(UIHandler, [
'setAutoStart',
'setHideUI'
]);

export { wrapped as SwipeToolhandler };
7 changes: 7 additions & 0 deletions bundles/framework/publisher2/resources/locale/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ Oskari.registerLocalization(
},
"panButtonsOptions": {
"showArrows": "Pan tool"
},
"swipe": {
"label": "Compare map layers",
"autoStart": "Start automatically"
}
},
"toollayout": {
Expand Down Expand Up @@ -247,6 +251,9 @@ Oskari.registerLocalization(
"noBaseLayers": "No selected background maps",
"noLayers": "No selected map layers"
},
"additionalTools": {
"label": "Additional tools"
},
"preview": "Map preview",
"location": "Location and zoom level",
"zoomlevel": "Zoom level",
Expand Down
7 changes: 7 additions & 0 deletions bundles/framework/publisher2/resources/locale/fi.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ Oskari.registerLocalization(
},
"panButtonsOptions": {
"showArrows": "Kartan liikuttaminen nuolipainikkeilla"
},
"swipe": {
"label": "Tasojen vertailutyökalu",
"autoStart": "Käynnistä automaattisesti"
}
},
"toollayout": {
Expand Down Expand Up @@ -247,6 +251,9 @@ Oskari.registerLocalization(
"noBaseLayers": "Ei valittuja taustakarttoja",
"noLayers": "Ei valittuja karttatasoja"
},
"additionalTools": {
"label": "Lisätyökalut"
},
"preview": "Kartan esikatselu",
"location": "Sijainti ja mittakaavataso",
"zoomlevel": "Mittakaavataso",
Expand Down
7 changes: 7 additions & 0 deletions bundles/framework/publisher2/resources/locale/sv.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ Oskari.registerLocalization(
},
"panButtonsOptions": {
"showArrows": "Panoreringsverktyg"
},
"swipe": {
"label": "Jämför kartlagret högst uppe med nedanstående kartlager",
"autoStart": "Starta automatisk"
}
},
"toollayout": {
Expand Down Expand Up @@ -247,6 +251,9 @@ Oskari.registerLocalization(
"noBaseLayers": "Inga bakgrundskartor valda",
"noLayers": "Inga kartlager valda"
},
"additionalTools": {
"label": "Ytterligare verktyg"
},
"preview": "Den inbäddade kartans förhandsgranskningsvy",
"location": "Läge och skalnivå.",
"zoomlevel": "Skalnivå",
Expand Down
73 changes: 73 additions & 0 deletions bundles/framework/publisher2/tools/AdditionalTool.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* @class Oskari.mapframework.publisher.tool.AdditionalTool
* This clazz documentates publisher2 react tool definations.
* Protocol/interface declaration for Publisher2 react tool.
* Provides an interface for bundles to add react tools to publisher2.
*/

Oskari.clazz.define('Oskari.mapframework.publisher.tool.AdditionalTool',
function (sandbox, mapmodule, localization) {
this._log = Oskari.log('publisher.AdditionalTool');
// sandbox
this.__sandbox = sandbox;
// mapmodule
this.__mapmodule = mapmodule;
// localization
this.__loc = localization;
// plugin
this.__plugin = null;
}, {
group: 'additional',
/**
* Initialize tool
* Override
* @method init
* @param pdata Publisher data. Includes tools' getValues return values
* @public
*/
init: function (pdata) {
this._log.error('Override init function for Tool ' + this.getTool().id);
},
/**
* Get tool object.
* @method getComponent
* @private
*
* @returns {Object}
*/
getComponent: function () {
this._log.error('Override getComponent function for Tool ' + this.getTool().id);
},
/**
* Get name.
* @method getName
* @public
*
* @returns {String} tool name
*/
getName: function () {

},
/**
* Is displayed.
* @method isDisplayed
* @public
*
* @returns {Boolean} is tool displayed
*/
isDisplayed: function () {
return true;
},
/**
* Get values.
* @method getValues
* @public
*
* @returns {Object} tool value object
*/
getValues: function () {
return null;
}
}, {
'protocol': ['Oskari.mapframework.publisher.AdditionalTool']
});
60 changes: 60 additions & 0 deletions bundles/framework/publisher2/tools/SwipeTool.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { AbstractPublisherTool } from './AbstractPublisherTool';
import { SwipeToolhandler } from '../handler/SwipeToolHandler';
import { SwipeToolComponent } from '../view/swipe/SwipeToolComponent';

export const SWIPE_ID = 'Oskari.mapframework.bundle.layerswipe.plugin.LayerSwipePlugin';

class SwipeTool extends AbstractPublisherTool {
constructor (...args) {
super(...args);
this.index = 5;
this.group = 'additional';
this.handler = new SwipeToolhandler(this);
}
getTool () {
return {
id: SWIPE_ID,
title: Oskari.getMsg('Publisher2', 'BasicView.maptools.swipe.label'),
config: this.state.pluginConfig || {}
};
}
getComponent () {
return {
component: SwipeToolComponent,
handler: this.handler
};
}
init (data) {
super.init(data);
// restore state to handler -> passing init data to it
this.handler.init(this.getTool().config);
}
getValues () {
if (!this.isEnabled()) {
return null;
}
const pluginConfig = this.getPlugin().getConfig();
const value = {
configuration: {
mapfull: {
conf: {
plugins: [{ id: this.getTool().id, config: pluginConfig }]
}
}
}
};
return value;
}
stop () {
super.stop();
this.handler.clearState();
}
}

// Attach protocol to make this discoverable by Oskari publisher
Oskari.clazz.defineES('Oskari.publisher.SwipeTool',
SwipeTool,
{
'protocol': ['Oskari.mapframework.publisher.AdditionalTool']
}
);
Loading

0 comments on commit 3a05363

Please sign in to comment.