Add GLA boundary to map (#464)

This commit is contained in:
mz8i 2019-10-28 16:48:59 +00:00 committed by GitHub
parent 5d3eff4800
commit 997e92d27d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 5 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,16 +1,15 @@
import { LatLngExpression } from 'leaflet';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import React, { Component, Fragment } from 'react'; import React, { Component, Fragment } from 'react';
import { Map, TileLayer, ZoomControl, AttributionControl } from 'react-leaflet-universal'; import { Map, TileLayer, ZoomControl, AttributionControl, GeoJSON } from 'react-leaflet-universal';
import '../../../node_modules/leaflet/dist/leaflet.css' import '../../../node_modules/leaflet/dist/leaflet.css'
import './map.css' import './map.css'
import { HelpIcon } from '../components/icons'; import { HelpIcon } from '../components/icons';
import Legend from './legend'; import Legend from './legend';
import { parseCategoryURL } from '../../parse';
import SearchBox from './search-box'; import SearchBox from './search-box';
import ThemeSwitcher from './theme-switcher'; import ThemeSwitcher from './theme-switcher';
import { GeoJsonObject } from 'geojson';
const OS_API_KEY = 'NVUxtY5r8eA6eIfwrPTAGKrAAsoeI9E9'; const OS_API_KEY = 'NVUxtY5r8eA6eIfwrPTAGKrAAsoeI9E9';
@ -28,6 +27,7 @@ interface ColouringMapState {
lat: number; lat: number;
lng: number; lng: number;
zoom: number; zoom: number;
boundary: GeoJsonObject;
} }
/** /**
* Map area * Map area
@ -48,7 +48,8 @@ class ColouringMap extends Component<ColouringMapProps, ColouringMapState> { //
theme: 'night', theme: 'night',
lat: 51.5245255, lat: 51.5245255,
lng: -0.1338422, lng: -0.1338422,
zoom: 16 zoom: 16,
boundary: undefined,
}; };
this.handleClick = this.handleClick.bind(this); this.handleClick = this.handleClick.bind(this);
this.handleLocate = this.handleLocate.bind(this); this.handleLocate = this.handleLocate.bind(this);
@ -100,8 +101,20 @@ class ColouringMap extends Component<ColouringMapProps, ColouringMapState> { //
this.setState({theme: newTheme}); this.setState({theme: newTheme});
} }
async getBoundary() {
const res = await fetch('/geometries/boundary-detailed.geojson');
const data = await res.json() as GeoJsonObject;
this.setState({
boundary: data
});
}
componentDidMount() {
this.getBoundary();
}
render() { render() {
const position: LatLngExpression = [this.state.lat, this.state.lng]; const position: [number, number] = [this.state.lat, this.state.lng];
// baselayer // baselayer
const key = OS_API_KEY; const key = OS_API_KEY;
@ -117,6 +130,11 @@ class ColouringMap extends Component<ColouringMapProps, ColouringMapState> { //
const buildingsBaseUrl = `/tiles/base_${this.state.theme}/{z}/{x}/{y}{r}.png`; const buildingsBaseUrl = `/tiles/base_${this.state.theme}/{z}/{x}/{y}{r}.png`;
const buildingBaseLayer = <TileLayer url={buildingsBaseUrl} minZoom={14} />; const buildingBaseLayer = <TileLayer url={buildingsBaseUrl} minZoom={14} />;
const boundaryStyleFn = () => ({color: '#bbb', fill: false});
const boundaryLayer = this.state.boundary &&
<GeoJSON data={this.state.boundary} style={boundaryStyleFn}/>;
// colour-data tiles // colour-data tiles
const cat = this.props.category; const cat = this.props.category;
const tilesetByCat = { const tilesetByCat = {
@ -166,6 +184,7 @@ class ColouringMap extends Component<ColouringMapProps, ColouringMapState> { //
> >
{ baseLayer } { baseLayer }
{ buildingBaseLayer } { buildingBaseLayer }
{ boundaryLayer }
{ dataLayer } { dataLayer }
{ highlightLayer } { highlightLayer }
<ZoomControl position="topright" /> <ZoomControl position="topright" />