Skip to content

Commit

Permalink
Toggle striped regions
Browse files Browse the repository at this point in the history
  • Loading branch information
thawsitt committed Mar 14, 2019
1 parent 32201f3 commit 99df252
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 18 deletions.
9 changes: 6 additions & 3 deletions src/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class LocalLegislationMap extends Component {
recordsModalOpen: false,
searchResults: null,
showBaseMap: true,
showStripedRegions: true,
};
this.mapRef = React.createRef();
}
Expand All @@ -40,9 +41,9 @@ class LocalLegislationMap extends Component {
});
};

toggleBaseMap = (showBaseMap) => {
toggleCheckBox = (key, isChecked) => {
this.setState({
showBaseMap: showBaseMap,
[key]: isChecked,
});
};

Expand Down Expand Up @@ -74,8 +75,9 @@ class LocalLegislationMap extends Component {
<InfoPanel info={this.state.info} />
<ControlPanel
changeColorScheme={this.changeColorScheme}
toggleBaseMap={this.toggleBaseMap}
toggleCheckBox={this.toggleCheckBox}
showBaseMap={this.state.showBaseMap}
showStripedRegions={this.state.showStripedRegions}
/>
<ColorLegend
mappingData={this.props.mappingData}
Expand Down Expand Up @@ -105,6 +107,7 @@ class LocalLegislationMap extends Component {
mappingData={this.props.mappingData}
maxNumEntries={maxNumEntries}
showRecordsModal={this.showRecordsModal}
showStripedRegions={this.state.showStripedRegions}
/>
</LeafletMap>
</div>
Expand Down
12 changes: 11 additions & 1 deletion src/components/ControlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,17 @@ class ControlPanel extends Component {
<Checkbox
label="World map"
checked={this.props.showBaseMap}
onChange={(e, data) => this.props.toggleBaseMap(data.checked)}
onChange={(e, data) =>
this.props.toggleCheckBox('showBaseMap', data.checked)
}
/>
<br />
<Checkbox
label="Striped regions"
checked={this.props.showStripedRegions}
onChange={(e, data) =>
this.props.toggleCheckBox('showStripedRegions', data.checked)
}
/>
</Card.Content>
</Card>
Expand Down
35 changes: 22 additions & 13 deletions src/components/GeoJSONLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class GeoJSONLayer extends Component {

return {
fillColor: '#fff',
fillOpacity: 0.8,
fillOpacity: this.props.showStripedRegions ? 0.8 : 0,
weight: 0,
fillPattern: Patterns.StripePattern({
color: '#fff',
Expand Down Expand Up @@ -111,20 +111,29 @@ class GeoJSONLayer extends Component {

highlightFeature = (e) => {
const layer = e.target;
const info = this.getDioceseData(layer);
this.props.updateInfo(info);
let weight = 0.5;
let dashArray = '3';
if (_inDatabase(layer.feature) || this.props.showStripedRegions) {
const info = this.getDioceseData(layer);
this.props.updateInfo(info);
}

let style;
if (_inDatabase(layer.feature)) {
weight = 2.0;
dashArray = '';
style = {
weight: 2,
color: 'black',
dashArray: '',
fillOpacity: 1.0,
};
} else {
style = {
weight: this.props.showStripedRegions ? 0.5 : 0,
color: 'black',
dashArray: '3',
fillOpacity: this.props.showStripedRegions ? 1.0 : 0,
};
}
layer.setStyle({
weight: weight,
color: 'black',
dashArray: dashArray,
fillOpacity: 1.0,
});

layer.setStyle(style);
layer.bringToFront();
};

Expand Down
2 changes: 1 addition & 1 deletion src/styles/Map.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}

.panel.panel-info {
margin-top: 160px !important;
margin-top: 170px !important;
}

.panel-left {
Expand Down

0 comments on commit 99df252

Please sign in to comment.