@@ -9,9 +9,12 @@ import VectorLayer from "ol/layer/Vector";
99
1010// Box selection
1111import { platformModifierKeyOnly } from 'ol/events/condition.js' ;
12+ import { getWidth } from 'ol/extent.js' ;
13+ import DragBox from 'ol/interaction/DragBox.js' ;
14+ import { getTransformFromProjections , transform } from 'ol/proj' ;
1215
1316import { featureToGeoJSON } from "./utils" ;
14- import DragBox from ' ol/interaction/DragBox.js' ;
17+ import VectorSource from " ol/source/Vector" ;
1518
1619// TODO: Should be a parameter
1720const highlightStyle = new Style ( {
@@ -63,19 +66,36 @@ function addSelectFeaturesToMap(map: Map, model?: AnyModel): void {
6366}
6467
6568function addBoxSelectionToMap ( map : Map , model ?: AnyModel ) : void {
66- console . warn ( "Box selection not implemented yet" ) ;
69+ console . warn ( "Box selection is still experimental." ) ;
70+
71+ let selected = [ ] as Feature [ ] ;
6772
6873 const dragBox = new DragBox ( {
6974 condition : platformModifierKeyOnly ,
7075 } ) ;
7176 map . addInteraction ( dragBox ) ;
7277 dragBox . on ( 'boxend' , function ( ) {
73- const extent = dragBox . getGeometry ( ) . getExtent ( ) ;
78+ const extent = dragBox . getGeometry ( ) . transform ( 'EPSG:3857' , 'EPSG:4326' ) . getExtent ( ) ;
7479 console . log ( "box extent" , extent ) ;
80+ //
81+ for ( let layer of map . getLayers ( ) . getArray ( ) ) {
82+ if ( layer instanceof VectorLayer ) {
83+ const source : VectorSource = layer . getSource ( ) ;
84+ console . log ( "source extend" , source . getExtent ( ) ) ;
85+ // const features = source.getFeaturesInExtent(extent).filter((feature: Feature) => feature?.getGeometry()?.intersectsExtent(extent));
86+ source . forEachFeatureIntersectingExtent ( extent , ( feature : Feature ) => {
87+ feature . set ( "layer" , layer . get ( "id" ) ) ;
88+ selected . push ( featureToGeoJSON ( feature ) ) ;
89+ } ) ;
90+ console . log ( "selected features" , selected ) ;
91+ }
92+ }
7593 } ) ;
7694
95+
7796 dragBox . on ( 'boxstart' , function ( ) {
7897 // select.clearSelection();
98+ selected = [ ] ;
7999 } ) ;
80100}
81101
0 commit comments