@@ -3,30 +3,38 @@ import type { Map } from "ol";
33import type Feature from "ol/Feature" ;
44
55import Style from "ol/style/Style" ;
6- import Fill from 'ol/style/Fill.js' ;
7- import Stroke from 'ol/style/Stroke.js' ;
6+ import Fill from 'ol/style/Fill' ;
7+ import Stroke from 'ol/style/Stroke' ;
8+ import Circle from "ol/style/Circle" ;
89import VectorLayer from "ol/layer/Vector" ;
10+ import WebGLVectorLayer from "ol/layer/WebGLVector" ;
11+ import VectorSource from "ol/source/Vector" ;
912
1013// Box selection
11- import { 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' ;
14+ import { platformModifierKeyOnly } from 'ol/events/condition' ;
15+ // import { getWidth } from 'ol/extent.js';
16+ import DragBox from 'ol/interaction/DragBox' ;
17+ // import { getTransformFromProjections, transform } from 'ol/proj';
1518
1619import { featureToGeoJSON } from "./utils" ;
17- import VectorSource from "ol/source/Vector" ;
20+
21+ const fill = new Fill ( {
22+ color : 'rgba(58, 154, 178,0.7)'
23+ } ) ;
24+ const stroke = new Stroke ( {
25+ color : "rgba(220, 203, 78, 0.7)" ,
26+ width : 2
27+ } ) ;
1828
1929// TODO: Should be a parameter
2030const highlightStyle = new Style ( {
21- fill : new Fill ( {
22- color : 'rgba(58, 154, 178,0.7)'
31+ image : new Circle ( {
32+ fill : fill ,
33+ stroke : stroke ,
34+ radius : 5 ,
2335 } ) ,
24- stroke : new Stroke ( {
25- // color: 'rgba(241, 27, 0, 0.7)',
26- color : "rgba(220, 203, 78, 0.7)" ,
27- // color: "rgba(111, 178, 193, 0.7)",
28- width : 2
29- } )
36+ fill : fill ,
37+ stroke : stroke
3038} ) ;
3139
3240// TODO: Setting new style only works for 'VectorLayer'
@@ -79,22 +87,34 @@ function addBoxSelectionToMap(map: Map, model?: AnyModel): void {
7987 console . log ( "box extent" , extent ) ;
8088 //
8189 for ( let layer of map . getLayers ( ) . getArray ( ) ) {
82- if ( layer instanceof VectorLayer ) {
90+ if ( layer instanceof VectorLayer || layer instanceof WebGLVectorLayer ) {
8391 const source : VectorSource = layer . getSource ( ) ;
8492 console . log ( "source extend" , source . getExtent ( ) ) ;
8593 // const features = source.getFeaturesInExtent(extent).filter((feature: Feature) => feature?.getGeometry()?.intersectsExtent(extent));
8694 source . forEachFeatureIntersectingExtent ( extent , ( feature : Feature ) => {
8795 feature . set ( "layer" , layer . get ( "id" ) ) ;
88- selected . push ( featureToGeoJSON ( feature ) ) ;
96+ selected . push ( feature ) ;
97+ if ( layer instanceof VectorLayer ) {
98+ feature . setStyle ( highlightStyle ) ;
99+ }
89100 } ) ;
90- console . log ( "selected features" , selected ) ;
101+ const output = selected . map ( f => featureToGeoJSON ( f ) ) ;
102+ console . log ( "selected features" , output ) ;
103+ if ( model ) {
104+ model . set ( "features" , { selected : output } ) ;
105+ model . save_changes ( ) ;
106+ }
91107 }
92108 }
93109 } ) ;
94110
95111
96112 dragBox . on ( 'boxstart' , function ( ) {
97- // select.clearSelection();
113+ selected . forEach ( ( f : Feature ) => { f . setStyle ( ) ; } ) ;
114+ if ( model ) {
115+ model . set ( "features" , { } ) ;
116+ model . save_changes ( ) ;
117+ }
98118 selected = [ ] ;
99119 } ) ;
100120}
0 commit comments