Skip to content

Commit

Permalink
Implemented dynamic tools for the Map plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarto committed Jan 13, 2017
1 parent 4702c33 commit b4489a9
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions web/client/plugins/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -76,6 +76,25 @@ const MapPlugin = React.createClass({
})}
</plugins.Layer>);
},
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 (
<plugins.Layer type={layer.type} srs={projection} position={index} key={layer.id || layer.name} options={layer}>
{this.renderLayerContent(layer)}
</plugins.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) => {
Expand All @@ -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 (
<plugins.Layer type={layer.type} srs={projection} position={index} key={layer.id || layer.name} options={layer}>
{this.renderLayerContent(layer)}
</plugins.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 <Tool key={tool} {...options}/>;
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 <Tool.impl key={Tool.name} {...options}/>;
});
},
render() {
Expand Down

0 comments on commit b4489a9

Please sign in to comment.