Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add labels to municipal boundaries layer #61

Merged
merged 2 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add distorable reference image layer [#46](https://github.com/azavea/iow-boundary-tool/pull/46)
- Add Land & water basemap [#48](https://github.com/azavea/iow-boundary-tool/pull/48)
- Add user reference image upload [#60](https://github.com/azavea/iow-boundary-tool/pull/60)
- Add labels to municipal boundary layer [#61](https://github.com/azavea/iow-boundary-tool/pull/61)

### Changed

Expand Down
18 changes: 18 additions & 0 deletions src/app/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,21 @@
border-radius: 50%;
background-color: var(--chakra-colors-black);
}

/* end Leaflet.DistortableImage overrides */

.muni-label {
background: rgba(255, 255, 255, 0);
border: 0;
border-radius: 0px;
box-shadow: 0 0px 0px;
font-weight: bold;
font-size: var(--chakra-fontSizes-sm);
color: var(--chakra-colors-purple-900);
text-shadow: 0 0 0.2em var(--chakra-colors-purple-50), 0 0 0.2em var(--chakra-colors-purple-50);
}

.muni-label-light {
color: var(--chakra-colors-purple-50);
text-shadow: 0 0 0.2em var(--chakra-colors-purple-900), 0 0 0.2em var(--chakra-colors-purple-900);
}
36 changes: 33 additions & 3 deletions src/app/src/components/Layers/MunicipalBoundariesLayer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useEffect, useState } from 'react';
import { useEffect, useMemo, useState } from 'react';
import L from 'leaflet';

import { useLayerVisibility, useMapLayer } from '../../hooks';
import { useSelector } from 'react-redux';
import { MUNICIPAL_BOUNDARY_LABELS_MIN_ZOOM_LEVEL } from '../../constants';

const MUNICIPAL_BOUNDARIES_LAYER_STYLE = {
color: '#553C9A', // var(--chakra-colors-purple-700)
Expand All @@ -28,7 +30,35 @@ export default function MunicipalBoundariesLayer() {
}

function RenderGeoJson({ json }) {
useMapLayer(
L.geoJSON(json, { style: () => MUNICIPAL_BOUNDARIES_LAYER_STYLE })
const { basemapType, mapZoom } = useSelector(state => state.map);

// Separating this condition to its own memoized value prevents
// re-creation of the layer on every zoom change
const shouldShowLabels = useMemo(
() => mapZoom > MUNICIPAL_BOUNDARY_LABELS_MIN_ZOOM_LEVEL,
[mapZoom]
);

const layer = useMemo(
() =>
L.geoJSON(json, {
style: () => MUNICIPAL_BOUNDARIES_LAYER_STYLE,
onEachFeature: shouldShowLabels
? (feature, layer) => {
layer.bindTooltip(feature.properties.name20, {
permanent: true,
direction: 'center',
className: `muni-label${
basemapType === 'satellite'
? ' muni-label-light'
: ''
}`,
});
}
: null,
}),
[json, basemapType, shouldShowLabels]
);

useMapLayer(layer);
}
2 changes: 2 additions & 0 deletions src/app/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ export const PARCELS_LAYER_URL =
'https://services.nconemap.gov/secure/rest/services/NC1Map_Parcels/MapServer';

export const SIDEBAR_TEXT_TOOLTIP_THRESHOLD = 30;

export const MUNICIPAL_BOUNDARY_LABELS_MIN_ZOOM_LEVEL = 9;