forked from geosolutions-it/MapStore2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Box Selection on Map (geosolutions-it#6078)
- Loading branch information
Showing
9 changed files
with
164 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2020, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
export const BOX_END = "BOX_END"; | ||
export const CHANGE_BOX_SELECTION_STATUS = "CHANGE_BOX_SELECTION_STATUS"; | ||
|
||
export function boxEnd(boxEndInfo) { | ||
return { | ||
type: BOX_END, | ||
boxEndInfo | ||
}; | ||
} | ||
|
||
export function changeBoxSelectionStatus(status) { | ||
return { | ||
type: CHANGE_BOX_SELECTION_STATUS, | ||
status | ||
}; | ||
} |
46 changes: 46 additions & 0 deletions
46
web/client/components/map/openlayers/BoxSelectionSupport.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2020, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {useEffect} from 'react'; | ||
import Select from 'ol/interaction/Select'; | ||
import DragBox from 'ol/interaction/DragBox'; | ||
|
||
let select; | ||
let dragBox; | ||
|
||
const BoxSelectionSupport = (props) => { | ||
const { map, onBoxEnd, status } = props; | ||
|
||
useEffect(() => { | ||
if (status === "start") { | ||
select = new Select(); | ||
dragBox = new DragBox({}); | ||
map.addInteraction(select); | ||
map.addInteraction(dragBox); | ||
} else if (status === "end") { | ||
map.removeInteraction(select); | ||
map.removeInteraction(dragBox); | ||
} | ||
}, [status]); | ||
|
||
useEffect(() => { | ||
if (dragBox) { | ||
|
||
// TODO: Pass some more information from event to the onBoxEnd function | ||
dragBox.on('boxend', () => { | ||
onBoxEnd({ | ||
boxExtent: dragBox.getGeometry().getExtent() | ||
}); | ||
}); | ||
} | ||
}, [status]); | ||
|
||
return null; | ||
}; | ||
|
||
export default BoxSelectionSupport; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2020, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
import assign from 'object-assign'; | ||
|
||
import { CHANGE_BOX_SELECTION_STATUS } from '../actions/box'; | ||
|
||
const initialState = { | ||
status: null | ||
}; | ||
|
||
function box(state = initialState, action) { | ||
switch (action.type) { | ||
case CHANGE_BOX_SELECTION_STATUS: | ||
return assign({}, state, {status: action.status}); | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
export default box; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright 2020, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
export const boxSelectionStatus = state => state && state.box && state.box.status; |