mirror of https://gitee.com/antv-l7/antv-l7
feat: mapbox添加fitBoundsOptions
This commit is contained in:
parent
5a5aa49fa1
commit
b7f0689fd5
|
@ -155,7 +155,7 @@ export interface ILayer {
|
||||||
destroy(): void;
|
destroy(): void;
|
||||||
source(data: any, option?: ISourceCFG): ILayer;
|
source(data: any, option?: ISourceCFG): ILayer;
|
||||||
setData(data: any, option?: ISourceCFG): ILayer;
|
setData(data: any, option?: ISourceCFG): ILayer;
|
||||||
fitBounds(): ILayer;
|
fitBounds(fitBoundsOptions?: mapboxgl.FitBoundsOptions): ILayer;
|
||||||
/**
|
/**
|
||||||
* 向当前图层注册插件
|
* 向当前图层注册插件
|
||||||
* @param plugin 插件实例
|
* @param plugin 插件实例
|
||||||
|
@ -222,6 +222,7 @@ export interface ILayerConfig {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
zIndex: number;
|
zIndex: number;
|
||||||
autoFit: boolean;
|
autoFit: boolean;
|
||||||
|
fitBoundsOptions?: mapboxgl.FitBoundsOptions;
|
||||||
name: string; //
|
name: string; //
|
||||||
blend: keyof typeof BlendType;
|
blend: keyof typeof BlendType;
|
||||||
pickedFeatureID: number;
|
pickedFeatureID: number;
|
||||||
|
|
|
@ -50,7 +50,7 @@ export interface IMapService<RawMap = {}> {
|
||||||
zoomOut(): void;
|
zoomOut(): void;
|
||||||
panTo(p: Point): void;
|
panTo(p: Point): void;
|
||||||
panBy(pixel: Point): void;
|
panBy(pixel: Point): void;
|
||||||
fitBounds(bound: Bounds): void;
|
fitBounds(bound: Bounds, fitBoundsOptions?: mapboxgl.FitBoundsOptions): void;
|
||||||
setZoomAndCenter(zoom: number, center: Point): void;
|
setZoomAndCenter(zoom: number, center: Point): void;
|
||||||
setCenter(center: [number, number]): void;
|
setCenter(center: [number, number]): void;
|
||||||
setPitch(pitch: number): void;
|
setPitch(pitch: number): void;
|
||||||
|
|
|
@ -654,7 +654,7 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
|
||||||
/**
|
/**
|
||||||
* zoom to layer Bounds
|
* zoom to layer Bounds
|
||||||
*/
|
*/
|
||||||
public fitBounds(): ILayer {
|
public fitBounds(fitBoundsOptions?: mapboxgl.FitBoundsOptions): ILayer {
|
||||||
if (!this.inited) {
|
if (!this.inited) {
|
||||||
this.updateLayerConfig({
|
this.updateLayerConfig({
|
||||||
autoFit: true,
|
autoFit: true,
|
||||||
|
@ -663,10 +663,13 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
|
||||||
}
|
}
|
||||||
const source = this.getSource();
|
const source = this.getSource();
|
||||||
const extent = source.extent;
|
const extent = source.extent;
|
||||||
this.mapService.fitBounds([
|
this.mapService.fitBounds(
|
||||||
[extent[0], extent[1]],
|
[
|
||||||
[extent[2], extent[3]],
|
[extent[0], extent[1]],
|
||||||
]);
|
[extent[2], extent[3]],
|
||||||
|
],
|
||||||
|
fitBoundsOptions,
|
||||||
|
);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -876,9 +879,9 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
|
||||||
|
|
||||||
private sourceEvent = () => {
|
private sourceEvent = () => {
|
||||||
this.dataState.dataSourceNeedUpdate = true;
|
this.dataState.dataSourceNeedUpdate = true;
|
||||||
const { autoFit } = this.getLayerConfig();
|
const { autoFit, fitBoundsOptions } = this.getLayerConfig();
|
||||||
if (autoFit) {
|
if (autoFit) {
|
||||||
this.fitBounds();
|
this.fitBounds(fitBoundsOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.emit('dataUpdate');
|
this.emit('dataUpdate');
|
||||||
|
|
|
@ -11,10 +11,10 @@ export default class LayerStylePlugin implements ILayerPlugin {
|
||||||
layer.hooks.afterInit.tap('LayerStylePlugin', () => {
|
layer.hooks.afterInit.tap('LayerStylePlugin', () => {
|
||||||
// 更新图层默认状态
|
// 更新图层默认状态
|
||||||
layer.updateLayerConfig({});
|
layer.updateLayerConfig({});
|
||||||
const { autoFit } = layer.getLayerConfig();
|
const { autoFit, fitBoundsOptions } = layer.getLayerConfig();
|
||||||
if (autoFit) {
|
if (autoFit) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
layer.fitBounds();
|
layer.fitBounds(fitBoundsOptions);
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -157,8 +157,11 @@ export default class MapboxService
|
||||||
this.panTo(pixel);
|
this.panTo(pixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public fitBounds(bound: Bounds): void {
|
public fitBounds(
|
||||||
this.map.fitBounds(bound);
|
bound: Bounds,
|
||||||
|
fitBoundsOptions?: mapboxgl.FitBoundsOptions,
|
||||||
|
): void {
|
||||||
|
this.map.fitBounds(bound, fitBoundsOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setMaxZoom(max: number): void {
|
public setMaxZoom(max: number): void {
|
||||||
|
|
|
@ -18,7 +18,7 @@ export default React.memo(function Chart(props: ISourceProps) {
|
||||||
layer.setData(data, sourceOption);
|
layer.setData(data, sourceOption);
|
||||||
}
|
}
|
||||||
if (sourceOption.autoFit) {
|
if (sourceOption.autoFit) {
|
||||||
layer.fitBounds();
|
layer.fitBounds(sourceOption && sourceOption.fitBoundsOptions);
|
||||||
}
|
}
|
||||||
}, [data, JSON.stringify(sourceOption)]);
|
}, [data, JSON.stringify(sourceOption)]);
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -60,6 +60,8 @@ export interface ISourceOptions extends ISourceCFG {
|
||||||
data: any;
|
data: any;
|
||||||
// 每次更新数据之后是否自适应缩放
|
// 每次更新数据之后是否自适应缩放
|
||||||
autoFit?: boolean;
|
autoFit?: boolean;
|
||||||
|
// Mapbox 自适应的参数
|
||||||
|
fitBoundsOptions?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IActiveOptions {
|
export interface IActiveOptions {
|
||||||
|
|
|
@ -49,7 +49,7 @@ export default interface IMapController {
|
||||||
/**
|
/**
|
||||||
* 调整地图适合指定区域
|
* 调整地图适合指定区域
|
||||||
*/
|
*/
|
||||||
fitBounds(bound: Bounds): void;
|
fitBounds(bound: Bounds, fitBoundsOptions?: mapboxgl.FitBoundsOptions): void;
|
||||||
|
|
||||||
setRotation(rotation: number): void;
|
setRotation(rotation: number): void;
|
||||||
|
|
||||||
|
|
|
@ -270,8 +270,11 @@ class Scene
|
||||||
public setZoom(zoom: number): void {
|
public setZoom(zoom: number): void {
|
||||||
this.mapService.setZoom(zoom);
|
this.mapService.setZoom(zoom);
|
||||||
}
|
}
|
||||||
public fitBounds(bound: Bounds): void {
|
public fitBounds(
|
||||||
this.mapService.fitBounds(bound);
|
bound: Bounds,
|
||||||
|
fitBoundsOptions?: mapboxgl.FitBoundsOptions,
|
||||||
|
): void {
|
||||||
|
this.mapService.fitBounds(bound, fitBoundsOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public setZoomAndCenter(zoom: number, center: Point): void {
|
public setZoomAndCenter(zoom: number, center: Point): void {
|
||||||
|
|
Loading…
Reference in New Issue