From c895e05fb09b0708b162273a6fe0d2c324d745e8 Mon Sep 17 00:00:00 2001 From: Esko Ikkala <esko.ikkala@aalto.fi> Date: Fri, 17 Aug 2018 14:23:55 +0300 Subject: [PATCH] =?UTF-8?q?Add=20Kotus=20pit=C3=A4j=C3=A4t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/components/map/LeafletMap.js | 21 +++++++++++++++++---- src/client/containers/MapApp.js | 4 ++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/client/components/map/LeafletMap.js b/src/client/components/map/LeafletMap.js index b47e3e78..391353f5 100644 --- a/src/client/components/map/LeafletMap.js +++ b/src/client/components/map/LeafletMap.js @@ -27,6 +27,7 @@ const ColorIcon = L.Icon.extend({ class LeafletMap2 extends React.Component { componentDidMount() { + this.props.getGeoJSON(); // Base layers const OSMBaseLayer = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { @@ -50,7 +51,9 @@ class LeafletMap2 extends React.Component { // attribution: 'National Land Survey of Finland' // }); - // Overlay layers + //console.log(this.createNLSUrl('kiinteistojaotus')); + + // Overlays const realEstateMapNLS = L.tileLayer(this.createNLSUrl('kiinteistojaotus'), { attribution: 'National Land Survey of Finland' }); @@ -105,10 +108,10 @@ class LeafletMap2 extends React.Component { 'Senate atlas (MapWarper)': senateAtlas, 'Western Front July 1917 (MapWarper)': westernFront }; - L.control.layers(baseMaps, overlayMaps).addTo(this.map); + this.layerControl = L.control.layers(baseMaps, overlayMaps).addTo(this.map); } - componentDidUpdate({ results, mapMode }) { + componentDidUpdate({ results, mapMode, geoJSON }) { // check if results data or mapMode have changed if (this.props.results !== results || this.props.mapMode !== mapMode) { if (this.props.mapMode === 'cluster') { @@ -117,6 +120,10 @@ class LeafletMap2 extends React.Component { this.updateMarkers(this.props.results); } } + if (this.props.geoJSON !== geoJSON) { + const sockenMapKotus = L.geoJSON(this.props.geoJSON); + this.layerControl.addOverlay(sockenMapKotus, 'Kotus pitäjät'); + } } updateMarkers(results) { @@ -160,6 +167,9 @@ class LeafletMap2 extends React.Component { } createNLSUrl(layerID) { + // return 'https://avoin-karttakuva.maanmittauslaitos.fi/avoin/wmts/1.0.0/' + + // layerID + '/default/WGS84_Pseudo-Mercator/{z}/{x}/{y}.png'; + return 'https://avoin-karttakuva.maanmittauslaitos.fi/avoin/wmts?service=WMTS' + '&request=GetTile&version=1.0.0&layer=' + layerID + '&style=default' + '&format=image/png&TileMatrixSet=WGS84_Pseudo-Mercator&TileMatrix={z}&TileRow={y}&TileCol={x}'; @@ -172,7 +182,10 @@ class LeafletMap2 extends React.Component { LeafletMap2.propTypes = { results: PropTypes.array, - mapMode: PropTypes.string.isRequired + mapMode: PropTypes.string.isRequired, + geoJSON: PropTypes.object, + //geoJSONKey: PropTypes.number, + getGeoJSON: PropTypes.func.isRequired, }; export default LeafletMap2; diff --git a/src/client/containers/MapApp.js b/src/client/containers/MapApp.js index 121607e2..30c81f9a 100644 --- a/src/client/containers/MapApp.js +++ b/src/client/containers/MapApp.js @@ -170,9 +170,9 @@ let MapApp = (props) => { <LeafletMap results={props.results} mapMode={props.mapMode} - // geoJSON={props.geoJSON} + geoJSON={props.geoJSON} // geoJSONKey={props.geoJSONKey} - // getGeoJSON={props.getGeoJSON} + getGeoJSON={props.getGeoJSON} // sliderValue={100} /> ); -- GitLab