Skip to content

Commit

Permalink
Updated map
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed May 21, 2021
1 parent 8d5b064 commit 66b1242
Show file tree
Hide file tree
Showing 12 changed files with 1,459 additions and 49 deletions.
3 changes: 3 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
],
"@eeacms/volto-tabs-block": [
"addons/volto-tabs-block/src"
],
"@eeacms/volto-openlayers-map": [
"addons/volto-openlayers-map/src"
]
},
"baseUrl": "src"
Expand Down
6 changes: 6 additions & 0 deletions mrs.developer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
"package": "@eeacms/volto-tabs-block",
"branch": "master",
"develop": true
},
"volto-openlayers-map": {
"url": "https://github.com/eea/volto-openlayers-map.git",
"path": "src",
"package": "@eeacms/volto-openlayers-map",
"develop": true
}
}

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"volto-datablocks",
"volto-embed",
"volto-addons",
"@eeacms/volto-openlayers-map",
"@eeacms/volto-tableau",
"@eeacms/volto-block-style",
"@eeacms/volto-tabs-block"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const OpenlayersMapView = (props) => {
Control = require('ol/control/Control.js').default;
defaultsControls = require('ol/control.js').defaults;
defaultsInteractions = require('ol/interaction.js').defaults;
olExtent = require('ol/extent.js').defaults;
olExtent = require('ol/extent.js');
OL_LOADED = true;
}

Expand Down Expand Up @@ -925,7 +925,7 @@ const OpenlayersMapView = (props) => {
},
strategy: function (extent, resolution) {
const tileGrid = createXYZ({
tileSize: 512,
tileSize: 256,
});
let z = tileGrid.getZForResolution(resolution);
let tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z);
Expand Down
73 changes: 55 additions & 18 deletions src/components/manage/Blocks/FiltersBlock/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -936,34 +936,65 @@ const View = ({ content, ...props }) => {
: props.discodata_query.search['extent'],
advancedFiltering,
...(!search
? {}
? {
locationTerm: null,
siteTerm: null,
}
: {
siteCountry: [],
province: [],
region: [],
riverBasin: [],
nuts_regions: [],
nuts_latest: [],
EEAActivity: [null],
siteCountry: [null],
nuts_latest: [null],
nuts_regions: [null],
province: [null],
region: [null],
riverBasin: [null],
pollutantGroup: [null],
pollutant: [null],
plantTypes: [null],
batConclusionCode: [null],
permitType: [null],
permitYear: [null],
}),
},
});

const newFiltersMeta = { ...state.filtersMeta };
const newFilters = { ...state.filters };

if (search) {
Object.keys(state.filtersMeta).forEach((key) => {
if (key !== 'reporting_years') {
newFiltersMeta[key].filteringInputs = [
{
id: _uniqueId('select_'),
type: 'select',
position: 0,
},
];
}
});

Object.keys(state.filters).forEach((key) => {
if (key !== 'reportingYear') {
newFilters[key] = [null];
}
});
}

setState({
...state,
open: false,
filters: {
...state.filters,
...(!search
? {}
: {
siteCountry: [null],
province: [null],
region: [null],
riverBasin: [null],
nuts_regions: [null],
nuts_latest: [null],
}),
...newFilters,
},
filtersMeta: {
...newFiltersMeta,
},
});

if (!search) {
setSearchTerm('');
}
};

