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 #1612. Extent calculation for GeoJson supported #1615

Merged
merged 3 commits into from
Mar 21, 2017
Merged
Changes from 1 commit
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
Next Next commit
Fix #1612. Extent calculation for GeoJson supported
  • Loading branch information
offtherailz committed Mar 20, 2017
commit af06a99897391183cf8eace71794a0d09eb50c8e
44 changes: 32 additions & 12 deletions web/client/utils/CoordinatesUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,13 @@ const CoordinatesUtils = {
if (geoJSON.coordinates) {
if (geoJSON.type !== "Point" && geoJSON.type !== "GeometryCollection") {
const flatCoordinates = chunk(flattenDeep(geoJSON.coordinates), 2);
flatCoordinates.reduce((extent, point) => {
extent[0] = (point[0] < newExtent[0]) ? point[0] : newExtent[0];
extent[1] = (point[1] < newExtent[1]) ? point[1] : newExtent[1];
extent[2] = (point[0] > newExtent[2]) ? point[0] : newExtent[2];
extent[3] = (point[1] > newExtent[3]) ? point[1] : newExtent[3];
return extent;
return flatCoordinates.reduce((extent, point) => {
return [
(point[0] < extent[0]) ? point[0] : extent[0],
(point[1] < extent[1]) ? point[1] : extent[1],
(point[0] > extent[2]) ? point[0] : extent[2],
(point[1] > extent[3]) ? point[1] : extent[3]
];
}, newExtent);
}else if (geoJSON.type === "Point") {
let point = geoJSON.coordinates;
Expand All @@ -254,15 +255,34 @@ const CoordinatesUtils = {
newExtent[2] = point[0] + point[0] * 0.01;
newExtent[3] = point[1] + point[1] * 0.01;
}else if (geoJSON.type === "GeometryCollection") {
geoJSON.geometies.reduce((extent, geometry) => {
return geoJSON.geometies.reduce((extent, geometry) => {
let ext = this.getGeoJSONExtent(geometry);
if (this.isValidExtent(ext)) {
extent[0] = (ext[0] < newExtent[0]) ? ext[0] : newExtent[0];
extent[1] = (ext[1] < newExtent[1]) ? ext[1] : newExtent[1];
extent[2] = (ext[2] > newExtent[2]) ? ext[2] : newExtent[2];
extent[3] = (ext[3] > newExtent[3]) ? ext[3] : newExtent[3];
return [
(ext[0] < extent[0]) ? ext[0] : extent[0],
Copy link
Contributor

Choose a reason for hiding this comment

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

can we create a function with this stuff, that is repeated many times?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, as you see the original one had many side effects. I didn't noticed they become exactly the same function after my refactor.

(ext[1] < extent[1]) ? ext[1] : extent[1],
(ext[2] > extent[2]) ? ext[2] : extent[2],
(ext[3] > extent[3]) ? ext[3] : extent[3]
];
}
}, newExtent);
}
} else if (geoJSON.type) {
if (geoJSON.type === "FeatureCollection") {
return geoJSON.features.reduce((extent, feature) => {
const ext = this.getGeoJSONExtent(feature);
if (this.isValidExtent(ext)) {
return [
(ext[0] < extent[0]) ? ext[0] : extent[0],
(ext[1] < extent[1]) ? ext[1] : extent[1],
(ext[2] > extent[2]) ? ext[2] : extent[2],
(ext[3] > extent[3]) ? ext[3] : extent[3]
];
}
return extent;
}, newExtent);
} else if (geoJSON.type === "Feature" && geoJSON.geometry) {
return this.getGeoJSONExtent(geoJSON.geometry);
}
}

Expand All @@ -278,7 +298,7 @@ const CoordinatesUtils = {
isValidExtent: function(extent) {
return !(
extent.indexOf(Infinity) !== -1 || extent.indexOf(-Infinity) !== -1 ||
extent[1] >= extent[2] || extent[1] >= extent[3]
extent[0] > extent[2] || extent[1] > extent[3]
);
},
calculateCircleCoordinates: function(center, radius, sides, rotation) {
Expand Down