mirror of https://gitee.com/antv-l7/antv-l7
feat(control): 修复地图缩放时,图层控件选中失效
This commit is contained in:
parent
e5e520e8d0
commit
2574509217
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue