mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-30 23:40:33 +01:00
Merge pull request #213 from gregorywolanski/60
Clickable layer tooltips (#60)
This commit is contained in:
commit
3c0ebfabab
6 changed files with 16 additions and 11 deletions
|
@ -33,7 +33,7 @@
|
||||||
"lodash.isequal": "^4.5.0",
|
"lodash.isequal": "^4.5.0",
|
||||||
"lodash.throttle": "^4.1.1",
|
"lodash.throttle": "^4.1.1",
|
||||||
"mapbox-gl": "^0.43.0",
|
"mapbox-gl": "^0.43.0",
|
||||||
"mapbox-gl-inspect": "^1.2.4",
|
"mapbox-gl-inspect": "^1.2.5",
|
||||||
"maputnik-design": "github:maputnik/design",
|
"maputnik-design": "github:maputnik/design",
|
||||||
"mousetrap": "^1.6.1",
|
"mousetrap": "^1.6.1",
|
||||||
"ol-mapbox-style": "^1.0.1",
|
"ol-mapbox-style": "^1.0.1",
|
||||||
|
|
|
@ -249,7 +249,8 @@ export default class App extends React.Component {
|
||||||
} else {
|
} else {
|
||||||
return <MapboxGlMap {...mapProps}
|
return <MapboxGlMap {...mapProps}
|
||||||
inspectModeEnabled={this.state.inspectModeEnabled}
|
inspectModeEnabled={this.state.inspectModeEnabled}
|
||||||
highlightedLayer={this.state.mapStyle.layers[this.state.selectedLayerIndex]} />
|
highlightedLayer={this.state.mapStyle.layers[this.state.selectedLayerIndex]}
|
||||||
|
onLayerSelect={this.onLayerSelect.bind(this)} />
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,7 @@ class LayerListContainer extends React.Component {
|
||||||
const grp = <LayerListGroup
|
const grp = <LayerListGroup
|
||||||
key={[groupPrefix, idx].join('-')}
|
key={[groupPrefix, idx].join('-')}
|
||||||
title={groupPrefix}
|
title={groupPrefix}
|
||||||
isActive={!this.isCollapsed(groupPrefix, idx)}
|
isActive={!this.isCollapsed(groupPrefix, idx) || idx === this.props.selectedLayerIndex}
|
||||||
onActiveToggle={this.toggleLayerGroup.bind(this, groupPrefix, idx)}
|
onActiveToggle={this.toggleLayerGroup.bind(this, groupPrefix, idx)}
|
||||||
/>
|
/>
|
||||||
listItems.push(grp)
|
listItems.push(grp)
|
||||||
|
@ -172,9 +172,10 @@ class LayerListContainer extends React.Component {
|
||||||
|
|
||||||
layers.forEach((layer, idxInGroup) => {
|
layers.forEach((layer, idxInGroup) => {
|
||||||
const groupIdx = findClosestCommonPrefix(this.props.layers, idx)
|
const groupIdx = findClosestCommonPrefix(this.props.layers, idx)
|
||||||
|
|
||||||
const listItem = <LayerListItem
|
const listItem = <LayerListItem
|
||||||
className={classnames({
|
className={classnames({
|
||||||
'maputnik-layer-list-item-collapsed': layers.length > 1 && this.isCollapsed(groupPrefix, groupIdx),
|
'maputnik-layer-list-item-collapsed': layers.length > 1 && this.isCollapsed(groupPrefix, groupIdx) && idx !== this.props.selectedLayerIndex,
|
||||||
'maputnik-layer-list-item-group-last': idxInGroup == layers.length - 1 && layers.length > 1
|
'maputnik-layer-list-item-group-last': idxInGroup == layers.length - 1 && layers.length > 1
|
||||||
})}
|
})}
|
||||||
index={idx}
|
index={idx}
|
||||||
|
|
|
@ -29,6 +29,7 @@ function groupFeaturesBySourceLayer(features) {
|
||||||
|
|
||||||
class FeatureLayerPopup extends React.Component {
|
class FeatureLayerPopup extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
|
onLayerSelect: PropTypes.func.isRequired,
|
||||||
features: PropTypes.array
|
features: PropTypes.array
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +41,9 @@ class FeatureLayerPopup extends React.Component {
|
||||||
return <label
|
return <label
|
||||||
key={idx}
|
key={idx}
|
||||||
className="maputnik-popup-layer"
|
className="maputnik-popup-layer"
|
||||||
|
onClick={() => {
|
||||||
|
this.props.onLayerSelect(feature.layer.id)
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<LayerIcon type={feature.layer.type} style={{
|
<LayerIcon type={feature.layer.type} style={{
|
||||||
width: 14,
|
width: 14,
|
||||||
|
|
|
@ -15,12 +15,6 @@ import 'mapbox-gl/dist/mapbox-gl.css'
|
||||||
import '../../mapboxgl.css'
|
import '../../mapboxgl.css'
|
||||||
import '../../libs/mapbox-rtl'
|
import '../../libs/mapbox-rtl'
|
||||||
|
|
||||||
function renderLayerPopup(features) {
|
|
||||||
var mountNode = document.createElement('div');
|
|
||||||
ReactDOM.render(<FeatureLayerPopup features={features} />, mountNode)
|
|
||||||
return mountNode.innerHTML;
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderPropertyPopup(features) {
|
function renderPropertyPopup(features) {
|
||||||
var mountNode = document.createElement('div');
|
var mountNode = document.createElement('div');
|
||||||
ReactDOM.render(<FeaturePropertyPopup features={features} />, mountNode)
|
ReactDOM.render(<FeaturePropertyPopup features={features} />, mountNode)
|
||||||
|
@ -60,6 +54,7 @@ function buildInspectStyle(originalMapStyle, coloredLayers, highlightedLayer) {
|
||||||
export default class MapboxGlMap extends React.Component {
|
export default class MapboxGlMap extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
onDataChange: PropTypes.func,
|
onDataChange: PropTypes.func,
|
||||||
|
onLayerSelect: PropTypes.func.isRequired,
|
||||||
mapStyle: PropTypes.object.isRequired,
|
mapStyle: PropTypes.object.isRequired,
|
||||||
inspectModeEnabled: PropTypes.bool.isRequired,
|
inspectModeEnabled: PropTypes.bool.isRequired,
|
||||||
highlightedLayer: PropTypes.object,
|
highlightedLayer: PropTypes.object,
|
||||||
|
@ -68,6 +63,7 @@ export default class MapboxGlMap extends React.Component {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
onMapLoaded: () => {},
|
onMapLoaded: () => {},
|
||||||
onDataChange: () => {},
|
onDataChange: () => {},
|
||||||
|
onLayerSelect: () => {},
|
||||||
mapboxAccessToken: tokens.mapbox,
|
mapboxAccessToken: tokens.mapbox,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +129,9 @@ export default class MapboxGlMap extends React.Component {
|
||||||
if(this.props.inspectModeEnabled) {
|
if(this.props.inspectModeEnabled) {
|
||||||
return renderPropertyPopup(features)
|
return renderPropertyPopup(features)
|
||||||
} else {
|
} else {
|
||||||
return renderLayerPopup(features)
|
var mountNode = document.createElement('div');
|
||||||
|
ReactDOM.render(<FeatureLayerPopup features={features} onLayerSelect={this.props.onLayerSelect} />, mountNode)
|
||||||
|
return mountNode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
.maputnik-popup-layer {
|
.maputnik-popup-layer {
|
||||||
display: block;
|
display: block;
|
||||||
color: $color-lowgray;
|
color: $color-lowgray;
|
||||||
|
cursor: pointer;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
line-height: 1.2;
|
line-height: 1.2;
|
||||||
padding: $margin-2;
|
padding: $margin-2;
|
||||||
|
|
Loading…
Reference in a new issue