2021-10-01 08:30:03 -04:00
|
|
|
import React, { FC, useCallback, useEffect, useMemo, useState } from 'react';
|
2021-05-04 12:17:14 -04:00
|
|
|
import { AttributionControl, MapContainer, ZoomControl, useMapEvent, Pane, useMap } from 'react-leaflet';
|
2019-02-11 04:04:19 -05:00
|
|
|
|
2019-11-13 14:23:22 -05:00
|
|
|
import 'leaflet/dist/leaflet.css';
|
2019-11-13 14:20:47 -05:00
|
|
|
import './map.css';
|
|
|
|
|
2020-01-02 05:59:13 -05:00
|
|
|
import { apiGet } from '../apiHelpers';
|
2019-08-14 04:21:42 -04:00
|
|
|
import { HelpIcon } from '../components/icons';
|
2021-02-22 01:59:24 -05:00
|
|
|
import { categoryMapsConfig } from '../config/category-maps-config';
|
|
|
|
import { Category } from '../config/categories-config';
|
2022-12-05 19:04:03 -05:00
|
|
|
import { initialMapViewport, mapBackgroundColor, MapTheme, BoroughEnablementState, ParcelEnablementState, FloodEnablementState, ConservationAreasEnablementState, HistoricDataEnablementState, CreativeEnablementState, HousingEnablementState, VistaEnablementState } from '../config/map-config';
|
2021-02-22 01:59:24 -05:00
|
|
|
import { Building } from '../models/building';
|
2019-11-07 02:39:26 -05:00
|
|
|
|
2021-05-02 13:24:27 -04:00
|
|
|
import { CityBaseMapLayer } from './layers/city-base-map-layer';
|
|
|
|
import { CityBoundaryLayer } from './layers/city-boundary-layer';
|
2022-11-01 16:17:36 -04:00
|
|
|
import { BoroughBoundaryLayer } from './layers/borough-boundary-layer';
|
2022-10-12 07:13:59 -04:00
|
|
|
import { ParcelBoundaryLayer } from './layers/parcel-boundary-layer';
|
2022-11-18 08:51:46 -05:00
|
|
|
import { HistoricDataLayer } from './layers/historic-data-layer';
|
2022-11-08 08:40:37 -05:00
|
|
|
import { FloodBoundaryLayer } from './layers/flood-boundary-layer';
|
2022-11-08 15:47:01 -05:00
|
|
|
import { ConservationAreaBoundaryLayer } from './layers/conservation-boundary-layer';
|
2022-12-05 19:04:03 -05:00
|
|
|
import { VistaBoundaryLayer } from './layers/vista-boundary-layer';
|
|
|
|
import { HousingBoundaryLayer } from './layers/housing-boundary-layer';
|
|
|
|
import { CreativeBoundaryLayer } from './layers/creative-boundary-layer';
|
2021-05-02 13:24:27 -04:00
|
|
|
import { BuildingBaseLayer } from './layers/building-base-layer';
|
|
|
|
import { BuildingDataLayer } from './layers/building-data-layer';
|
|
|
|
import { BuildingNumbersLayer } from './layers/building-numbers-layer';
|
|
|
|
import { BuildingHighlightLayer } from './layers/building-highlight-layer';
|
|
|
|
|
2021-10-01 08:30:03 -04:00
|
|
|
import { Legend } from './legend';
|
2021-05-02 13:24:27 -04:00
|
|
|
import SearchBox from './search-box';
|
|
|
|
import ThemeSwitcher from './theme-switcher';
|
2022-11-01 16:17:36 -04:00
|
|
|
import BoroughSwitcher from './borough-switcher';
|
2022-10-12 07:13:59 -04:00
|
|
|
import ParcelSwitcher from './parcel-switcher';
|
2022-11-08 08:40:37 -05:00
|
|
|
import FloodSwitcher from './flood-switcher';
|
2022-11-08 15:47:01 -05:00
|
|
|
import ConservationAreaSwitcher from './conservation-switcher';
|
2022-11-18 08:51:46 -05:00
|
|
|
import HistoricDataSwitcher from './historic-data-switcher';
|
2022-12-05 19:04:03 -05:00
|
|
|
import VistaSwitcher from './vista-switcher';
|
|
|
|
import CreativeSwitcher from './creative-switcher';
|
|
|
|
import HousingSwitcher from './housing-switcher';
|
2021-10-01 08:30:03 -04:00
|
|
|
import { BuildingMapTileset } from '../config/tileserver-config';
|
2018-09-09 17:22:44 -04:00
|
|
|
|
2019-09-08 20:09:05 -04:00
|
|
|
interface ColouringMapProps {
|
2021-02-22 01:59:24 -05:00
|
|
|
selectedBuildingId: number;
|
2019-09-08 20:09:05 -04:00
|
|
|
mode: 'basic' | 'view' | 'edit' | 'multi-edit';
|
2021-02-22 01:59:24 -05:00
|
|
|
category: Category;
|
|
|
|
revisionId: string;
|
|
|
|
onBuildingAction: (building: Building) => void;
|
2019-09-08 20:09:05 -04:00
|
|
|
}
|
|
|
|
|
2021-10-01 08:30:03 -04:00
|
|
|
export const ColouringMap : FC<ColouringMapProps> = ({
|
|
|
|
category,
|
|
|
|
mode,
|
|
|
|
revisionId,
|
|
|
|
onBuildingAction,
|
|
|
|
selectedBuildingId,
|
|
|
|
children
|
|
|
|
}) => {
|
|
|
|
|
2021-12-09 11:39:00 -05:00
|
|
|
const [theme, setTheme] = useState<MapTheme>('night');
|
2022-12-02 10:43:18 -05:00
|
|
|
const [borough, setBorough] = useState<BoroughEnablementState>('enabled');
|
2022-10-12 07:13:59 -04:00
|
|
|
const [parcel, setParcel] = useState<ParcelEnablementState>('disabled');
|
2022-11-08 08:40:37 -05:00
|
|
|
const [flood, setFlood] = useState<FloodEnablementState>('disabled');
|
2022-11-08 15:47:01 -05:00
|
|
|
const [conservation, setConservation] = useState<ConservationAreasEnablementState>('disabled');
|
2022-11-18 08:51:46 -05:00
|
|
|
const [historicData, setHistoricData] = useState<HistoricDataEnablementState>('disabled');
|
2022-12-05 19:04:03 -05:00
|
|
|
const [creative, setCreative] = useState<CreativeEnablementState>('disabled');
|
|
|
|
const [housing, setHousing] = useState<HousingEnablementState>('disabled');
|
|
|
|
const [vista, setVista] = useState<VistaEnablementState>('disabled');
|
2021-10-01 08:30:03 -04:00
|
|
|
const [position, setPosition] = useState(initialMapViewport.position);
|
|
|
|
const [zoom, setZoom] = useState(initialMapViewport.zoom);
|
|
|
|
|
|
|
|
const [mapColourScale, setMapColourScale] = useState<BuildingMapTileset>();
|
|
|
|
|
|
|
|
const handleLocate = useCallback(
|
|
|
|
(lat: number, lng: number, zoom: number) => {
|
|
|
|
setPosition([lat, lng]);
|
|
|
|
setZoom(zoom);
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleClick = useCallback(
|
|
|
|
async (e) => {
|
|
|
|
const {lat, lng} = e.latlng;
|
|
|
|
const data = await apiGet(`/api/buildings/locate?lat=${lat}&lng=${lng}`);
|
|
|
|
const building = data?.[0];
|
|
|
|
onBuildingAction(building);
|
|
|
|
},
|
|
|
|
[onBuildingAction],
|
|
|
|
)
|
|
|
|
|
|
|
|
const themeSwitch = useCallback(
|
|
|
|
(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const newTheme = (theme === 'light')? 'night' : 'light';
|
|
|
|
setTheme(newTheme);
|
|
|
|
},
|
|
|
|
[theme],
|
|
|
|
)
|
|
|
|
|
2022-11-01 16:17:36 -04:00
|
|
|
const boroughSwitch = useCallback(
|
|
|
|
(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const newBorough = (borough === 'enabled')? 'disabled' : 'enabled';
|
|
|
|
setBorough(newBorough);
|
|
|
|
},
|
|
|
|
[borough],
|
|
|
|
)
|
|
|
|
|
2022-10-12 07:13:59 -04:00
|
|
|
const parcelSwitch = useCallback(
|
|
|
|
(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const newParcel = (parcel === 'enabled')? 'disabled' : 'enabled';
|
|
|
|
setParcel(newParcel);
|
|
|
|
},
|
|
|
|
[parcel],
|
|
|
|
)
|
|
|
|
|
2022-11-08 08:40:37 -05:00
|
|
|
const floodSwitch = useCallback(
|
|
|
|
(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const newFlood = (flood === 'enabled')? 'disabled' : 'enabled';
|
|
|
|
setFlood(newFlood);
|
|
|
|
},
|
|
|
|
[flood],
|
|
|
|
)
|
|
|
|
|
2022-11-08 15:47:01 -05:00
|
|
|
const conservationSwitch = useCallback(
|
|
|
|
(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const newConservation = (conservation === 'enabled')? 'disabled' : 'enabled';
|
|
|
|
setConservation(newConservation);
|
|
|
|
},
|
|
|
|
[conservation],
|
|
|
|
)
|
|
|
|
|
2022-11-18 08:51:46 -05:00
|
|
|
const historicDataSwitch = useCallback(
|
|
|
|
(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const newHistoric = (historicData === 'enabled')? 'disabled' : 'enabled';
|
|
|
|
setHistoricData(newHistoric);
|
|
|
|
},
|
|
|
|
[historicData],
|
|
|
|
)
|
|
|
|
|
2022-12-05 19:04:03 -05:00
|
|
|
const vistaSwitch = useCallback(
|
|
|
|
(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const newVista = (vista === 'enabled')? 'disabled' : 'enabled';
|
|
|
|
setVista(newVista);
|
|
|
|
},
|
|
|
|
[vista],
|
|
|
|
)
|
|
|
|
|
|
|
|
const housingSwitch = useCallback(
|
|
|
|
(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const newHousing = (housing === 'enabled')? 'disabled' : 'enabled';
|
|
|
|
setHousing(newHousing);
|
|
|
|
},
|
|
|
|
[housing],
|
|
|
|
)
|
|
|
|
|
|
|
|
const creativeSwitch = useCallback(
|
|
|
|
(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const newCreative = (creative === 'enabled')? 'disabled' : 'enabled';
|
|
|
|
setCreative(newCreative);
|
|
|
|
},
|
|
|
|
[creative],
|
|
|
|
)
|
|
|
|
|
2021-10-01 08:30:03 -04:00
|
|
|
const categoryMapDefinitions = useMemo(() => categoryMapsConfig[category], [category]);
|
2021-05-02 13:24:27 -04:00
|
|
|
|
2021-10-01 08:30:03 -04:00
|
|
|
useEffect(() => {
|
|
|
|
if(!categoryMapDefinitions.some(def => def.mapStyle === mapColourScale)) {
|
|
|
|
setMapColourScale(categoryMapDefinitions[0].mapStyle);
|
|
|
|
}
|
|
|
|
}, [categoryMapDefinitions, mapColourScale]);
|
|
|
|
|
|
|
|
const hasSelection = selectedBuildingId != undefined;
|
|
|
|
const isEdit = ['edit', 'multi-edit'].includes(mode);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="map-container">
|
|
|
|
<MapContainer
|
|
|
|
center={initialMapViewport.position}
|
|
|
|
zoom={initialMapViewport.zoom}
|
|
|
|
minZoom={9}
|
|
|
|
maxZoom={18}
|
|
|
|
doubleClickZoom={false}
|
|
|
|
zoomControl={false}
|
|
|
|
attributionControl={false}
|
|
|
|
>
|
|
|
|
<ClickHandler onClick={handleClick} />
|
|
|
|
<MapBackgroundColor theme={theme} />
|
|
|
|
<MapViewport position={position} zoom={zoom} />
|
|
|
|
|
|
|
|
<Pane
|
|
|
|
key={theme}
|
|
|
|
name={'cc-base-pane'}
|
|
|
|
style={{zIndex: 50}}
|
2019-05-27 11:39:16 -04:00
|
|
|
>
|
2021-10-01 08:30:03 -04:00
|
|
|
<CityBaseMapLayer theme={theme} />
|
|
|
|
<BuildingBaseLayer theme={theme} />
|
|
|
|
</Pane>
|
|
|
|
|
|
|
|
{
|
|
|
|
mapColourScale &&
|
|
|
|
<BuildingDataLayer
|
|
|
|
tileset={mapColourScale}
|
|
|
|
revisionId={revisionId}
|
|
|
|
/>
|
|
|
|
}
|
2021-05-02 13:24:27 -04:00
|
|
|
|
2021-10-01 08:30:03 -04:00
|
|
|
<Pane
|
|
|
|
name='cc-overlay-pane'
|
|
|
|
style={{zIndex: 300}}
|
|
|
|
>
|
|
|
|
<CityBoundaryLayer />
|
2022-11-18 08:51:46 -05:00
|
|
|
<HistoricDataLayer enablement={historicData}/>
|
2022-11-01 16:17:36 -04:00
|
|
|
<BoroughBoundaryLayer enablement={borough}/>
|
2022-10-12 07:13:59 -04:00
|
|
|
<ParcelBoundaryLayer enablement={parcel}/>
|
2022-11-08 08:40:37 -05:00
|
|
|
<FloodBoundaryLayer enablement={flood}/>
|
2022-11-08 15:47:01 -05:00
|
|
|
<ConservationAreaBoundaryLayer enablement={conservation}/>
|
2022-12-05 19:04:03 -05:00
|
|
|
<VistaBoundaryLayer enablement={vista}/>
|
|
|
|
<HousingBoundaryLayer enablement={housing}/>
|
|
|
|
<CreativeBoundaryLayer enablement={creative}/>
|
2021-10-01 08:30:03 -04:00
|
|
|
<BuildingNumbersLayer revisionId={revisionId} />
|
2021-05-02 13:24:27 -04:00
|
|
|
{
|
2021-10-01 08:30:03 -04:00
|
|
|
selectedBuildingId &&
|
|
|
|
<BuildingHighlightLayer
|
|
|
|
selectedBuildingId={selectedBuildingId}
|
|
|
|
baseTileset={mapColourScale}
|
2021-12-03 14:32:54 -05:00
|
|
|
/>
|
2021-05-02 13:24:27 -04:00
|
|
|
}
|
2021-10-01 08:30:03 -04:00
|
|
|
</Pane>
|
|
|
|
|
|
|
|
<ZoomControl position="topright" />
|
|
|
|
<AttributionControl prefix=""/>
|
|
|
|
</MapContainer>
|
|
|
|
{
|
|
|
|
mode !== 'basic' &&
|
|
|
|
<>
|
|
|
|
{
|
|
|
|
!hasSelection &&
|
|
|
|
<div className="map-notice">
|
|
|
|
<HelpIcon /> {isEdit ? 'Click a building to edit' : 'Click a building for details'}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
<Legend mapColourScaleDefinitions={categoryMapDefinitions} mapColourScale={mapColourScale} onMapColourScale={setMapColourScale}/>
|
2021-12-03 14:37:03 -05:00
|
|
|
<ThemeSwitcher onSubmit={themeSwitch} currentTheme={theme} />
|
2022-11-01 16:17:36 -04:00
|
|
|
<BoroughSwitcher onSubmit={boroughSwitch} currentDisplay={borough} />
|
2022-10-12 07:13:59 -04:00
|
|
|
<ParcelSwitcher onSubmit={parcelSwitch} currentDisplay={parcel} />
|
2022-11-08 08:40:37 -05:00
|
|
|
<FloodSwitcher onSubmit={floodSwitch} currentDisplay={flood} />
|
2022-11-08 15:47:01 -05:00
|
|
|
<ConservationAreaSwitcher onSubmit={conservationSwitch} currentDisplay={conservation} />
|
2022-11-18 08:51:46 -05:00
|
|
|
<HistoricDataSwitcher onSubmit={historicDataSwitch} currentDisplay={historicData} />
|
2022-12-05 19:04:03 -05:00
|
|
|
<VistaSwitcher onSubmit={vistaSwitch} currentDisplay={vista} />
|
|
|
|
<HousingSwitcher onSubmit={housingSwitch} currentDisplay={housing} />
|
|
|
|
<CreativeSwitcher onSubmit={creativeSwitch} currentDisplay={creative} />
|
2021-10-01 08:30:03 -04:00
|
|
|
<SearchBox onLocate={handleLocate} />
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
2019-05-27 11:20:00 -04:00
|
|
|
}
|
2018-09-09 17:22:44 -04:00
|
|
|
|
2021-12-03 14:32:54 -05:00
|
|
|
function ClickHandler({ onClick }: {onClick: (e) => void}) {
|
2021-04-26 14:19:06 -04:00
|
|
|
useMapEvent('click', (e) => onClick(e));
|
2021-12-03 14:32:54 -05:00
|
|
|
|
2021-04-26 14:19:06 -04:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-12-03 14:32:54 -05:00
|
|
|
function MapBackgroundColor({ theme}: {theme: MapTheme}) {
|
2021-05-04 12:17:14 -04:00
|
|
|
const map = useMap();
|
|
|
|
useEffect(() => {
|
|
|
|
map.getContainer().style.backgroundColor = mapBackgroundColor[theme];
|
|
|
|
});
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-06-11 20:35:20 -04:00
|
|
|
function MapViewport({
|
|
|
|
position,
|
|
|
|
zoom
|
|
|
|
}: {
|
|
|
|
position: [number, number];
|
|
|
|
zoom: number;
|
|
|
|
}) {
|
|
|
|
const map = useMap();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
map.setView(position, zoom)
|
|
|
|
}, [position, zoom]);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|