Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented dynamic tools for the Map plugin #1384

Merged
merged 1 commit into from
Jan 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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