Cleanup popup nodes

Before, the component instances used for rendering popup content were
kept around, slowly leaking memory. This could be observed using react
developer tools.
This commit is contained in:
Alexander Clausen 2019-01-06 05:49:03 +01:00
parent 84654e81af
commit 8f391d7d52

View file

@ -17,10 +17,12 @@ import '../../libs/mapbox-rtl'
const IS_SUPPORTED = MapboxGl.supported();
function renderPropertyPopup(features) {
function renderPopup(popup) {
var mountNode = document.createElement('div');
ReactDOM.render(<FeaturePropertyPopup features={features} />, mountNode)
return mountNode.innerHTML;
ReactDOM.render(popup, mountNode)
var content = mountNode.innerHTML;
ReactDOM.unmountComponentAtNode(mountNode);
return content;
}
function buildInspectStyle(originalMapStyle, coloredLayers, highlightedLayer) {
@ -162,11 +164,9 @@ export default class MapboxGlMap extends React.Component {
buildInspectStyle: (originalMapStyle, coloredLayers) => buildInspectStyle(originalMapStyle, coloredLayers, this.props.highlightedLayer),
renderPopup: features => {
if(this.props.inspectModeEnabled) {
return renderPropertyPopup(features)
return renderPopup(<FeaturePropertyPopup features={features} />);
} else {
var mountNode = document.createElement('div');
ReactDOM.render(<FeatureLayerPopup features={features} onLayerSelect={this.props.onLayerSelect} />, mountNode)
return mountNode
return renderPopup(<FeatureLayerPopup features={features} onLayerSelect={this.props.onLayerSelect} />);
}
}
})