Skip to content

Commit

Permalink
Merge pull request #315 from orangemug/feature/option-to-display-tile…
Browse files Browse the repository at this point in the history
…-boundaries

Added option to display tile boundaries
  • Loading branch information
orangemug committed Jun 3, 2018
2 parents a28a417 + cd28a53 commit 7a7f2eb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/components/App.jsx
Expand Up @@ -31,6 +31,7 @@ import LayerWatcher from '../libs/layerwatcher'
import tokens from '../config/tokens.json'
import isEqual from 'lodash.isequal'
import Debug from '../libs/debug'
import queryUtil from '../libs/query-util'

import MapboxGl from 'mapbox-gl'
import mapboxUtil from 'mapbox-gl/src/util/mapbox'
Expand Down Expand Up @@ -172,6 +173,9 @@ export default class App extends React.Component {
shortcuts: false,
export: false,
},
mapOptions: {
showTileBoundaries: queryUtil.asBool(queryObj, "show-tile-boundaries")
},
mapFilter: queryObj["color-blindness-emulation"],
}

Expand Down Expand Up @@ -402,6 +406,7 @@ export default class App extends React.Component {
mapRenderer() {
const mapProps = {
mapStyle: style.replaceAccessToken(this.state.mapStyle, {allowFallback: true}),
options: this.state.mapOptions,
onDataChange: (e) => {
this.layerWatcher.analyzeMap(e.map)
this.fetchSources();
Expand Down Expand Up @@ -502,13 +507,13 @@ export default class App extends React.Component {
/>
<SettingsModal
mapStyle={this.state.mapStyle}
onStyleChanged={this.onStyleChanged}
onStyleChanged={this.onStyleChanged.bind(this)}
isOpen={this.state.isOpen.settings}
onOpenToggle={this.toggleModal.bind(this, 'settings')}
/>
<ExportModal
mapStyle={this.state.mapStyle}
onStyleChanged={this.onStyleChanged}
onStyleChanged={this.onStyleChanged.bind(this)}
isOpen={this.state.isOpen.export}
onOpenToggle={this.toggleModal.bind(this, 'export')}
/>
Expand All @@ -519,7 +524,7 @@ export default class App extends React.Component {
/>
<SourcesModal
mapStyle={this.state.mapStyle}
onStyleChanged={this.onStyleChanged}
onStyleChanged={this.onStyleChanged.bind(this)}
isOpen={this.state.isOpen.sources}
onOpenToggle={this.toggleModal.bind(this, 'sources')}
/>
Expand Down
14 changes: 12 additions & 2 deletions src/components/map/MapboxGlMap.jsx
Expand Up @@ -58,6 +58,7 @@ export default class MapboxGlMap extends React.Component {
mapStyle: PropTypes.object.isRequired,
inspectModeEnabled: PropTypes.bool.isRequired,
highlightedLayer: PropTypes.object,
options: PropTypes.object,
}

static defaultProps = {
Expand Down Expand Up @@ -92,20 +93,29 @@ export default class MapboxGlMap extends React.Component {
}

componentDidUpdate(prevProps) {
const map = this.state.map;

if(this.props.inspectModeEnabled !== prevProps.inspectModeEnabled) {
this.state.inspect.toggleInspector()
}
if(this.props.inspectModeEnabled) {
this.state.inspect.render()
}

map.showTileBoundaries = this.props.options.showTileBoundaries;
}

componentDidMount() {
const map = new MapboxGl.Map({
const mapOpts = {
...this.props.options,
container: this.container,
style: this.props.mapStyle,
hash: true,
})
}

const map = new MapboxGl.Map(mapOpts);

map.showTileBoundaries = mapOpts.showTileBoundaries;

const zoom = new ZoomControl;
map.addControl(zoom, 'top-right');
Expand Down
17 changes: 17 additions & 0 deletions src/libs/query-util.js
@@ -0,0 +1,17 @@
function asBool(queryObj, key) {
if(queryObj.hasOwnProperty(key)) {
if(queryObj[key].match(/^false|0$/)) {
return false;
}
else {
return true;
}
}
else {
return false;
}
}

module.exports = {
asBool
}

0 comments on commit 7a7f2eb

Please sign in to comment.