-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathZoningStore.js
More file actions
290 lines (275 loc) · 12.1 KB
/
ZoningStore.js
File metadata and controls
290 lines (275 loc) · 12.1 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
import axios from 'axios';
import { defineStore } from 'pinia';
import { useParcelsStore } from './ParcelsStore';
import { useGeocodeStore } from '@/stores/GeocodeStore.js'
import useTransforms from '@/composables/useTransforms';
const { rcoPrimaryContact, phoneNumber, date } = useTransforms();
export const useZoningStore = defineStore('ZoningStore', {
state: () => {
return {
zoningBase: {},
loadingZoningBase: false,
zoningOverlays: {},
loadingZoningOverlays: false,
pendingBills: {},
loadingPendingBills: false,
zoningAppeals: {},
loadingZoningAppeals: false,
rcos: {},
loadingRcos: false,
loadingZoningData: true,
};
},
actions: {
async fillAllZoningData() {
this.fillZoningBase();
this.fillZoningOverlays();
this.fillPendingBills();
this.fillZoningAppeals();
this.fillRcos();
},
async clearAllZoningData() {
this.zoningBase = {};
this.loadingZoningBase = true;
this.zoningOverlays = {};
this.loadingZoningOverlays = true;
this.pendingBills = {};
this.loadingPendingBills = true;
this.zoningAppeals = {};
this.loadingZoningAppeals = true;
this.rcos = {};
this.loadingRcos = true;
this.loadingZoningData = true;
},
async fillZoningBase() {
try {
const ParcelsStore = useParcelsStore();
const features = ParcelsStore.dor.features;
if (!features) return;
for (let feature of features) {
let baseUrl = 'https://phl.carto.com/api/v2/sql?q=';
const mapreg = feature.properties.MAPREG;
const query = "\
WITH all_zoning AS \
( \
SELECT * \
FROM phl.zoning_basedistricts \
), \
parcel AS \
( \
SELECT * \
FROM phl.dor_parcel \
WHERE dor_parcel.mapreg = '" + mapreg + "' \
), \
zp AS \
( \
SELECT all_zoning.* \
FROM all_zoning, parcel \
WHERE St_intersects(parcel.the_geom, all_zoning.the_geom) \
), \
combine AS \
( \
SELECT zp.objectid, \
zp.long_code, \
zp.pending, \
zp.pendingbill, \
zp.pendingbillurl, \
St_area(St_intersection(zp.the_geom, parcel.the_geom)) / St_area(parcel.the_geom) AS overlap_area \
FROM zp, parcel \
), \
total AS \
( \
SELECT long_code, pending, pendingbill, pendingbillurl, sum(overlap_area) as sum_overlap_area \
FROM combine \
GROUP BY long_code, pending, pendingbill, pendingbillurl \
) \
SELECT * \
FROM total \
WHERE sum_overlap_area >= 0.01";
const url = baseUrl += query;
const response = await fetch(url);
if (response.ok) {
this.zoningBase[feature.properties.OBJECTID] = await response.json();
this.loadingZoningBase = false;
} else {
this.loadingZoningBase = false;
if (import.meta.env.VITE_DEBUG == 'true') console.warn('fillZoningBase - await resolved but HTTP status was not successful');
}
}
} catch {
this.loadingZoningBase = false;
if (import.meta.env.VITE_DEBUG == 'true') console.error('fillZoningBase - await never resolved, failed to fetch data');
}
},
async fillZoningOverlays() {
const ParcelsStore = useParcelsStore();
const features = ParcelsStore.dor.features;
if (!features) return;
for (let feature of features) {
try {
let baseUrl = 'https://phl.carto.com/api/v2/sql?q=';
const mapreg = feature.properties.MAPREG;
const query = "WITH all_zoning AS \
( SELECT * FROM phl.zoning_overlays ), \
parcel AS \
( SELECT * FROM phl.dor_parcel WHERE dor_parcel.mapreg = '" + mapreg + "' ), \
zp AS \
( SELECT all_zoning.* FROM all_zoning, parcel WHERE st_intersects(parcel.the_geom, all_zoning.the_geom)) \
SELECT code_section, code_section_link, objectid, overlay_name, overlay_symbol, pending, pendingbill, pendingbillurl, sunset_date, type \
FROM zp";
const url = baseUrl += query;
const response = await fetch(url);
if (response.ok) {
const data = await response.json();
if (import.meta.env.VITE_DEBUG == 'true') console.log('data:', data);
data.rows.forEach(row => {
row.link = `<a target='_blank' href='${row.code_section_link}'>${row.code_section}<i class='fas fa-external-link-alt'></i></a>`
});
this.zoningOverlays[feature.properties.OBJECTID] = data;
this.loadingZoningOverlays = false;
} else {
this.loadingZoningOverlays = false;
if (import.meta.env.VITE_DEBUG == 'true') console.warn('fillZoningOverlays - await resolved but HTTP status was not successful');
}
} catch {
this.loadingZoningOverlays = false;
if (import.meta.env.VITE_DEBUG == 'true') console.error('fillZoningOverlays - await never resolved, failed to fetch data');
}
}
},
async fillPendingBills() {
const ParcelsStore = useParcelsStore();
const features = ParcelsStore.dor.features;
if (!features) {
this.loadingPendingBills = false;
return;
}
for (let feature of features) {
let featureId = feature.properties.OBJECTID,
target = this.zoningBase[featureId] || {},
data = target.data || {};
// include only rows where pending is true
const { rows=[]} = data;
const rowsFiltered = rows.filter(row => row.pending === 'Yes');
// give each pending zoning bill a type of "zoning"
const rowsFilteredWithType = rowsFiltered.map((row) => {
row.billType = 'Base District';
row.currentZoning = row.long_code;
return row;
});
let overlayRowsFilteredWithType = [];
// append pending overlays
if (this.zoningOverlays[featureId]) {
const overlayRows = this.zoningOverlays[featureId].rows;
const overlayRowsFiltered = overlayRows.filter(row => row.pending === 'Yes');
overlayRowsFilteredWithType = overlayRowsFiltered.map((row) => {
row.billType = 'Overlay';
row.currentZoning = row.overlay_name;
return row;
});
} else {
overlayRowsFilteredWithType = [];
}
// combine pending zoning and overlays
const zoningAndOverlays = rowsFilteredWithType.concat(overlayRowsFilteredWithType);
this.pendingBills[featureId] = zoningAndOverlays;
}
this.loadingPendingBills = false;
},
async fillZoningAppeals() {
try {
const GeocodeStore = useGeocodeStore();
const feature = GeocodeStore.aisData.features[0];
let baseUrl = 'https://phl.carto.com/api/v2/sql?q=';
const streetaddress = feature.properties.street_address;
const pwd_parcel_id = feature.properties.pwd_parcel_id;
const addressId = feature.properties.li_address_key.replace(/\|/g, "', '");
const eclipseLocationId = feature.properties.eclipse_location_id.replace(/\|/g, "', '");
const eclipseQuery = feature.properties.eclipse_location_id ? `addressobjectid IN ('${eclipseLocationId}')` : ``;
const zoningQuery = `applicationtype in ('Zoning Board of Adjustment', 'RB_ZBA') AND applicationtype is not null`
const opaQuery = feature.properties.opa_account_num ? ` AND opa_account_num IN ('${ feature.properties.opa_account_num}')` : ``;
const query = `SELECT * FROM APPEALS WHERE (address = '${ streetaddress }' AND ${zoningQuery} \
OR addressobjectid IN ('${ addressId }') AND ${zoningQuery} \
OR parcel_id_num IN ('${ pwd_parcel_id }') AND ${zoningQuery}) \
${ opaQuery } AND ${zoningQuery} \
AND systemofrecord IN ('HANSEN') \
UNION SELECT * FROM APPEALS WHERE (${eclipseQuery} AND ${zoningQuery} \
OR parcel_id_num IN ('${ pwd_parcel_id }') AND ${zoningQuery}) \
${ opaQuery } AND ${zoningQuery} \
AND systemofrecord IN ('ECLIPSE') \
ORDER BY scheduleddate DESC`;
const url = baseUrl += query;
const response = await fetch(url);
if (response.ok) {
let data = await response.json();
console.log('response ok, response:', response, 'data:', data);
data.rows.forEach((row) => {
console.log('in loop, row:', row);
let address = row.address;
if (row.unit_num && row.unit_num != null) {
address += ' Unit ' + row.unit_num;
}
console.log('in loop, row:', row);
row.appeallink = `<a target='_blank' href='https://li.phila.gov/Property-History/search/Appeal-Detail?address=${row.address}&Id=${row.appealnumber}'>${row.appealnumber}<i class='fas fa-external-link-alt'></i></a>`
row.calendarlink = "<a target='_blank' href='https://li.phila.gov/zba-appeals-calendar/appeal?from=2-7-2000&to=4-7-2050®ion=all&Id="+row.appealnumber+"'>"+date(row.scheduleddate, 'MM/dd/yyyy')+" <i class='fa fa-external-link-alt'></i></a>";
console.log('in loop, row:', row);
});
this.zoningAppeals = data;
this.loadingZoningAppeals = false;
} else {
this.loadingZoningAppeals = false;
if (import.meta.env.VITE_DEBUG == 'true') console.warn('fillZoningAppeals - await resolved but HTTP status was not successful');
}
} catch {
this.loadingZoningAppeals = false;
if (import.meta.env.VITE_DEBUG == 'true') console.error('fillZoningAppeals - await never resolved, failed to fetch data');
}
},
async fillRcos() {
try {
const GeocodeStore = useGeocodeStore();
const feature = GeocodeStore.aisData.features[0];
let url = '//services.arcgis.com/fLeGjb7u4uXqeF9q/arcgis/rest/services/Zoning_RCO/FeatureServer/0/query';
let params = {
'returnGeometry': true,
'where': "1=1",
'outSR': 4326,
'outFields': '*',
'inSr': 4326,
'geometryType': 'esriGeometryPoint',
'spatialRel': 'esriSpatialRelWithin',
'f': 'geojson',
'geometry': JSON.stringify({ "x": feature.geometry.coordinates[0], "y": feature.geometry.coordinates[1], "spatialReference": { "wkid": 4326 }}),
};
const response = await axios.get(url, { params });
if (response.status === 200) {
let data = await response.data;
data.features.sort((a, b) => {
if (a.properties.ORGANIZATION_NAME < b.properties.ORGANIZATION_NAME) {
return -1;
}
if (a.properties.ORGANIZATION_NAME > b.properties.ORGANIZATION_NAME) {
return 1;
}
return 0;
});
data.features.forEach(item => {
item.properties.rco = `<b>${item.properties.ORGANIZATION_NAME}</b><br>${item.properties.ORGANIZATION_ADDRESS}`;
item.properties.contact = `${rcoPrimaryContact(item.properties.PRIMARY_NAME)}<br>${phoneNumber(item.properties.PRIMARY_PHONE)}<br><a target='_blank' href='mailto:${item.properties.PRIMARY_EMAIL}'>${item.properties.PRIMARY_EMAIL}</a>`;
})
this.rcos = data;
this.loadingRcos = false;
} else {
this.loadingRcos = false;
if (import.meta.env.VITE_DEBUG == 'true') console.warn('fillRcos - await resolved but HTTP status was not successful');
}
} catch {
this.loadingRcos = false;
if (import.meta.env.VITE_DEBUG == 'true') console.error('fillRcos - await never resolved, failed to fetch data');
}
}
},
// keeping formatting getters here in the store only works if the data is not looped
// through for a horizontal table
getters: {},
})