Skip to content

Commit

Permalink
Seperate out geom types
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Oct 8, 2024
1 parent c666af1 commit ccbedb3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
6 changes: 3 additions & 3 deletions api/web/src/components/ConnectionSinkEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
:url='sink.body.url'
:username='sink.body.username'
:password='sink.body.password'
@layer='sink.body.layer = $event'
@layer='sink.body.points = $event'
@close='esriView.view = false'
/>
</template>
Expand All @@ -127,7 +127,7 @@
<div class='d-flex'>
<div class='ms-auto'>
<button
v-if='sink.body.layer'
v-if='sink.body.points'
class='cursor-pointer btn btn-primary'
@click='create'
>
Expand Down Expand Up @@ -207,7 +207,7 @@ export default {
url: '',
username: '',
password: '',
layer: ''
points: ''
},
logging: false,
enabled: true,
Expand Down
2 changes: 1 addition & 1 deletion tasks/hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"type": "module",
"private": true,
"scripts": {
"tsc": "tsc --noEmit --watch",
"lint": "eslint src/",
"check": "tsc --noEmit src/index.ts",
"build": "tsup --target es2022 --format esm src/index.ts"
},
"dependencies": {
Expand Down
44 changes: 26 additions & 18 deletions tasks/hooks/src/adaptors/arcgis.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import { Point } from 'arcgis-rest-api';
import { Geometry, Point, Polyline, Polygon } from 'arcgis-rest-api';
import { geojsonToArcGIS } from '@terraformer/arcgis'
// @ts-expect-error Default export behavior
import proj4 from 'proj4';

export default async function arcgis(data: any): Promise<boolean> {
if (
(data.feat.geometry.type === 'Point' && !data.body.points)
|| (data.feat.geometry.type === 'LineString' && !data.body.lines)
|| (data.feat.geometry.type === 'Polygon' && !data.body.polys)
|| (!['Point', 'LineString', 'Polygon'].includes(data.feat.geometry.type))
) {
}

let layer;
if (data.body.points && data.feat.geometry.type === 'Point') {
layer = data.body.points
Expand Down Expand Up @@ -44,18 +37,33 @@ export default async function arcgis(data: any): Promise<boolean> {

if (query.error) throw new Error(query.error.message);

let geometry = geojsonToArcGIS(data.feat.geometry) as Point;
if (!geometry.x || !geometry.y) throw new Error('Incompatible Geometry');
let geometry: Geometry;
if (data.feat.geometry.type === 'Point') {
let geom = geojsonToArcGIS(data.feat.geometry) as Point;
if (!geom.x || !geom.y) throw new Error('Incompatible Geometry');

const proj = proj4('EPSG:4326', 'EPSG:3857', [ geometry.x, geometry.y ]);
const proj = proj4('EPSG:4326', 'EPSG:3857', [ geom.x, geom.y ]);

geometry = {
x: proj[0],
y: proj[1],
spatialReference: {
wkid: 102100,
latestWkid: 3857
geom = {
x: proj[0],
y: proj[1],
spatialReference: {
wkid: 102100,
latestWkid: 3857
}
}

geometry = geom;
} else if (data.feat.geometry.type === 'LineString') {
let geom = geojsonToArcGIS(data.feat.geometry) as Polyline;

console.error(geom);
} else if (data.feat.geometry.type === 'Polygon') {
let geom = geojsonToArcGIS(data.feat.geometry) as Polygon;

console.error(geom);
} else {
throw new Error(`Incompatible Geometry: ${data.feat.geometry.type}`);
}

if (!query.features.length) {
Expand Down
4 changes: 2 additions & 2 deletions tasks/hooks/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Lambda from "aws-lambda";
import ArcGIS from './adaptors/arcgis.js';
import CW from '@aws-sdk/client-cloudwatch';
import * as Lambda from "aws-lambda";
import * as CW from '@aws-sdk/client-cloudwatch';

type Meta = {
Timestamp: Date;
Expand Down

0 comments on commit ccbedb3

Please sign in to comment.