Skip to content

Commit

Permalink
Multi identify (#1338)
Browse files Browse the repository at this point in the history
* Store modifier state in map click

* Add option to enable multiple identify selections via ctrl-key
  • Loading branch information
manisandro authored and mbarto committed Dec 12, 2016
1 parent a83de16 commit 2f0b144
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
10 changes: 7 additions & 3 deletions web/client/components/data/identify/Identify.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ const Identify = React.createClass({
bodyClassName: React.PropTypes.string,
asPanel: React.PropTypes.bool,
headerGlyph: React.PropTypes.string,
closeGlyph: React.PropTypes.string
closeGlyph: React.PropTypes.string,
allowMultiselection: React.PropTypes.bool
},
getDefaultProps() {
return {
Expand Down Expand Up @@ -103,12 +104,15 @@ const Identify = React.createClass({
bodyClassName: "panel-body",
asPanel: true,
headerGlyph: "info-sign",
closeGlyph: ""
closeGlyph: "",
allowMultiselection: false
};
},
componentWillReceiveProps(newProps) {
if (this.needsRefresh(newProps)) {
this.props.purgeResults();
if (!newProps.point.modifiers || newProps.point.modifiers.ctrl !== true || !newProps.allowMultiselection) {
this.props.purgeResults();
}
const queryableLayers = newProps.layers.filter(newProps.queryableLayersFilter);
queryableLayers.forEach((layer) => {
const {url, request, metadata} = this.props.buildRequest(layer, newProps);
Expand Down
21 changes: 21 additions & 0 deletions web/client/components/data/identify/__tests__/Identify-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,27 @@ describe('Identify', () => {
expect(spyPurgeResults.calls.length).toEqual(2);
});

it('creates the Identify component does not purge if multiselection enabled', () => {
const testHandlers = {
purgeResults: () => {}
};

const spyPurgeResults = expect.spyOn(testHandlers, 'purgeResults');

const identify = ReactDOM.render(
<Identify
queryableLayersFilter={() => true}
enabled={true} layers={[{}, {}]} {...testHandlers} buildRequest={() => ({})}
multiSelection={true}
/>,
document.getElementById("container")
);
identify.setProps({point: {pixel: {x: 1, y: 1}, modifiers: {ctrl: false}}});
expect(spyPurgeResults.calls.length).toEqual(1);
identify.setProps({point: {pixel: {x: 1, y: 1}, modifiers: {ctrl: true}}});
expect(spyPurgeResults.calls.length).toEqual(1);
});

it('creates the Identify component uses custom viewer', () => {
const Viewer = (props) => <span className="myviewer">{props.responses.length}</span>;
const identify = ReactDOM.render(
Expand Down
5 changes: 5 additions & 0 deletions web/client/components/map/leaflet/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ let LeafletMap = React.createClass({
latlng: {
lat: event.latlng.lat,
lng: event.latlng.lng
},
modifiers: {
alt: event.originalEvent.altKey,
ctrl: event.originalEvent.ctrlKey,
shift: event.originalEvent.shiftKey
}
});
}
Expand Down
6 changes: 4 additions & 2 deletions web/client/components/map/leaflet/__tests__/Map-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ describe('LeafletMap', () => {
expect(spy.calls[0].arguments.length).toEqual(1);
expect(spy.calls[0].arguments[0].pixel).toExist();
expect(spy.calls[0].arguments[0].latlng).toExist();
expect(spy.calls[0].arguments[0].modifiers).toExist();
expect(spy.calls[0].arguments[0].modifiers.alt).toEqual(false);
expect(spy.calls[0].arguments[0].modifiers.ctrl).toEqual(false);
expect(spy.calls[0].arguments[0].modifiers.shift).toEqual(false);
done();
}, 600);


});

it('check if the map changes when receive new props', () => {
Expand Down
5 changes: 5 additions & 0 deletions web/client/components/map/openlayers/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ var OpenlayersMap = React.createClass({
latlng: {
lat: coords[1],
lng: tLng
},
modifiers: {
alt: event.originalEvent.altKey,
ctrl: event.originalEvent.ctrlKey,
shift: event.originalEvent.shiftKey
}
});
}
Expand Down

0 comments on commit 2f0b144

Please sign in to comment.