@@ -16,7 +16,7 @@ import {
16
16
Select ,
17
17
} from 'ol/interaction'
18
18
import { focus as events_condifition_focus } from 'ol/events/condition'
19
- import { defaults as control_defaults } from 'ol/control'
19
+ import { defaults as control_defaults } from 'ol/control'
20
20
import { transform , fromLonLat , transformExtent } from 'ol/proj'
21
21
import { createEmpty , extend , getCenter , containsCoordinate } from 'ol/extent'
22
22
import { FeatureCollection } from 'geojson'
@@ -32,6 +32,8 @@ import Button from 'ol-ext/control/Button'
32
32
import TextButton from 'ol-ext/control/TextButton'
33
33
import LayerPopup from 'ol-ext/control/LayerPopup'
34
34
import Popup from 'ol-ext/overlay/Popup'
35
+ import { position } from 'ol-ext/control/control'
36
+ import GeometryType from 'ol/geom/GeometryType' ;
35
37
36
38
interface GttClientOption {
37
39
target : HTMLDivElement | null
@@ -239,7 +241,7 @@ export class GttClient {
239
241
240
242
// Add Toolbar
241
243
this . toolbar = new Bar ( )
242
- this . toolbar . setPosition ( 'bottom-left' as any ) // is type.d old?
244
+ this . toolbar . setPosition ( 'bottom-left' as position )
243
245
this . map . addControl ( this . toolbar )
244
246
this . setView ( )
245
247
this . setGeolocation ( this . map )
@@ -253,7 +255,7 @@ export class GttClient {
253
255
handleClick : ( ) => {
254
256
this . zoomToExtent ( true ) ;
255
257
}
256
- } as any )
258
+ } )
257
259
this . toolbar . addControl ( maximizeCtrl )
258
260
259
261
if ( this . contents . edit ) {
@@ -348,18 +350,18 @@ export class GttClient {
348
350
this . map . addInteraction ( modify )
349
351
350
352
const mainbar = new Bar ( )
351
- mainbar . setPosition ( "top-left" as any )
353
+ mainbar . setPosition ( "top-left" as position )
352
354
this . map . addControl ( mainbar )
353
355
354
356
const editbar = new Bar ( {
355
- toggleOne : true , // one control active at the same time
356
- group : true // group controls together
357
- } as any )
357
+ toggleOne : true , // one control active at the same time
358
+ group : true // group controls together
359
+ } )
358
360
mainbar . addControl ( editbar )
359
361
360
- types . forEach ( type => {
362
+ types . forEach ( ( type , idx ) => {
361
363
const draw = new Draw ( {
362
- type : type as any ,
364
+ type : type as GeometryType ,
363
365
source : this . vector . getSource ( )
364
366
} )
365
367
@@ -371,8 +373,9 @@ export class GttClient {
371
373
const control = new Toggle ( {
372
374
html : `<i class="gtt-icon-${ type . toLowerCase ( ) } " ></i>` ,
373
375
title : type ,
374
- interaction : draw
375
- } as any )
376
+ interaction : draw ,
377
+ active : ( idx === 0 )
378
+ } )
376
379
editbar . addControl ( control )
377
380
} )
378
381
@@ -394,23 +397,17 @@ export class GttClient {
394
397
this . zoomToExtent ( )
395
398
}
396
399
}
397
- } as any ) )
398
-
399
- // Control has no setActive
400
- // const _controls = editbar.getControls() as unknown
401
- // const controls = _controls as Array<Control>
402
- // controls[0].setActive(true)
400
+ } ) )
403
401
}
404
402
405
403
setPopover ( ) {
406
404
const popup = new Popup ( {
407
405
popupClass : 'default' ,
408
406
closeBox : true ,
409
407
onclose : ( ) => { } ,
410
- positionning : 'auto' ,
411
- autoPan : true ,
412
- autoPanAnimation : { duration : 250 }
413
- } as any )
408
+ positioning : 'auto' ,
409
+ anim : true
410
+ } )
414
411
this . map . addOverlay ( popup )
415
412
416
413
// Control Select
@@ -432,7 +429,7 @@ export class GttClient {
432
429
const url = popup_contents . href . replace ( / \[ ( .+ ?) \] / g, feature . get ( 'id' ) )
433
430
content . push ( `<a href="${ url } ">Edit</a>` )
434
431
435
- popup . show ( feature . getGeometry ( ) . getFirstCoordinate ( ) , content . join ( ' ' ) as any )
432
+ popup . show ( feature . getGeometry ( ) . getFirstCoordinate ( ) , content . join ( ' ' ) )
436
433
} )
437
434
438
435
select . getFeatures ( ) . on ( [ 'remove' ] , _ => {
@@ -478,8 +475,11 @@ export class GttClient {
478
475
} )
479
476
if ( addressInput ) {
480
477
// Todo: only works with point geometries for now for the last geometry
481
- const feature = features [ features . length - 1 ] . getGeometry ( ) as any
482
- let coords = feature . getCoordinates ( )
478
+ const geom = features [ features . length - 1 ] . getGeometry ( ) as Point
479
+ if ( geom === null ) {
480
+ return
481
+ }
482
+ let coords = geom . getCoordinates ( )
483
483
coords = transform ( coords , 'EPSG:3857' , 'EPSG:4326' )
484
484
const reverse_geocode_url = geocoder . reverse_geocode_url . replace ( "{lon}" , coords [ 0 ] . toString ( ) ) . replace ( "{lat}" , coords [ 1 ] . toString ( ) )
485
485
fetch ( reverse_geocode_url )
@@ -643,7 +643,7 @@ export class GttClient {
643
643
width : 1
644
644
} ) ,
645
645
opacity : 1 ,
646
- } as any ) ,
646
+ } ) ,
647
647
stroke : new Stroke ( {
648
648
width : 4 ,
649
649
color : self . getColor ( feature )
@@ -867,7 +867,7 @@ export class GttClient {
867
867
geolocation . setTracking ( active )
868
868
geolocationLayer . setVisible ( active )
869
869
}
870
- } as any )
870
+ } )
871
871
this . toolbar . addControl ( geolocationCtrl )
872
872
}
873
873
@@ -1066,10 +1066,10 @@ export class GttClient {
1066
1066
controls : [
1067
1067
new TextButton ( {
1068
1068
html : '<form><input name="address" type="text" /></form>'
1069
- } as any )
1069
+ } )
1070
1070
]
1071
- } as any )
1072
- } as any )
1071
+ } )
1072
+ } )
1073
1073
this . toolbar . addControl ( geocodingCtrl )
1074
1074
1075
1075
// Make Geocoding API request
@@ -1130,8 +1130,8 @@ export class GttClient {
1130
1130
if ( layer instanceof VectorLayer &&
1131
1131
layer . getKeys ( ) . indexOf ( "title" ) >= 0 &&
1132
1132
layer . get ( "title" ) === "Features" ) {
1133
- const features = ( layer as any ) . getSource ( ) . getFeatures ( )
1134
- const pointIndex = features . findIndex ( ( feature : any ) => {
1133
+ const features = layer . getSource ( ) . getFeatures ( )
1134
+ const pointIndex = features . findIndex ( ( feature : Feature ) => {
1135
1135
return feature . getGeometry ( ) . getType ( ) === "Point"
1136
1136
} )
1137
1137
if ( pointIndex >= 0 ) {
0 commit comments