Skip to content

Commit dcc9a67

Browse files
authored
Merge pull request #100 from gtt-project/feature/upgrade-types-ol-ext
Upgrading types-ol-ext
2 parents 0a55fac + d8d4088 commit dcc9a67

File tree

3 files changed

+200
-56
lines changed

3 files changed

+200
-56
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
"dependencies": {
2323
"font-awesome": "^4.7.0",
2424
"ol": "^6.5.0",
25-
"ol-ext": "^3.1.19"
25+
"ol-ext": "^3.2.3"
2626
},
2727
"devDependencies": {
28-
"@types/ol": "^6.4.2",
29-
"@types/ol-ext": "npm:@siedlerchr/types-ol-ext",
28+
"@types/ol": "^6.5.3",
29+
"@types/ol-ext": "npm:@gtt-project/types-ol-ext",
3030
"css-loader": "^5.1.1",
3131
"sass": "^1.32.8",
3232
"sass-loader": "^11.0.1",

src/components/gtt-client.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
Select,
1717
} from 'ol/interaction'
1818
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'
2020
import { transform, fromLonLat, transformExtent } from 'ol/proj'
2121
import { createEmpty, extend, getCenter, containsCoordinate } from 'ol/extent'
2222
import { FeatureCollection } from 'geojson'
@@ -32,6 +32,8 @@ import Button from 'ol-ext/control/Button'
3232
import TextButton from 'ol-ext/control/TextButton'
3333
import LayerPopup from 'ol-ext/control/LayerPopup'
3434
import Popup from 'ol-ext/overlay/Popup'
35+
import { position } from 'ol-ext/control/control'
36+
import GeometryType from 'ol/geom/GeometryType';
3537

3638
interface GttClientOption {
3739
target: HTMLDivElement | null
@@ -239,7 +241,7 @@ export class GttClient {
239241

240242
// Add Toolbar
241243
this.toolbar = new Bar()
242-
this.toolbar.setPosition('bottom-left' as any) // is type.d old?
244+
this.toolbar.setPosition('bottom-left' as position)
243245
this.map.addControl(this.toolbar)
244246
this.setView()
245247
this.setGeolocation(this.map)
@@ -253,7 +255,7 @@ export class GttClient {
253255
handleClick: () => {
254256
this.zoomToExtent(true);
255257
}
256-
} as any)
258+
})
257259
this.toolbar.addControl(maximizeCtrl)
258260

259261
if (this.contents.edit) {
@@ -348,18 +350,18 @@ export class GttClient {
348350
this.map.addInteraction(modify)
349351

350352
const mainbar = new Bar()
351-
mainbar.setPosition("top-left" as any)
353+
mainbar.setPosition("top-left" as position)
352354
this.map.addControl(mainbar)
353355

354356
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+
})
358360
mainbar.addControl(editbar)
359361

360-
types.forEach(type => {
362+
types.forEach((type, idx) => {
361363
const draw = new Draw({
362-
type: type as any,
364+
type: type as GeometryType,
363365
source: this.vector.getSource()
364366
})
365367

@@ -371,8 +373,9 @@ export class GttClient {
371373
const control = new Toggle({
372374
html: `<i class="gtt-icon-${type.toLowerCase()}" ></i>`,
373375
title: type,
374-
interaction: draw
375-
} as any)
376+
interaction: draw,
377+
active: (idx === 0)
378+
})
376379
editbar.addControl(control)
377380
})
378381

@@ -394,23 +397,17 @@ export class GttClient {
394397
this.zoomToExtent()
395398
}
396399
}
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+
}))
403401
}
404402

405403
setPopover() {
406404
const popup = new Popup({
407405
popupClass: 'default',
408406
closeBox: true,
409407
onclose: () => {},
410-
positionning: 'auto',
411-
autoPan: true,
412-
autoPanAnimation: { duration: 250 }
413-
} as any)
408+
positioning: 'auto',
409+
anim: true
410+
})
414411
this.map.addOverlay(popup)
415412

416413
// Control Select
@@ -432,7 +429,7 @@ export class GttClient {
432429
const url = popup_contents.href.replace(/\[(.+?)\]/g, feature.get('id'))
433430
content.push(`<a href="${url}">Edit</a>`)
434431

435-
popup.show(feature.getGeometry().getFirstCoordinate(), content.join(' ') as any)
432+
popup.show(feature.getGeometry().getFirstCoordinate(), content.join(' '))
436433
})
437434

438435
select.getFeatures().on(['remove'], _ => {
@@ -478,8 +475,11 @@ export class GttClient {
478475
})
479476
if (addressInput) {
480477
// 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()
483483
coords = transform(coords, 'EPSG:3857', 'EPSG:4326')
484484
const reverse_geocode_url = geocoder.reverse_geocode_url.replace("{lon}", coords[0].toString()).replace("{lat}", coords[1].toString())
485485
fetch(reverse_geocode_url)
@@ -643,7 +643,7 @@ export class GttClient {
643643
width: 1
644644
}),
645645
opacity: 1,
646-
} as any),
646+
}),
647647
stroke: new Stroke({
648648
width: 4,
649649
color: self.getColor(feature)
@@ -867,7 +867,7 @@ export class GttClient {
867867
geolocation.setTracking(active)
868868
geolocationLayer.setVisible(active)
869869
}
870-
} as any)
870+
})
871871
this.toolbar.addControl(geolocationCtrl)
872872
}
873873

@@ -1066,10 +1066,10 @@ export class GttClient {
10661066
controls: [
10671067
new TextButton({
10681068
html: '<form><input name="address" type="text" /></form>'
1069-
} as any)
1069+
})
10701070
]
1071-
} as any)
1072-
} as any)
1071+
})
1072+
})
10731073
this.toolbar.addControl(geocodingCtrl)
10741074

10751075
// Make Geocoding API request
@@ -1130,8 +1130,8 @@ export class GttClient {
11301130
if (layer instanceof VectorLayer &&
11311131
layer.getKeys().indexOf("title") >= 0 &&
11321132
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) => {
11351135
return feature.getGeometry().getType() === "Point"
11361136
})
11371137
if (pointIndex >= 0) {

0 commit comments

Comments
 (0)