Skip to content

Commit 0c1e938

Browse files
committed
refactor: fix geojson type issue
1 parent a5167ef commit 0c1e938

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

libs/ngx-mapbox-gl/src/lib/marker/marker.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from '@angular/core';
1717
import type { LngLatLike, Marker, MarkerOptions } from 'mapbox-gl';
1818
import { MapService } from '../map/map.service';
19+
import type { Feature, Point } from 'geojson';
1920

2021
@Component({
2122
selector: 'mgl-marker',
@@ -39,7 +40,7 @@ export class MarkerComponent
3940
clickTolerance = input<MarkerOptions['clickTolerance']>();
4041

4142
/* Dynamic input */
42-
feature = input<GeoJSON.Feature<GeoJSON.Point>>();
43+
feature = input<Feature<Point>>();
4344
lngLat = input<LngLatLike>();
4445
draggable = input<MarkerOptions['draggable']>();
4546
popupShown = input<boolean>();

libs/ngx-mapbox-gl/src/lib/popup/popup.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import { LngLatLike, PointLike, Popup, PopupOptions } from 'mapbox-gl';
1717
import { MapService } from '../map/map.service';
1818
import { MarkerComponent } from '../marker/marker.component';
19+
import { Feature, Point } from 'geojson';
1920

2021
@Component({
2122
selector: 'mgl-popup',
@@ -37,7 +38,7 @@ export class PopupComponent
3738
maxWidth = input<PopupOptions['maxWidth']>();
3839

3940
/* Dynamic input */
40-
feature = input<GeoJSON.Feature<GeoJSON.Point>>();
41+
feature = input<Feature<Point>>();
4142
lngLat = input<LngLatLike>();
4243
marker = input<MarkerComponent>();
4344
offset = input<

libs/ngx-mapbox-gl/src/lib/source/geojson/feature.component.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
model,
1010
} from '@angular/core';
1111
import { GeoJSONSourceComponent } from './geojson-source.component';
12+
import { Feature, GeometryObject, GeoJsonProperties, Point } from 'geojson';
1213

1314
@Component({
1415
selector: 'mgl-feature',
@@ -22,11 +23,11 @@ export class FeatureComponent implements OnInit, OnDestroy {
2223

2324
/* Init inputs */
2425
id = model<number>(); // FIXME number only for now https://github.com/mapbox/mapbox-gl-js/issues/2716
25-
geometry = input.required<GeoJSON.GeometryObject>();
26-
properties = input<GeoJSON.GeoJsonProperties>();
26+
geometry = input.required<GeometryObject>();
27+
properties = input<GeoJsonProperties>();
2728
type = 'Feature' as const;
2829

29-
private feature: GeoJSON.Feature<GeoJSON.GeometryObject>;
30+
private feature: Feature<GeometryObject>;
3031

3132
ngOnInit() {
3233
if (!this.id()) {
@@ -46,7 +47,7 @@ export class FeatureComponent implements OnInit, OnDestroy {
4647
}
4748

4849
updateCoordinates(coordinates: number[]) {
49-
(this.feature.geometry as GeoJSON.Point).coordinates = coordinates;
50+
(this.feature.geometry as Point).coordinates = coordinates;
5051
this.GeoJSONSourceComponent.updateFeatureData.next(null);
5152
}
5253
}

libs/ngx-mapbox-gl/src/lib/source/geojson/geojson-source.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type { GeoJSONSource, GeoJSONSourceSpecification } from 'mapbox-gl';
1515
import { fromEvent, Subject, Subscription } from 'rxjs';
1616
import { debounceTime, filter } from 'rxjs/operators';
1717
import { MapService } from '../../map/map.service';
18+
import type { Feature, GeometryObject, GeoJSON } from 'geojson';
1819

1920
type GeoJSONSourceInputs = {
2021
[K in keyof Omit<GeoJSONSourceSpecification, 'type'>]: InputSignal<
@@ -36,7 +37,7 @@ export class GeoJSONSourceComponent
3637
id = input.required<string>();
3738

3839
/* Dynamic inputs */
39-
data = model<GeoJSONSourceSpecification['data']>();
40+
data = model<GeoJSON | string>();
4041
minzoom = input<GeoJSONSourceSpecification['minzoom']>();
4142
maxzoom = input<GeoJSONSourceSpecification['maxzoom']>();
4243
attribution = input<GeoJSONSourceSpecification['attribution']>();
@@ -152,7 +153,7 @@ export class GeoJSONSourceComponent
152153
const source = this.mapService.getSource<GeoJSONSource>(this.id())!;
153154
return this.zone.run(
154155
async () =>
155-
new Promise<GeoJSON.Feature<GeoJSON.Geometry>[] | null | undefined>(
156+
new Promise<Feature<GeometryObject>[] | null | undefined>(
156157
(resolve, reject) => {
157158
source.getClusterChildren(clusterId, (error, features) => {
158159
if (error) {
@@ -177,7 +178,7 @@ export class GeoJSONSourceComponent
177178
const source = this.mapService.getSource<GeoJSONSource>(this.id())!;
178179
return this.zone.run(
179180
async () =>
180-
new Promise<GeoJSON.Feature<GeoJSON.Geometry>[]>((resolve, reject) => {
181+
new Promise<Feature<GeometryObject>[]>((resolve, reject) => {
181182
source.getClusterLeaves(
182183
clusterId,
183184
limit,

0 commit comments

Comments
 (0)