Skip to content

Commit

Permalink
Fix geosolutions-it#1312. Calculate bbox for shape files.
Browse files Browse the repository at this point in the history
 - Fixed error when bbox[0] is not defined
 - Added alternative calculation of bbox for points
  • Loading branch information
offtherailz committed Nov 30, 2016
1 parent 9cdec35 commit 5a726e7
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions web/client/components/shapefile/ShapefileUploadAndStyle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,21 @@ const ShapeFileUploadAndStyle = React.createClass({

// calculates the bbox that contains all shapefiles added
const bbox = this.props.layers[0].features.reduce((bboxtotal, feature) => {
return (feature.geometry.bbox[0] && feature.geometry.bbox[1] && feature.geometry.bbox[2] && feature.geometry.bbox[3] ) && [
Math.min(bboxtotal[0], feature.geometry.bbox[0]),
Math.min(bboxtotal[1], feature.geometry.bbox[1]),
Math.max(bboxtotal[2], feature.geometry.bbox[2]),
Math.max(bboxtotal[3], feature.geometry.bbox[3])
] || bboxtotal;
if (feature.geometry.bbox && feature.geometry.bbox[0] && feature.geometry.bbox[1] && feature.geometry.bbox[2] && feature.geometry.bbox[3] ) {
return [
Math.min(bboxtotal[0], feature.geometry.bbox[0]),
Math.min(bboxtotal[1], feature.geometry.bbox[1]),
Math.max(bboxtotal[2], feature.geometry.bbox[2]),
Math.max(bboxtotal[3], feature.geometry.bbox[3])
] || bboxtotal;
} else if (feature.geometry && feature.geometry.type === "Point" && feature.geometry.coordinates && feature.geometry.coordinates.length >= 2) {
return [Math.min(bboxtotal[0], feature.geometry.coordinates[0]),
Math.min(bboxtotal[1], feature.geometry.coordinates[1]),
Math.max(bboxtotal[2], feature.geometry.coordinates[0]),
Math.max(bboxtotal[3], feature.geometry.coordinates[1])
];
}
return bboxtotal;
}, this.props.bbox);
if (this.state.zoomOnShapefiles) {
this.props.updateShapeBBox(bbox);
Expand Down

0 comments on commit 5a726e7

Please sign in to comment.