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

Fix #1310. Improved vector gfi with buffer #1311

Merged
merged 4 commits into from
Dec 6, 2016
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions web/client/components/data/identify/Identify.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const Identify = React.createClass({
format: React.PropTypes.string,
map: React.PropTypes.object,
layers: React.PropTypes.array,
buffer: React.PropTypes.number,
requests: React.PropTypes.array,
responses: React.PropTypes.array,
viewerOptions: React.PropTypes.object,
Expand Down Expand Up @@ -66,6 +67,7 @@ const Identify = React.createClass({
format: MapInfoUtils.getDefaultInfoFormatValue(),
requests: [],
responses: [],
buffer: 2,
viewerOptions: {},
viewer: DefaultViewer,
purgeResults: () => {},
Expand Down
2 changes: 1 addition & 1 deletion web/client/components/data/identify/viewers/JSONViewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var JSONViewer = React.createClass({
},
render() {
const RowViewer = this.props.rowViewer || PropertiesViewer;
return (<div>
return (<div style={{maxHeight: "250px"}}>
{(this.props.response.features || []).map((feature, i) => {
return <RowViewer key={i} title={feature.id} exclude={["bbox"]} {...feature.properties}/>;
})}
Expand Down
30 changes: 28 additions & 2 deletions web/client/reducers/mapInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const {RESET_CONTROLS} = require('../actions/controls');

const assign = require('object-assign');
const {head} = require('lodash');
const {inside} = require('turf');
const {intersect, buffer} = require('turf');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use:

turf/node_modules/turf-intersect

and

turf/node_modules/turf-buffer

to avoid including the complete turf bundle

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no node-modules in my node_modules/turf dir.

Probably because I'm using most recent npm:

There are only package.json and index.js. The index.js has this content:
npm: '3.5.2',

/*eslint global-require: 0*/

/**
 * Turf is a modular geospatial analysis engine written in JavaScript. It performs geospatial
 * processing tasks with GeoJSON data and can be run on a server or in a browser.
 *
 * @module turf
 * @summary Geospatial analysis for JavaScript
 */
module.exports = {
    isolines: require('turf-isolines'),
    [...]
    buffer: require('turf-buffer'),
    [...]
    intersect: require('turf-intersect'),
    [...]
    };

var helpers = require('turf-helpers');
[...]
module.exports.point = helpers.point;
module.exports.polygon = helpers.polygon;
module.exports.lineString = helpers.lineString;
[...]

They are only in your node modules, with an oldest node_modules.

So I think the good approch is the mine one, that is compatible with both versions, and optimized for the newer, that will be used in the future.

What do you think?


function receiveResponse(state, action, type) {
const request = head((state.requests || []).filter((req) => req.reqId === action.reqId));
Expand Down Expand Up @@ -119,7 +119,33 @@ function mapInfo(state = {}, action) {
"coordinates": [action.request.lng, action.request.lat]
}
};
const intersected = action.layer.features.filter((feature) => inside(point, feature));
let unit = action.metadata && action.metadata.units;
switch (unit) {
case "m":
unit = "meters";
break;
case "deg":
unit = "degrees";
break;
case "mi":
unit = "miles";
break;
default:
unit = "meters";
}
let resolution = action.metadata && action.metadata.resolution || 1;
let bufferedPoint = buffer(point, (action.metadata.buffer || 1) * resolution, unit);
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.
return intersect(bufferedPoint, (resolution && action.metadata.buffer && unit) ? buffer(feature, 1, "meters") : feature);
}catch(e) {
return false;
}
}

);
const responses = state.responses || [];
return assign({}, state, {
requests: [...state.requests, {}],
Expand Down
5 changes: 4 additions & 1 deletion web/client/utils/MapInfoUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ const MapInfoUtils = {
},
metadata: {
fields: Object.keys(layer.features[0].properties),
title: layer.name
title: layer.name,
resolution: props.map && props.map && props.map.zoom && MapUtils.getCurrentResolution(props.map.zoom, 0, 21, 96),
buffer: props.buffer,
units: props.map && props.map.units
},
url: ""
};
Expand Down