feat(control): 修复地图缩放时,图层控件选中失效

This commit is contained in:
thinkinggis 2020-02-05 14:56:20 +08:00
parent e5e520e8d0
commit 2574509217
4 changed files with 35 additions and 3 deletions

View File

@ -175,8 +175,12 @@ export default class Layers extends Control {
for (let i = inputs.length - 1; i >= 0; i--) {
input = inputs[i];
layer = this.layerService.getLayer(input.layerId);
if (layer) {
input.disabled = !layer.inited || !layer.isVisible();
if (layer && layer.inited) {
const minZoom = layer.getMinZoom();
const maxZoom = layer.getMaxZoom();
input.disabled = zoom < minZoom || zoom > maxZoom;
}
}
}

View File

@ -141,6 +141,9 @@ export interface ILayer {
isVisible(): boolean;
setMaxZoom(min: number): ILayer;
setMinZoom(max: number): ILayer;
getMinZoom(): number;
getMaxZoom(): number;
get(name: string): number;
setBlend(type: keyof typeof BlendType): void;
// animate(field: string, option: any): ILayer;
render(): ILayer;

View File

@ -629,6 +629,22 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
return this;
}
public getMinZoom(): number {
const { minZoom } = this.getLayerConfig();
return minZoom as number;
}
public getMaxZoom(): number {
const { maxZoom } = this.getLayerConfig();
return maxZoom as number;
}
public get(name: string) {
const cfg = this.getLayerConfig();
// @ts-ignore
return cfg[name];
}
public setMaxZoom(maxZoom: number): ILayer {
this.updateLayerConfig({
maxZoom,

View File

@ -1,5 +1,5 @@
// @ts-ignore
import { PointLayer, PolygonLayer, Scale, Scene } from '@antv/l7';
import { Layers, PointLayer, PolygonLayer, Scale, Scene } from '@antv/l7';
import { Mapbox } from '@antv/l7-maps';
import * as React from 'react';
@ -70,7 +70,16 @@ export default class ScaleComponent extends React.Component {
layer.setSelect(e.featureId);
});
const scaleControl = new Scale();
const layers = {
点图层: pointLayer,
面图层: layer,
};
const layerControl = new Layers({
overlayers: layers,
});
scene.addControl(scaleControl);
scene.addControl(layerControl);
}
public render() {