From 008969b8aa6ba53abbc93458e0b6504b7a383831 Mon Sep 17 00:00:00 2001 From: mbarto Date: Mon, 24 Jul 2017 12:45:32 +0200 Subject: [PATCH] Fixes and improvements to identify on vector layers (#2051) * Fixes and improvements to identify on vector layers * Fixed lint issues --- .../data/identify/viewers/row/PropertiesViewer.jsx | 9 ++++++++- web/client/components/map/leaflet/Feature.jsx | 5 ++++- web/client/reducers/mapInfo.js | 2 +- web/client/utils/mapinfo/vector.js | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/web/client/components/data/identify/viewers/row/PropertiesViewer.jsx b/web/client/components/data/identify/viewers/row/PropertiesViewer.jsx index 185b5a45ec..7202a09e53 100644 --- a/web/client/components/data/identify/viewers/row/PropertiesViewer.jsx +++ b/web/client/components/data/identify/viewers/row/PropertiesViewer.jsx @@ -8,6 +8,7 @@ const PropTypes = require('prop-types'); */ const React = require('react'); +const {isString} = require('lodash'); const alwaysExcluded = ["exclude", "titleStyle", "listStyle", "componentStyle", "title"]; @@ -47,7 +48,7 @@ class PropertiesViewer extends React.Component { .filter(this.toExlude) .map((key) => { return ( -

{key} {this.props[key]}

+

{key} {this.renderProperty(this.props[key])}

); }); }; @@ -80,6 +81,12 @@ class PropertiesViewer extends React.Component { ); }; + renderProperty = (prop) => { + if (isString(prop)) { + return prop; + } + return JSON.stringify(prop); + }; render() { return (
diff --git a/web/client/components/map/leaflet/Feature.jsx b/web/client/components/map/leaflet/Feature.jsx index e8ee29bb73..a06c9fc2b5 100644 --- a/web/client/components/map/leaflet/Feature.jsx +++ b/web/client/components/map/leaflet/Feature.jsx @@ -175,7 +175,10 @@ class Feature extends React.Component { this._layer.on('click', (event) => { if (this.props.onClick) { this.props.onClick({ - pixel: event.containerPoint, + pixel: { + x: event.originalEvent && event.originalEvent.x, + y: event.originalEvent && event.originalEvent.y + }, latlng: event.latlng }); } diff --git a/web/client/reducers/mapInfo.js b/web/client/reducers/mapInfo.js index 6aa66131b6..71ad16906a 100644 --- a/web/client/reducers/mapInfo.js +++ b/web/client/reducers/mapInfo.js @@ -146,7 +146,7 @@ function mapInfo(state = {}, action) { } let resolution = action.metadata && action.metadata.resolution || 1; let bufferedPoint = buffer(point, (action.metadata.buffer || 1) * resolution, unit); - const intersected = action.layer.features.filter( + const intersected = (action.layer.features || []).filter( (feature) => { try { // TODO: instead of create a fixed buffer, we should check the feature style to create the proper buffer. diff --git a/web/client/utils/mapinfo/vector.js b/web/client/utils/mapinfo/vector.js index 78b28357a7..6597289f0e 100644 --- a/web/client/utils/mapinfo/vector.js +++ b/web/client/utils/mapinfo/vector.js @@ -16,7 +16,7 @@ module.exports = { lng: props.point.latlng.lng }, metadata: { - fields: Object.keys(layer.features[0].properties), + fields: layer.features && layer.features.length && Object.keys(layer.features[0].properties) || [], title: layer.name, resolution: props.map && props.map && props.map.zoom && MapUtils.getCurrentResolution(props.map.zoom, 0, 21, 96), buffer: props.buffer,