const getNewExtent = (searchTerm) => {
Expand Down Expand Up @@ -1362,6 +1393,8 @@ const View = ({ content, ...props }) => {
);
props.setQueryParam({
queryParam: {
locationTerm: null,
siteTerm: null,
advancedFiltering: true,
filtersCounter: props.discodata_query.search[
'filtersCounter'
Expand All @@ -1372,6 +1405,7 @@ const View = ({ content, ...props }) => {
: 1,
},
});
setSearchTerm('');
}}
placeholder={
state.filtersMeta['reporting_years']?.placeholder
Expand Down Expand Up @@ -1443,6 +1477,8 @@ const View = ({ content, ...props }) => {
);
props.setQueryParam({
queryParam: {
locationTerm: null,
siteTerm: null,
advancedFiltering: true,
filtersCounter: props.discodata_query.search[
'filtersCounter'
Expand All @@ -1453,6 +1489,7 @@ const View = ({ content, ...props }) => {
: 1,
},
});
setSearchTerm('');
}}
placeholder={
state.filtersMeta['industries']?.placeholder
Expand Down
32 changes: 32 additions & 0 deletions src/components/manage/Blocks/SiteLocationMap/Edit.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { SidebarPortal } from '@plone/volto/components';
import InlineForm from '@plone/volto/components/manage/Form/InlineForm';
import SiteLocationMapView from './View';
import schema from './schema';
import { connectBlockToProviderData } from 'volto-datablocks/hocs';

const Edit = (props) => {
const { data = {}, block = null, selected = false, onChangeBlock } = props;

return (
<>
<SiteLocationMapView {...props} mode="edit" />

<SidebarPortal selected={selected}>
<InlineForm
schema={schema}
title={schema.title}
onChangeField={(id, value) => {
onChangeBlock(block, {
...data,
[id]: value,
});
}}
formData={data}
/>
</SidebarPortal>
</>
);
};

export default connectBlockToProviderData(Edit);
105 changes: 105 additions & 0 deletions src/components/manage/Blocks/SiteLocationMap/View.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import React, { useState } from 'react';
import { connect } from 'react-redux';
import Map from '@eeacms/volto-openlayers-map/Map';
import { Interactions } from '@eeacms/volto-openlayers-map/Interactions';
import { Controls } from '@eeacms/volto-openlayers-map/Controls';
import { Layers, Layer } from '@eeacms/volto-openlayers-map/Layers';
import { openlayers } from '@eeacms/volto-openlayers-map';
import { getSiteLocationURL } from './index';
import qs from 'querystring';
import './style.css';

const View = (props) => {
const [options, setOptions] = React.useState({});
const [vectorSource, setVectorSource] = useState(null);
const { format, proj, source, style } = openlayers;
const { siteInspireId } = { ...props.query, ...props.discodata_query };

React.useState(() => {
if (__SERVER__) return;
const vs = vectorSource || new source.Vector();
if (!vectorSource) {
setVectorSource(vs);
}
if (!siteInspireId) return;
const esrijsonFormat = new format.EsriJSON();
// Get site feature
const url = getSiteLocationURL(siteInspireId);
fetch(url).then(function (response) {
if (response.status !== 200) return;
response.json().then(function (data) {
const features = esrijsonFormat.readFeatures(data);
if (features.length > 0) {
vs.addFeatures(features);
setOptions({
...options,
extent: features[0].getGeometry().getExtent(),
});
}
});
});
}, [siteInspireId]);

if (__SERVER__ || !vectorSource) return '';

const siteStyle = new style.Style({
image: new style.Circle({
radius: 3,
fill: new style.Fill({ color: '#00FF00' }),
stroke: new style.Stroke({ color: '#6A6A6A', width: 1 }),
zIndex: 0,
}),
});

return (
<div className="site-location-map-wrapper full-width">
<div className="site-location-map full-width">
<Map
view={{
center: proj.fromLonLat([20, 50]),
showFullExtent: true,
maxZoom: 12,
minZoom: 12,
zoom: 12,
}}
renderer="webgl"
{...options}
>
<Layers>
<Layer.Tile
source={
new source.XYZ({
url:
'https://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer/tile/{z}/{y}/{x}',
})
}
zIndex={0}
/>
<Layer.VectorImage
source={vectorSource}
style={siteStyle}
title="1.Sites"
zIndex={1}
/>
</Layers>
<Controls attribution={false} zoom={false} />
<Interactions
doubleClickZoom={false}
dragAndDrop={false}
dragPan={false}
keyboardPan={false}
keyboardZoom={false}
mouseWheelZoom={false}
pointer={false}
select={false}
/>
</Map>
</div>
</div>
);
};

export default connect((state) => ({
query: qs.parse(state.router.location.search.replace('?', '')),
discodata_query: state.discodata_query.search,
}))(View);
28 changes: 28 additions & 0 deletions src/components/manage/Blocks/SiteLocationMap/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sliderSVG from '@plone/volto/icons/slider.svg';
import { getEncodedString } from '~/utils';
import SiteLocationMapEdit from './Edit';
import SiteLocationMapView from './View';

export const getSiteLocationURL = (siteInspireId) => {
const condition = `(InspireSiteId LIKE '${getEncodedString(siteInspireId)}')`;
return `https://air.discomap.eea.europa.eu/arcgis/rest/services/Air/IED_SiteMap/FeatureServer/0/query?f=json&where=${condition}&returnGeometry=true&spatialRel=esriSpatialRelIntersects&outFields=InspireSiteId&outSR=102100`;
};

export default (config) => {
config.blocks.blocksConfig.site_location = {
id: 'site_location',
title: 'Site location',
icon: sliderSVG,
group: 'eprtr_blocks',
edit: SiteLocationMapEdit,
view: SiteLocationMapView,
restricted: false,
mostUsed: false,
sidebarTab: 1,
security: {
addPermission: [],
view: [],
},
};
return config;
};
17 changes: 17 additions & 0 deletions src/components/manage/Blocks/SiteLocationMap/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const schema = {
title: 'Site location',

fieldsets: [
{
id: 'default',
title: 'Default',
fields: [],
},
],

properties: {},

required: [],
};

export default schema;
19 changes: 19 additions & 0 deletions src/components/manage/Blocks/SiteLocationMap/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
div#view .ui.container > .site-location-map-wrapper,
div#view .ui.container > .site-location-map {
margin-bottom: 0;
}

.site-location-map {
display: flex;
justify-content: center;
margin-bottom: 1rem;
}

.site-location-map.visible.transition {
display: flex !important;
}

.site-location-map .ol-map {
height: 400px;
min-height: 400px;
}
2 changes: 2 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ import ListView from '~/components/manage/Blocks/DiscodataComponents/List/View';
import BlocksWidget from '~/components/manage/Widgets/BlocksWidget';
import QueryParametersListWidget from '~/components/manage/Blocks/DiscodataComponents/Widgets/QueryParametersListWidget';

import installSiteLocationMap from '~/components/manage/Blocks/SiteLocationMap';
import installSiteTableau from '~/components/manage/Blocks/SiteTableau';
import installSiteStructureSidebar from '~/components/manage/Blocks/SiteStructureSidebar';
import installSiteHeader from '~/components/manage/Blocks/SiteBlocks/Header';
Expand Down Expand Up @@ -380,6 +381,7 @@ export default function applyConfig(config) {
];

return [
installSiteLocationMap,
installSiteTableau,
installSiteStructureSidebar,
installSiteHeader,
Expand Down
Loading

0 comments on commit 66b1242

Please sign in to comment.