diff --git a/src/client/components/facet_results/LeafletMap.js b/src/client/components/facet_results/LeafletMap.js index c797504475a256b5f92bfd318b4fc777aced2aab..d4318ae523b0dda65d041554bbadb7e02b95c877 100644 --- a/src/client/components/facet_results/LeafletMap.js +++ b/src/client/components/facet_results/LeafletMap.js @@ -4,6 +4,7 @@ import { withStyles } from '@material-ui/core/styles' import intl from 'react-intl-universal' import L from 'leaflet' import { has, orderBy, isEqual } from 'lodash' +// import buffer from '@turf/buffer' import CircularProgress from '@material-ui/core/CircularProgress' import { purple } from '@material-ui/core/colors' import history from '../../History' @@ -94,7 +95,7 @@ class LeafletMap extends React.Component { constructor (props) { super(props) this.state = { - activeOverlays: [], + activeOverlays: props.activeOverlays ? props.activeOverlays : [], prevZoomLevel: null, mapMode: props.mapMode } @@ -116,6 +117,12 @@ class LeafletMap extends React.Component { } if (this.props.showExternalLayers) { this.props.clearGeoJSONLayers() + if (this.state.activeOverlays.length > 0 && this.isSafeToLoadLargeLayers()) { + this.props.fetchGeoJSONLayers({ + layerIDs: this.state.activeOverlays, + bounds: this.leafletMap.getBounds() + }) + } } } @@ -356,84 +363,94 @@ class LeafletMap extends React.Component { }) } - isSafeToLoadLargeLayersAfterZooming = () => true - // { - // return (this.leafletMap.getZoom() === 13 || - // (this.leafletMap.getZoom() >= 13 && this.state.prevZoomLevel > this.leafletMap.getZoom())) - // } + isSafeToLoadLargeLayersAfterZooming = () => { + return (this.leafletMap.getZoom() === 13 || + (this.leafletMap.getZoom() >= 13 && this.state.prevZoomLevel > this.leafletMap.getZoom())) + } - isSafeToLoadLargeLayers = () => true - // this.leafletMap.getZoom() >= 13 + isSafeToLoadLargeLayers = () => this.leafletMap.getZoom() >= 13 initOverLays = basemaps => { - // const fhaArchaeologicalSiteRegistryAreas = L.layerGroup([], { - // id: 'arkeologiset_kohteet_alue', + const fhaArchaeologicalSiteRegistryAreas = L.layerGroup([], { + id: 'arkeologiset_kohteet_alue', + type: 'geoJSON', + source: 'FHA', + // this layer includes only GeoJSON Polygons, define style for them + geoJSONPolygonOptions: { + color: '#dd2c00', + cursor: 'pointer' + // dashArray: '3, 5' + }, + geoJSONPolygonBoundaryOptions: { + color: '#dd2c00', + // cursor: 'pointer', + dashArray: '3, 5' + } + }) + const fhaArchaeologicalSiteRegistryPoints = L.layerGroup([], { + id: 'arkeologiset_kohteet_piste', + type: 'geoJSON', + source: 'FHA', + // this layer includes only GeoJSON points, define style for them + geoJSONMarkerOptions: { + radius: 8, + fillColor: '#dd2c00', + weight: 1, + opacity: 1, + fillOpacity: 0.8 + } + }) + // const fhaLidar = L.tileLayer.wms(`${process.env.API_URL}/fha-wms`, { + // layers: 'NBA:lidar', + // version: '1.3.0', + // attribution: 'FHA', + // minZoom: 12, + // maxZoom: 16 + // }) + // const kotusParishes1938 = L.layerGroup([], { + // id: 'kotus:pitajat', // type: 'geoJSON', - // source: 'FHA', + // source: 'kotus', // // this layer includes only GeoJSON Polygons, define style for them - // geojsonMPolygonOptions: { + // geoJSONPolygonOptions: { // color: '#dd2c00', // cursor: 'pointer', // dashArray: '3, 5' // } // }) - // const fhaArchaeologicalSiteRegistryPoints = L.layerGroup([], { - // id: 'arkeologiset_kohteet_piste', + // const kotusParishesDialecticalRegions = L.layerGroup([], { + // id: 'kotus:rajat-sms-alueet', // type: 'geoJSON', - // source: 'FHA', - // // this layer includes only GeoJSON points, define style for them - // geojsonMarkerOptions: { - // radius: 8, - // fillColor: '#dd2c00', - // weight: 1, - // opacity: 1, - // fillOpacity: 0.8 + // source: 'kotus', + // // this layer includes only GeoJSON Polygons, define style for them + // geoJSONPolygonOptions: { + // color: '#fca903', + // cursor: 'pointer', + // dashArray: '3, 5' + // } + // }) + // const kotusParishesDialecticalSubRegions = L.layerGroup([], { + // id: 'kotus:rajat-sms-alueosat', + // type: 'geoJSON', + // source: 'kotus', + // // this layer includes only GeoJSON Polygons, define style for them + // geoJSONPolygonOptions: { + // color: '#119100', + // cursor: 'pointer', + // dashArray: '3, 5' + // } + // }) + // const kotusParishesDialecticalBorder = L.layerGroup([], { + // id: 'kotus:rajat-lansi-ita', + // type: 'geoJSON', + // source: 'kotus', + // // this layer includes only GeoJSON Polygons, define style for them + // geoJSONPolygonOptions: { + // color: '#2403fc', + // cursor: 'pointer', + // dashArray: '3, 5' // } // }) - const kotusParishes1938 = L.layerGroup([], { - id: 'kotus:pitajat', - type: 'geoJSON', - source: 'kotus', - // this layer includes only GeoJSON Polygons, define style for them - geojsonMPolygonOptions: { - color: '#dd2c00', - cursor: 'pointer', - dashArray: '3, 5' - } - }) - const kotusParishesDialecticalRegions = L.layerGroup([], { - id: 'kotus:rajat-sms-alueet', - type: 'geoJSON', - source: 'kotus', - // this layer includes only GeoJSON Polygons, define style for them - geojsonMPolygonOptions: { - color: '#fca903', - cursor: 'pointer', - dashArray: '3, 5' - } - }) - const kotusParishesDialecticalSubRegions = L.layerGroup([], { - id: 'kotus:rajat-sms-alueosat', - type: 'geoJSON', - source: 'kotus', - // this layer includes only GeoJSON Polygons, define style for them - geojsonMPolygonOptions: { - color: '#119100', - cursor: 'pointer', - dashArray: '3, 5' - } - }) - const kotusParishesDialecticalBorder = L.layerGroup([], { - id: 'kotus:rajat-lansi-ita', - type: 'geoJSON', - source: 'kotus', - // this layer includes only GeoJSON Polygons, define style for them - geojsonMPolygonOptions: { - color: '#2403fc', - cursor: 'pointer', - dashArray: '3, 5' - } - }) const karelianMaps = L.tileLayer('https:///mapwarper.onki.fi/mosaics/tile/4/{z}/{x}/{y}.png', { type: 'tile', attribution: 'SeCo' @@ -443,16 +460,24 @@ class LeafletMap extends React.Component { attribution: 'SeCo' }) this.overlayLayers = { - // [intl.get('leafletMap.externalLayers.arkeologiset_kohteet_alue')]: fhaArchaeologicalSiteRegistryAreas, - // [intl.get('leafletMap.externalLayers.arkeologiset_kohteet_piste')]: fhaArchaeologicalSiteRegistryPoints, + [intl.get('leafletMap.externalLayers.arkeologiset_kohteet_alue')]: fhaArchaeologicalSiteRegistryAreas, + [intl.get('leafletMap.externalLayers.arkeologiset_kohteet_piste')]: fhaArchaeologicalSiteRegistryPoints, + // [intl.get('leafletMap.externalLayers.fhaLidar')]: fhaLidar, [intl.get('leafletMap.externalLayers.karelianMaps')]: karelianMaps, - [intl.get('leafletMap.externalLayers.senateAtlas')]: senateAtlas, - [intl.get('leafletMap.externalLayers.kotus:pitajat')]: kotusParishes1938, - [intl.get('leafletMap.externalLayers.kotus:rajat-sms-alueet')]: kotusParishesDialecticalRegions, - [intl.get('leafletMap.externalLayers.kotus:rajat-sms-alueosat')]: kotusParishesDialecticalSubRegions, - [intl.get('leafletMap.externalLayers.kotus:rajat-lansi-ita')]: kotusParishesDialecticalBorder + [intl.get('leafletMap.externalLayers.senateAtlas')]: senateAtlas + // [intl.get('leafletMap.externalLayers.kotus:pitajat')]: kotusParishes1938, + // [intl.get('leafletMap.externalLayers.kotus:rajat-sms-alueet')]: kotusParishesDialecticalRegions, + // [intl.get('leafletMap.externalLayers.kotus:rajat-sms-alueosat')]: kotusParishesDialecticalSubRegions, + // [intl.get('leafletMap.externalLayers.kotus:rajat-lansi-ita')]: kotusParishesDialecticalBorder } - L.control.layers(basemaps, this.overlayLayers).addTo(this.leafletMap) + + // Add default active overlays directly to the map + this.state.activeOverlays.map(overlay => + this.leafletMap.addLayer(this.overlayLayers[intl.get(`leafletMap.externalLayers.${overlay}`)])) + + // Add all basemaps and all overlays via the control to the map + L.control.layers(basemaps, this.overlayLayers, { collapsed: !this.props.layerControlExpanded }).addTo(this.leafletMap) + const opacityLayers = { [intl.get('leafletMap.externalLayers.karelianMaps')]: karelianMaps, [intl.get('leafletMap.externalLayers.senateAtlas')]: senateAtlas @@ -466,19 +491,38 @@ class LeafletMap extends React.Component { The baseLayers and overlays parameters are object literals with layer names as keys and Layer objects as values */ + + // console.log(layerObj.geoJSON) + // const bufferedGeoJSON = buffer(layerObj.geoJSON, 0.2, { units: 'kilometres' }) + // const bufferedGeoJSON = transformScale(layerObj.geoJSON, 0.3) + // console.log(bufferedGeoJSON) const leafletOverlay = this.overlayLayers[intl.get(`leafletMap.externalLayers.${layerObj.layerID}`)] + leafletOverlay.clearLayers() const leafletGeoJSONLayer = L.geoJSON(layerObj.geoJSON, { // style for GeoJSON Points pointToLayer: (feature, latlng) => { return L.circleMarker(latlng, leafletOverlay.options.geojsonMarkerOptions) }, // style for GeoJSON Polygons - style: leafletOverlay.options.geojsonMPolygonOptions, + style: leafletOverlay.options.geoJSONPolygonOptions, // add popups onEachFeature: (feature, layer) => { layer.bindPopup(this.createPopUpContentGeoJSON(layerObj.layerID, feature.properties)) } }) + // const leafletGeoJSONBoundaryLayer = L.geoJSON(bufferedGeoJSON, { + // // style for GeoJSON Points + // pointToLayer: (feature, latlng) => { + // return L.circleMarker(latlng, leafletOverlay.options.geojsonMarkerOptions) + // }, + // // style for GeoJSON Polygons + // style: leafletOverlay.options.geoJSONPolygonBoundaryOptions + // // add popups + // // onEachFeature: (feature, layer) => { + // // layer.bindPopup(this.createPopUpContentGeoJSON(layerObj.layerID, feature.properties)) + // // } + // }) + // leafletGeoJSONBoundaryLayer.addTo(leafletOverlay).addTo(this.leafletMap) leafletGeoJSONLayer.addTo(leafletOverlay).addTo(this.leafletMap) } @@ -817,7 +861,7 @@ class LeafletMap extends React.Component { const container = document.createElement('div') const heading = document.createElement('h3') const headingLink = document.createElement('a') - headingLink.href = '' + headingLink.style.cssText = 'cursor: pointer; text-decoration: underline' headingLink.textContent = data.prefLabel.prefLabel headingLink.addEventListener('click', () => history.push(data.dataProviderUrl)) heading.appendChild(headingLink) diff --git a/src/client/components/perspectives/sampo/Perspective1.js b/src/client/components/perspectives/sampo/Perspective1.js index 9dc59d6890b82ec45c41fc3066d19731c6a3138f..cf196ff608b04ae9afa1f0d7f26cc7e3984fb95c 100644 --- a/src/client/components/perspectives/sampo/Perspective1.js +++ b/src/client/components/perspectives/sampo/Perspective1.js @@ -65,7 +65,7 @@ const Perspective1 = props => { showMapModeControl={false} instance={props.placesResults.instanceTableData} fetchResults={props.fetchResults} - fetchGeoJSONLayers={props.fetchGeoJSONLayersBackend} + fetchGeoJSONLayers={props.fetchGeoJSONLayers} clearGeoJSONLayers={props.clearGeoJSONLayers} fetchByURI={props.fetchByURI} fetching={props.placesResults.fetching} @@ -108,7 +108,7 @@ const Perspective1 = props => { showMapModeControl={false} instance={props.placesResults.instanceTableData} fetchResults={props.fetchResults} - fetchGeoJSONLayers={props.fetchGeoJSONLayersBackend} + fetchGeoJSONLayers={props.fetchGeoJSONLayers} clearGeoJSONLayers={props.clearGeoJSONLayers} fetchByURI={props.fetchByURI} fetching={props.placesResults.fetching} diff --git a/src/client/translations/sampo/localeEN.js b/src/client/translations/sampo/localeEN.js index d5f88b03050cde442707ed001b20d7e65c6e795a..9b0beb37d8ceae94991b305076da6b4aa9d220cb 100644 --- a/src/client/translations/sampo/localeEN.js +++ b/src/client/translations/sampo/localeEN.js @@ -151,8 +151,9 @@ export default { backgroundMapNLS: 'Background map (National Land Survey of Finland)' }, externalLayers: { - arkeologiset_kohteet_alue: 'Register of Archaeological Sites, areas', - arkeologiset_kohteet_piste: 'Register of Archaeological Sites, points', + arkeologiset_kohteet_alue: 'Register of Archaeological Sites, areas (Finnish Heritage Agency)', + arkeologiset_kohteet_piste: 'Register of Archaeological Sites, points (Finnish Heritage Agency)', + fhaLidar: 'Elevation model (Finnish Heritage Agency)', karelianMaps: 'Karelian maps, 1:100 000 topographic (SeCo)', senateAtlas: 'Senate atlas, 1:21 000 topographic (SeCo)', 'kotus:pitajat': 'Finnish parishes in 1938 (Institute for the Languages of Finland)',