From b4489a97f8fc749dc312c4da38473b4b3f192616 Mon Sep 17 00:00:00 2001 From: Mauro Bartolomeoli Date: Fri, 13 Jan 2017 17:06:44 +0100 Subject: [PATCH] Implemented dynamic tools for the Map plugin --- web/client/plugins/Map.jsx | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/web/client/plugins/Map.jsx b/web/client/plugins/Map.jsx index 62c36ab984..d7e41f9ced 100644 --- a/web/client/plugins/Map.jsx +++ b/web/client/plugins/Map.jsx @@ -14,7 +14,7 @@ var Spinner = require('react-spinkit'); require('./map/css/map.css'); const Message = require('../components/I18N/Message'); - +const {isString} = require('lodash'); let plugins; const MapPlugin = React.createClass({ @@ -76,6 +76,25 @@ const MapPlugin = React.createClass({ })} ); }, + getTool(tool) { + if (isString(tool)) { + return { + name: tool, + impl: plugins.tools[tool] + }; + } + return tool[this.props.mapType] || tool; + }, + renderLayers() { + const projection = this.props.map.projection || 'EPSG:3857'; + return this.props.layers.map((layer, index) => { + return ( + + {this.renderLayerContent(layer)} + + ); + }).concat(this.props.features && this.props.features.length && this.getHighlightLayer(projection, this.props.layers.length) || []); + }, renderLayerContent(layer) { if (layer.features && layer.type === "vector") { return layer.features.map( (feature) => { @@ -93,21 +112,11 @@ const MapPlugin = React.createClass({ } return null; }, - renderLayers() { - const projection = this.props.map.projection || 'EPSG:3857'; - return this.props.layers.map((layer, index) => { - return ( - - {this.renderLayerContent(layer)} - - ); - }).concat(this.props.features && this.props.features.length && this.getHighlightLayer(projection, this.props.layers.length) || []); - }, renderSupportTools() { return this.props.tools.map((tool) => { - const Tool = plugins.tools[tool]; - const options = (this.props.toolsOptions[tool] && this.props.toolsOptions[tool][this.props.mapType]) || this.props.toolsOptions[tool] || {}; - return ; + const Tool = this.getTool(tool); + const options = (this.props.toolsOptions[Tool.name] && this.props.toolsOptions[Tool.name][this.props.mapType]) || this.props.toolsOptions[Tool.name] || {}; + return ; }); }, render() {