-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (51 loc) · 2.26 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import fetch from 'node-fetch';
import express from 'express';
import { writeFile } from 'fs/promises';
const app = express();
app.get('/api/landUsePlanning', async (req, res) => {
try {
const url = 'https://gisservices.chathamcountync.gov/opendataagol/rest/services/LandUsePlanning/Chatham_PittsboroZoning/MapServer/layers?f=json';
// landUsePlanning
const response = await fetch(url);
const data = await response.json();
console.log(data,"---1")
await writeFile('apiResponseFirst.json', JSON.stringify(data, null, 2))
res.json(data);
} catch (error) {
console.error('Error fetching data:', error);
res.status(500).json({ message: 'Error fetching data' });
}
});
app.get('/api/map-service', async (req, res) => {
try {
const urlLine = 'https://gis11.services.ncdot.gov/arcgis/rest/services/NCDOT_STIP/MapServer/1/query?f=json&where=(1=1) AND (1=1)&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=OBJECTID ASC&outSR=102100';
const urlDot = 'https://gis11.services.ncdot.gov/arcgis/rest/services/NCDOT_STIP/MapServer/0/query?f=json&where=(1=1) AND (1=1)&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=OBJECTID ASC&outSR=102100'
// Line
const responseLine = await fetch(urlLine);
const dataLine = await responseLine.json();
// Dot
const responseDot = await fetch(urlDot);
const dataDot = await responseDot.json();
const attributesArray = [];
if (dataLine.features && Array.isArray(dataLine.features)) {
dataLine.features.forEach((feature, i) => {
attributesArray.push(feature.attributes);
});
}
if (dataDot.features && Array.isArray(dataDot.features)) {
dataDot.features.forEach((feature, i) => {
attributesArray.push(feature.attributes);
});
}
console.log(attributesArray,"---2")
await writeFile('apiResponseSecond.json', JSON.stringify({attributesArray}, null, 2))
res.json(attributesArray);
} catch (error) {
console.error('Error fetching data:', error);
res.status(500).json({ message: 'Error fetching data' });
}
});
const PORT = process.env.PORT || 8000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});