Skip to content

Commit

Permalink
Use zoning district page looking function from zoning-district model;…
Browse files Browse the repository at this point in the history
… Refactor function to work with all zoning codes;
  • Loading branch information
allthesignals committed Oct 27, 2021
1 parent 14ae980 commit c6609e6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
9 changes: 1 addition & 8 deletions app/models/map-features/lot.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import carto from 'labs-zola/utils/carto';
import config from 'labs-zola/config/environment';
import { handleCommercialZoningExceptions as getPrimaryZone } from 'labs-zola/models/map-features/zoning-district';

const { specialDistrictCrosswalk } = config;

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

const getPrimaryZone = (zonedist = '') => {
if (!zonedist) return '';
let primary = zonedist.match(/\w\d*/)[0].toLowerCase();
// special handling for c1 and c2
if ((primary === 'c1') || (primary === 'c2')) primary = 'c1-c2';
return primary;
};

const bldgclassLookup = {
A0: 'One Family Dwellings - Cape Cod',
A1: 'One Family Dwellings - Two Stories Detached (Small or Moderate Size, With or Without Attic)',
Expand Down
38 changes: 24 additions & 14 deletions app/models/map-features/zoning-district.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,30 @@ const zoningAbbr = {
BPC: 'bpc',
};

// Performs case insensitive string equality check.
// Uses "accent" level sensitivity:
// "accent": Only strings that differ in base letters or accents and other diacritic marks compare as unequal.
// Examples: a ≠ b, a ≠ á, a = A.
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#parameters.
const isSimilar = (string1, string2) => string1.localeCompare(string2, undefined, { sensitivity: 'accent' }) === 0;

// This is purely intended to conform to DCP website's zoning district URL scheme.
// Originally added to make it possible to link out to DCP website:
// https://github.com/NYCPlanning/labs-zola/commit/889cd2ddaf8b17f37a977fb5f84409e3c5535695
export const handleCommercialZoningExceptions = (primaryzone) => {
let url = '';

if ((primaryzone === 'c1') || (primaryzone === 'c2')) {
url = 'c1-c2';
} else if (primaryzone === 'c3') {
url = 'c3-c3a';
} else {
url = primaryzone;
if (!primaryzone) return '';

let code = primaryzone.match(/\w\d*/)[0].toLowerCase();

// Check case insensitive similarity because zoning codes are represented either
// capitalized or otherwise
if (isSimilar(primaryzone, 'c1') || isSimilar(primaryzone, 'c2')) {
code = 'c1-c2';
} else if (isSimilar(primaryzone, 'c3')) {
code = 'c3-c3a';
}

return url;
return code;
};

const { attr } = DS;
Expand All @@ -105,14 +117,12 @@ export default class ZoningDistrictFragment extends MF.Fragment {
@attr('string')
zonedist;

// Used to clean up the 'zonedist' field to build a URL to the DCP website
@computed('zonedist')
get primaryzone() {
get dcpWebsiteFileName() {
const zonedist = this.get('zonedist');

// convert R6A to r6
const primary = handleCommercialZoningExceptions(zonedist.match(/\w\d*/)[0].toLowerCase());

return primary;
return handleCommercialZoningExceptions(zonedist);
}

@computed('zonedist')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{{#unless (eq this.model.zonedist "BPC")}}
<p>
<a
href="https://www1.nyc.gov/site/planning/zoning/districts-tools/{{this.model.primaryzone}}.page"
href="https://www1.nyc.gov/site/planning/zoning/districts-tools/{{this.model.dcpWebsiteFileName}}.page"
target="_blank"
>
{{fa-icon "external-link-alt"}}
Expand Down

0 comments on commit c6609e6

Please sign in to comment.