Geomap: Fix duplicate layer bug (#54660)

* Geomap: Fix duplicate layer bug

* Remove dependency on name parameter
This commit is contained in:
Drew Slobodnjak
2022-09-02 10:53:21 -07:00
committed by GitHub
parent 773a453108
commit 600ea254af
2 changed files with 9 additions and 0 deletions

View File

@@ -35,6 +35,7 @@ import { GeomapOverlay, OverlayProps } from './GeomapOverlay';
import { GeomapTooltip } from './GeomapTooltip';
import { DebugOverlay } from './components/DebugOverlay';
import { MeasureOverlay } from './components/MeasureOverlay';
import { MeasureVectorLayer } from './components/MeasureVectorLayer';
import { GeomapHoverPayload, GeomapLayerHover } from './event';
import { getGlobalStyles } from './globalStyles';
import { defaultMarkersConfig, MARKERS_LAYER_ID } from './layers/data/markersLayer';
@@ -146,6 +147,12 @@ export class GeomapPanel extends Component<Props, State> {
private doOptionsUpdate(selected: number) {
const { options, onOptionsChange } = this.props;
const layers = this.layers;
this.map?.getLayers().forEach((l) => {
if (l instanceof MeasureVectorLayer) {
this.map?.removeLayer(l);
this.map?.addLayer(l);
}
});
onOptionsChange({
...options,
basemap: layers[0].options,
@@ -227,6 +234,7 @@ export class GeomapPanel extends Component<Props, State> {
});
},
reorder: (startIndex: number, endIndex: number) => {
// TODO look into reorder with respect to measure layer
const result = Array.from(this.layers);
const [removed] = result.splice(startIndex, 1);
result.splice(endIndex, 0, removed);

View File

@@ -53,6 +53,7 @@ export const MeasureOverlay = ({ map, menuActiveState }: Props) => {
if (firstLoad) {
// Initialize on first load
setFirstLoad(false);
vector.current.setZIndex(1);
map.addLayer(vector.current);
map.addInteraction(vector.current.modify);
}