Skip to content

Commit 360275b

Browse files
committed
Use zoning district page looking function from zoning-district model; Refactor function to work with all zoning codes;
1 parent 14ae980 commit 360275b

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

app/models/map-features/lot.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { computed } from '@ember/object';
44
import { alias } from '@ember/object/computed';
55
import carto from 'labs-zola/utils/carto';
66
import config from 'labs-zola/config/environment';
7+
import { handleCommercialZoningExceptions as getPrimaryZone } from 'labs-zola/models/map-features/zoning-district';
78

89
const { specialDistrictCrosswalk } = config;
910

@@ -14,14 +15,6 @@ const specialPurposeDistrictsSQL = function(table, spdist1, spdist2, spdist3) {
1415
WHERE sdlbl IN ('${spdist1}', '${spdist2}', '${spdist3}')`;
1516
};
1617

17-
const getPrimaryZone = (zonedist = '') => {
18-
if (!zonedist) return '';
19-
let primary = zonedist.match(/\w\d*/)[0].toLowerCase();
20-
// special handling for c1 and c2
21-
if ((primary === 'c1') || (primary === 'c2')) primary = 'c1-c2';
22-
return primary;
23-
};
24-
2518
const bldgclassLookup = {
2619
A0: 'One Family Dwellings - Cape Cod',
2720
A1: 'One Family Dwellings - Two Stories Detached (Small or Moderate Size, With or Without Attic)',

app/models/map-features/zoning-district.js

+26-14
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,32 @@ const zoningAbbr = {
8383
BPC: 'bpc',
8484
};
8585

86+
// Performs case insensitive string equality check.
87+
// Uses "accent" level sensitivity:
88+
// "accent": Only strings that differ in base letters or accents and other diacritic marks compare as unequal.
89+
// Examples: a ≠ b, a ≠ á, a = A.
90+
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#parameters.
91+
const isSimilar = (string1, string2) => {
92+
return string1.localeCompare(string2, undefined, { sensitivity: 'accent' }) === 0;
93+
};
94+
95+
// This is purely intended to conform to DCP website's zoning district URL scheme.
96+
// Originally added to make it possible to link out to DCP website:
97+
// https://github.com/NYCPlanning/labs-zola/commit/889cd2ddaf8b17f37a977fb5f84409e3c5535695
8698
export const handleCommercialZoningExceptions = (primaryzone) => {
87-
let url = '';
88-
89-
if ((primaryzone === 'c1') || (primaryzone === 'c2')) {
90-
url = 'c1-c2';
91-
} else if (primaryzone === 'c3') {
92-
url = 'c3-c3a';
93-
} else {
94-
url = primaryzone;
99+
if (!primaryzone) return;
100+
101+
let code = primaryzone.match(/\w\d*/)[0].toLowerCase();
102+
103+
// Check case insensitive similarity because zoning codes are represented either
104+
// capitalized or otherwise
105+
if (isSimilar(primaryzone, 'c1') || isSimilar(primaryzone, 'c2')) {
106+
code = 'c1-c2';
107+
} else if (isSimilar(primaryzone, 'c3')) {
108+
code = 'c3-c3a';
95109
}
96110

97-
return url;
111+
return code;
98112
};
99113

100114
const { attr } = DS;
@@ -105,14 +119,12 @@ export default class ZoningDistrictFragment extends MF.Fragment {
105119
@attr('string')
106120
zonedist;
107121

122+
// Used to clean up the 'zonedist' field to build a URL to the DCP website
108123
@computed('zonedist')
109-
get primaryzone() {
124+
get dcpWebsiteFileName() {
110125
const zonedist = this.get('zonedist');
111126

112-
// convert R6A to r6
113-
const primary = handleCommercialZoningExceptions(zonedist.match(/\w\d*/)[0].toLowerCase());
114-
115-
return primary;
127+
return handleCommercialZoningExceptions(zonedist);
116128
}
117129

118130
@computed('zonedist')

app/templates/components/layer-record-views/zoning-district.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{{#unless (eq this.model.zonedist "BPC")}}
1111
<p>
1212
<a
13-
href="https://www1.nyc.gov/site/planning/zoning/districts-tools/{{this.model.primaryzone}}.page"
13+
href="https://www1.nyc.gov/site/planning/zoning/districts-tools/{{this.model.dcpWebsiteFileName}}.page"
1414
target="_blank"
1515
>
1616
{{fa-icon "external-link-alt"}}

0 commit comments

Comments
 (0)