Skip to content

Commit

Permalink
Merge pull request #1000 from adamkendis/FRONT-map-open-requests-fix
Browse files Browse the repository at this point in the history
997 - RequestsLayer fix
  • Loading branch information
adamkendis authored Mar 5, 2021
2 parents f3733d5 + b0275a0 commit ee7168e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 44 deletions.
31 changes: 20 additions & 11 deletions client/components/Map/Map.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */

import React from 'react';
// import PropTypes from 'proptypes';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { withStyles } from '@material-ui/core/styles';
import mapboxgl from 'mapbox-gl';
Expand Down Expand Up @@ -36,7 +36,7 @@ import MapSearch from './controls/MapSearch';
// import MapRegion from './controls/MapRegion';
// import MapMeta from './controls/MapMeta';

// import RequestDetail from './RequestDetail';
import RequestDetail from './RequestDetail';

const styles = theme => ({
root: {
Expand All @@ -52,7 +52,6 @@ const styles = theme => ({
},
})

// TODO: major refactor, hooks
class Map extends React.Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -124,6 +123,13 @@ class Map extends React.Component {
}
}

// requestsLayer requires requestTypes for circle-color
if (this.props.requestTypes != prevProps.requestTypes) {
this.requestsLayer.init({
map: this.map,
});
}

if (
this.state.filterGeo !== prevState.filterGeo ||
this.state.selectedTypes !== prevState.selectedTypes
Expand All @@ -140,7 +146,7 @@ class Map extends React.Component {
this.setState({
locationInfo: {
nc: {
name: ncNameFromId(geo.properties.nc_id),
name: geo.properties.council_name,
// url removed from /geojson payload
// need to map from /councils response
// url: geo.properties.waddress || geo.properties.dwebsite,
Expand All @@ -163,10 +169,6 @@ class Map extends React.Component {
}

initLayers = addListeners => {
this.requestsLayer.init({
map: this.map,
});

this.addressLayer.init({
map: this.map,
addListeners,
Expand Down Expand Up @@ -421,6 +423,7 @@ class Map extends React.Component {
pinsInfo,
getPinInfo,
lastUpdated,
requestTypes,
} = this.props;

const {
Expand Down Expand Up @@ -448,6 +451,7 @@ class Map extends React.Component {
activeLayer={activeRequestsLayer}
selectedTypes={selectedTypes}
colorScheme={colorScheme}
requestTypes={requestTypes}
/>
<AddressLayer
ref={el => this.addressLayer = el}
Expand All @@ -464,9 +468,9 @@ class Map extends React.Component {
visible={geoFilterType === GEO_FILTER_TYPES.cc}
boundaryStyle={mapStyle === 'dark' ? 'light' : 'dark'}
/>
{/* <div ref={el => this.requestDetail = el}>
<div ref={el => this.requestDetail = el}>
<RequestDetail srnumber={selectedRequestId} />
</div> */}
</div>
{ this.state.mapReady && (
<>
{/* <MapOverview
Expand Down Expand Up @@ -502,12 +506,17 @@ class Map extends React.Component {
}
}

Map.propTypes = {};
Map.propTypes = {
requests: PropTypes.shape({}),
position: PropTypes.shape({}),
selectedTypes: PropTypes.arrayOf(PropTypes.number),
};

Map.defaultProps = {};

const mapStateToProps = state => ({
ncBoundaries: state.metadata.ncGeojson,
requestTypes: state.metadata.requestTypes,
});

export default connect(mapStateToProps, null)(withStyles(styles)(Map));
13 changes: 6 additions & 7 deletions client/components/Map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ class MapContainer extends React.Component {
if (prevProps.activeMode !== this.props.activeMode ||
prevProps.pins !== this.props.pins)
this.setData();

if (prevProps.requestTypes !== this.props.requestTypes)
this.setState({ selectedTypes: this.getSelectedTypes() });
}

getOpenRequests = async () => {
Expand Down Expand Up @@ -91,11 +88,13 @@ class MapContainer extends React.Component {
}))
});

// TODO: fix this
getSelectedTypes = () => {
const { requestTypes } = this.props;
return Object.keys(requestTypes).filter(type => {
return type !== 'All' && requestTypes[type]
});
// return Object.keys(requestTypes).filter(type => {
// return type !== 'All' && requestTypes[type]
// });
return requestTypes;
};

render() {
Expand Down Expand Up @@ -123,7 +122,7 @@ const mapStateToProps = state => ({
position: state.ui.map,
lastUpdated: state.metadata.lastPulledLocal,
activeMode: state.ui.map.activeMode,
requestTypes: state.mapFilters.requestTypes,
requestTypes: state.filters.requestTypes,
});

const mapDispatchToProps = dispatch => ({
Expand Down
50 changes: 24 additions & 26 deletions client/components/Map/layers/RequestsLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ import { getColors } from '../mapColors';
// so you don't cover up important labels
const BEFORE_ID = 'poi-label';

function circleColors(colorScheme) {
const colors = getColors(colorScheme);

const colorsArray = Object.keys(REQUEST_TYPES).reduce((p, c) => {
return [...p, c, colors[c]];
}, []);

function circleColors(requestTypes) {
const colors = [];
requestTypes.forEach(type => colors.push(type.typeId, type.color))
return [
'match',
['get', 'type'],
...colorsArray,
...colors,
'#FFFFFF',
];
}
Expand All @@ -46,6 +42,7 @@ class RequestsLayer extends React.Component {
selectedTypes,
requests,
colorScheme,
requestTypes
} = this.props;

if (activeLayer !== prev.activeLayer)
Expand All @@ -65,7 +62,7 @@ class RequestsLayer extends React.Component {
const { requests } = this.props;
this.map.addSource('requests', {
type: 'geojson',
data: requests
data: requests,
});
};

Expand All @@ -74,6 +71,7 @@ class RequestsLayer extends React.Component {
activeLayer,
selectedTypes,
colorScheme,
requestTypes,
} = this.props;

this.map.addLayer({
Expand All @@ -91,36 +89,36 @@ class RequestsLayer extends React.Component {
[15, 10]
],
},
'circle-color': circleColors(colorScheme),
'circle-color': circleColors(requestTypes),
'circle-opacity': 0.8,
},
filter: typeFilter(selectedTypes),
// filter: typeFilter(selectedTypes),
}, BEFORE_ID);

this.map.addLayer({
id: 'request-heatmap',
type: 'heatmap',
source: 'requests',
layout: {
visibility: activeLayer === 'heatmap' ? 'visible' : 'none',
},
paint: {
'heatmap-radius': 5,
},
filter: typeFilter(selectedTypes),
}, BEFORE_ID);
// this.map.addLayer({
// id: 'request-heatmap',
// type: 'heatmap',
// source: 'requests',
// layout: {
// visibility: activeLayer === 'heatmap' ? 'visible' : 'none',
// },
// paint: {
// 'heatmap-radius': 5,
// },
// filter: typeFilter(selectedTypes),
// }, BEFORE_ID);
};

setActiveLayer = activeLayer => {
switch(activeLayer) {
case 'points':
this.map.setLayoutProperty('request-circles', 'visibility', 'visible');
this.map.setLayoutProperty('request-heatmap', 'visibility', 'none');
// this.map.setLayoutProperty('request-heatmap', 'visibility', 'none');
break;

case 'heatmap':
this.map.setLayoutProperty('request-circles', 'visibility', 'none');
this.map.setLayoutProperty('request-heatmap', 'visibility', 'visible');
// this.map.setLayoutProperty('request-heatmap', 'visibility', 'visible');
break;

default:
Expand Down Expand Up @@ -154,7 +152,7 @@ export default RequestsLayer;

RequestsLayer.propTypes = {
activeLayer: PropTypes.oneOf(['points', 'heatmap']),
selectedTypes: PropTypes.arrayOf(PropTypes.string),
selectedTypes: PropTypes.arrayOf(PropTypes.number),
requests: PropTypes.shape({}),
colorScheme: PropTypes.string,
};
Expand Down

0 comments on commit ee7168e

Please sign in to comment.