Skip to content

Commit

Permalink
Added optional custom zoomToFeature action (#1234)
Browse files Browse the repository at this point in the history
* Added optional custom zoomToFeature action

* Added test and fix on Mauro's review
  • Loading branch information
kappu72 authored and mbarto committed Nov 2, 2016
1 parent f60755c commit 47ed231
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
10 changes: 8 additions & 2 deletions web/client/components/data/featuregrid/FeatureGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const FeatureGrid = React.createClass({
toolbar: React.PropTypes.object,
dataSource: React.PropTypes.object,
selectAll: React.PropTypes.func,
selectAllActive: React.PropTypes.bool
selectAllActive: React.PropTypes.bool,
zoomToFeatureAction: React.PropTypes.func
},
contextTypes: {
messages: React.PropTypes.object
Expand Down Expand Up @@ -245,7 +246,12 @@ const FeatureGrid = React.createClass({
zoomToFeature(params) {
let geometry = params.data.geometry;
if (geometry.coordinates) {
this.changeMapView([geometry], this.props.zoom);

if (this.props.zoomToFeatureAction) {
this.props.zoomToFeatureAction(params.data);
} else {
this.changeMapView([geometry], this.props.zoom);
}
}
},
zoomToFeatures() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,27 @@ describe("Test FeatureGrid Component", () => {
params = {selectedRows: []};
comp.selectFeatures(params);
expect(comp).toExist();
});
it('Test FeatureGrid custom zoomToFeatures', () => {
let map = {
size: {width: 1360, height: 685},
center: {x: -98, y: 26, crs: "EPSG:4326"},
projection: "EPSG:900913"
};
const testZoomTo = {
action: () => {
return true;
}
};
const spy = expect.spyOn(testZoomTo, 'action');

let comp = ReactDOM.render(
<FeatureGrid features={data.features} paging={true} map={map} zoomToFeatureAction={testZoomTo.action}/>, document.getElementById("container"));
expect(comp).toExist();
let params = {data: {geometry: {coordinates: []}}};
comp.zoomToFeature(params);
expect(spy).toHaveBeenCalled();
expect(spy).toHaveBeenCalledWith(params.data);
});
});

0 comments on commit 47ed231

Please sign in to comment.