Skip to content

Commit

Permalink
Refine types for new features
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Jul 8, 2024
1 parent 17152c4 commit 1f5ff7d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ export let cfg = {

// Should assign any necessary properties. Runs inside a gjSchemeCollection
// update; the logic shouldn't look at anything in there.
newPointFeature: (f: Feature<Point>) => {},
newPolygonFeature: (f: Feature<Polygon>) => {},
newLineStringFeature: (f: Feature<LineString>) => {},
newPointFeature: (f: FeatureWithID<Point>) => {},
newPolygonFeature: (f: FeatureWithID<Polygon>) => {},
newLineStringFeature: (f: FeatureWithID<LineString>) => {},

updateFeature: (
destination: FeatureWithAnyProps,
Expand Down
5 changes: 3 additions & 2 deletions src/lib/draw/point/PointMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
$pointTool!.clearEventListeners();
});
function onSuccess(f: Feature<Point>) {
function onSuccess(feature: Feature<Point>) {
let f = feature as FeatureWithID<Point>;
gjSchemeCollection.update((gj) => {
f.id = newFeatureId(gj);
f.properties ||= {};
f.properties.scheme_reference = getArbitrarySchemeRef(gj);
cfg.newPointFeature(f);
gj.features.push(f as FeatureWithID);
gj.features.push(f);
return gj;
});
Expand Down
5 changes: 3 additions & 2 deletions src/lib/draw/polygon/PolygonMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
$polygonTool!.clearEventListeners();
});
function onSuccess(f: Feature<Polygon>) {
function onSuccess(feature: Feature<Polygon>) {
let f = feature as FeatureWithID<Polygon>;
gjSchemeCollection.update((gj) => {
f.id = newFeatureId(gj);
f.properties ||= {};
f.properties.scheme_reference = getArbitrarySchemeRef(gj);
cfg.newPolygonFeature(f);
gj.features.push(f as FeatureWithID);
gj.features.push(f);
return gj;
});
Expand Down
8 changes: 4 additions & 4 deletions src/lib/draw/route/RouteMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
$routeTool!.clearEventListeners();
});
function onSuccess(f: Feature<LineString | Polygon>) {
function onSuccess(feature: Feature<LineString | Polygon>) {
let f = feature as FeatureWithID<LineString>;
gjSchemeCollection.update((gj) => {
f.id = newFeatureId(gj);
f.properties ||= {};
f.properties.scheme_reference = getArbitrarySchemeRef(gj);
// @ts-expect-error We did startRoute, so we know it's a LineString
cfg.newPolygonFeature(f as Feature<LineString>);
gj.features.push(f as FeatureWithID);
cfg.newLineStringFeature(f);
gj.features.push(f);
return gj;
});
Expand Down
9 changes: 5 additions & 4 deletions src/lib/draw/snap_polygon/SnapPolygonMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
$routeTool!.clearEventListeners();
});
function onSuccess(f: Feature<LineString | Polygon>) {
function onSuccess(feature: Feature<LineString | Polygon>) {
// We did startArea, so we know it's a Polygon
let f = feature as FeatureWithID<Polygon>;
gjSchemeCollection.update((gj) => {
f.id = newFeatureId(gj);
f.properties ||= {};
f.properties.scheme_reference = getArbitrarySchemeRef(gj);
// We did startArea, so we know it's a Polygon
cfg.newPolygonFeature(f as Feature<Polygon>);
gj.features.push(f as FeatureWithID);
cfg.newPolygonFeature(f);
gj.features.push(f);
return gj;
});
Expand Down

0 comments on commit 1f5ff7d

Please sign in to comment.