Skip to content

Commit

Permalink
Add ArcGIS layer types
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Oct 8, 2024
1 parent f1e98eb commit 8feda3c
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions tasks/hooks/src/adaptors/arcgis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,27 @@ import { geojsonToArcGIS } from '@terraformer/arcgis'
import proj4 from 'proj4';

export default async function arcgis(data: any): Promise<boolean> {
if (data.feat.geometry.type !== 'Point') {
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
} else if (data.body.lines && data.feat.geometry.type === 'LineString') {
layer = data.body.lines
} else if (data.body.polys && data.feat.geometry.type === 'Polygon') {
layer = data.body.polys;
} else {
console.error(`ok - skipping ${data.feat.properties.callsign} due to geometry: ${data.feat.geometry.type}`);
return false;
}

const res_query = await fetch(data.body.layer + '/query', {
const res_query = await fetch(layer + '/query', {
method: 'POST',
headers: {
'Referer': data.secrets.referer,
Expand Down Expand Up @@ -44,7 +59,7 @@ export default async function arcgis(data: any): Promise<boolean> {
}

if (!query.features.length) {
const res = await fetch(new URL(data.body.layer + '/addFeatures'), {
const res = await fetch(new URL(layer + '/addFeatures'), {
method: 'POST',
headers: {
'Referer': data.secrets.referer,
Expand Down Expand Up @@ -81,7 +96,7 @@ export default async function arcgis(data: any): Promise<boolean> {
} else {
const oid = query.features[0].attributes.objectid;

const res = await fetch(new URL(data.body.layer + '/updateFeatures'), {
const res = await fetch(new URL(layer + '/updateFeatures'), {
method: 'POST',
headers: {
'Referer': data.secrets.referer,
Expand Down

0 comments on commit 8feda3c

Please sign in to comment.