mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2025-04-06 13:13:09 +02:00
Merge pull request #483 from sk1p/popup-cleanup
Various cleanups regarding popups and inspect mode
This commit is contained in:
commit
de8c687dfb
3 changed files with 14 additions and 14 deletions
src/components
|
@ -198,7 +198,7 @@ export default class Toolbar extends React.Component {
|
||||||
<ToolbarSelect wdKey="nav:inspect">
|
<ToolbarSelect wdKey="nav:inspect">
|
||||||
<MdFindInPage />
|
<MdFindInPage />
|
||||||
<IconText>View </IconText>
|
<IconText>View </IconText>
|
||||||
<select onChange={(e) => this.handleSelection(e.target.value)}>
|
<select onChange={(e) => this.handleSelection(e.target.value)} value={currentView.id}>
|
||||||
{views.map((item) => {
|
{views.map((item) => {
|
||||||
return (
|
return (
|
||||||
<option key={item.id} value={item.id}>
|
<option key={item.id} value={item.id}>
|
||||||
|
|
|
@ -22,7 +22,7 @@ function renderProperties(feature) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderFeature(feature) {
|
function renderFeature(feature) {
|
||||||
return <div key={feature.id}>
|
return <div key={`${feature.sourceLayer}-${feature.id}`}>
|
||||||
<div className="maputnik-popup-layer-id">{feature.layer['source-layer']}{feature.inspectModeCounter && <span> × {feature.inspectModeCounter}</span>}</div>
|
<div className="maputnik-popup-layer-id">{feature.layer['source-layer']}{feature.inspectModeCounter && <span> × {feature.inspectModeCounter}</span>}</div>
|
||||||
<InputBlock key={"property-type"} label={"$type"}>
|
<InputBlock key={"property-type"} label={"$type"}>
|
||||||
<StringInput value={feature.geometry.type} style={{backgroundColor: 'transparent'}} />
|
<StringInput value={feature.geometry.type} style={{backgroundColor: 'transparent'}} />
|
||||||
|
@ -43,7 +43,7 @@ function removeDuplicatedFeatures(features) {
|
||||||
if(featureIndex === -1) {
|
if(featureIndex === -1) {
|
||||||
uniqueFeatures.push(feature)
|
uniqueFeatures.push(feature)
|
||||||
} else {
|
} else {
|
||||||
if(uniqueFeatures[featureIndex].hasOwnProperty('counter')) {
|
if(uniqueFeatures[featureIndex].hasOwnProperty('inspectModeCounter')) {
|
||||||
uniqueFeatures[featureIndex].inspectModeCounter++
|
uniqueFeatures[featureIndex].inspectModeCounter++
|
||||||
} else {
|
} else {
|
||||||
uniqueFeatures[featureIndex].inspectModeCounter = 2
|
uniqueFeatures[featureIndex].inspectModeCounter = 2
|
||||||
|
|
|
@ -17,10 +17,10 @@ import '../../libs/mapbox-rtl'
|
||||||
|
|
||||||
const IS_SUPPORTED = MapboxGl.supported();
|
const IS_SUPPORTED = MapboxGl.supported();
|
||||||
|
|
||||||
function renderPropertyPopup(features) {
|
function renderPopup(popup, mountNode) {
|
||||||
var mountNode = document.createElement('div');
|
ReactDOM.render(popup, mountNode);
|
||||||
ReactDOM.render(<FeaturePropertyPopup features={features} />, mountNode)
|
var content = mountNode.innerHTML;
|
||||||
return mountNode.innerHTML;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildInspectStyle(originalMapStyle, coloredLayers, highlightedLayer) {
|
function buildInspectStyle(originalMapStyle, coloredLayers, highlightedLayer) {
|
||||||
|
@ -77,9 +77,6 @@ export default class MapboxGlMap extends React.Component {
|
||||||
this.state = {
|
this.state = {
|
||||||
map: null,
|
map: null,
|
||||||
inspect: null,
|
inspect: null,
|
||||||
isPopupOpen: false,
|
|
||||||
popupX: 0,
|
|
||||||
popupY: 0,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,6 +147,8 @@ export default class MapboxGlMap extends React.Component {
|
||||||
const nav = new MapboxGl.NavigationControl();
|
const nav = new MapboxGl.NavigationControl();
|
||||||
map.addControl(nav, 'top-right');
|
map.addControl(nav, 'top-right');
|
||||||
|
|
||||||
|
const tmpNode = document.createElement('div');
|
||||||
|
|
||||||
const inspect = new MapboxInspect({
|
const inspect = new MapboxInspect({
|
||||||
popup: new MapboxGl.Popup({
|
popup: new MapboxGl.Popup({
|
||||||
closeOnClick: false
|
closeOnClick: false
|
||||||
|
@ -165,11 +164,9 @@ export default class MapboxGlMap extends React.Component {
|
||||||
buildInspectStyle: (originalMapStyle, coloredLayers) => buildInspectStyle(originalMapStyle, coloredLayers, this.props.highlightedLayer),
|
buildInspectStyle: (originalMapStyle, coloredLayers) => buildInspectStyle(originalMapStyle, coloredLayers, this.props.highlightedLayer),
|
||||||
renderPopup: features => {
|
renderPopup: features => {
|
||||||
if(this.props.inspectModeEnabled) {
|
if(this.props.inspectModeEnabled) {
|
||||||
return renderPropertyPopup(features)
|
return renderPopup(<FeaturePropertyPopup features={features} />, tmpNode);
|
||||||
} else {
|
} else {
|
||||||
var mountNode = document.createElement('div');
|
return renderPopup(<FeatureLayerPopup features={features} onLayerSelect={this.props.onLayerSelect} />, tmpNode);
|
||||||
ReactDOM.render(<FeatureLayerPopup features={features} onLayerSelect={this.props.onLayerSelect} />, mountNode)
|
|
||||||
return mountNode
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -177,6 +174,9 @@ export default class MapboxGlMap extends React.Component {
|
||||||
|
|
||||||
map.on("style.load", () => {
|
map.on("style.load", () => {
|
||||||
this.setState({ map, inspect });
|
this.setState({ map, inspect });
|
||||||
|
if(this.props.inspectModeEnabled) {
|
||||||
|
inspect.toggleInspector();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
map.on("data", e => {
|
map.on("data", e => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue