mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-28 17:31:14 +01:00
Show layer table
This commit is contained in:
parent
0c483cffe3
commit
8f561d8a27
2 changed files with 46 additions and 0 deletions
20
src/components/map/FeatureLayerTable.jsx
Normal file
20
src/components/map/FeatureLayerTable.jsx
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
class FeatureLayerTable extends React.Component {
|
||||||
|
render() {
|
||||||
|
const feature = this.props.feature
|
||||||
|
const rows = <tr>
|
||||||
|
<td className="debug-prop-key">{feature.layer.id}</td>
|
||||||
|
</tr>
|
||||||
|
return <table
|
||||||
|
style={{
|
||||||
|
color: 'black',
|
||||||
|
}}
|
||||||
|
className="debug-props">
|
||||||
|
<tbody>{rows}</tbody>
|
||||||
|
</table>;;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default FeatureLayerTable
|
|
@ -1,9 +1,17 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import ReactDOM from 'react-dom'
|
||||||
import MapboxGl from 'mapbox-gl'
|
import MapboxGl from 'mapbox-gl'
|
||||||
|
import FeatureLayerTable from './FeatureLayerTable'
|
||||||
import validateColor from 'mapbox-gl-style-spec/lib/validate/validate_color'
|
import validateColor from 'mapbox-gl-style-spec/lib/validate/validate_color'
|
||||||
import style from '../../libs/style.js'
|
import style from '../../libs/style.js'
|
||||||
import 'mapbox-gl/dist/mapbox-gl.css'
|
import 'mapbox-gl/dist/mapbox-gl.css'
|
||||||
|
|
||||||
|
function renderTable(feature) {
|
||||||
|
var mountNode = document.createElement('div');
|
||||||
|
ReactDOM.render(<FeatureLayerTable feature={feature} />, mountNode);
|
||||||
|
return mountNode.innerHTML;
|
||||||
|
}
|
||||||
|
|
||||||
export default class MapboxGlMap extends React.Component {
|
export default class MapboxGlMap extends React.Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
onDataChange: React.PropTypes.func,
|
onDataChange: React.PropTypes.func,
|
||||||
|
@ -52,6 +60,24 @@ export default class MapboxGlMap extends React.Component {
|
||||||
map: this.state.map
|
map: this.state.map
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
map.on('click', this.displayPopup.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
displayPopup(e) {
|
||||||
|
const features = this.state.map.queryRenderedFeatures(e.point, {
|
||||||
|
layers: this.layers
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!features.length) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const feature = features[0]
|
||||||
|
console.log('Click on feature', feature)
|
||||||
|
const popup = new MapboxGl.Popup()
|
||||||
|
.setLngLat(e.lngLat)
|
||||||
|
.setHTML(renderTable(feature))
|
||||||
|
.addTo(this.state.map)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
Loading…
Reference in a new issue