feat: l7map 补充地图参数、pitchEnabled、rotateEnabled

This commit is contained in:
2912401452 2022-03-23 14:35:40 +08:00
parent 886598bf1e
commit 07b605d61c
6 changed files with 25 additions and 9 deletions

View File

@ -61,6 +61,8 @@ export default class Camera extends EventEmitter {
private onEaseFrame: (_: number) => void;
private onEaseEnd: (easeId?: string) => void;
private easeFrameId: number;
private pitchEnabled: boolean;
private rotateEnabled: boolean;
constructor(options: IMapOptions) {
super();
@ -69,6 +71,8 @@ export default class Camera extends EventEmitter {
this.moving = false;
this.zooming = false;
this.bearingSnap = options.bearingSnap;
this.pitchEnabled = options.pitchEnabled;
this.rotateEnabled = options.rotateEnabled;
this.transform = new Transform(
minZoom,
maxZoom,
@ -363,10 +367,10 @@ export default class Camera extends EventEmitter {
if (this.zooming) {
tr.zoom = interpolate(startZoom, zoom, k);
}
if (this.rotating) {
if (this.rotating && this.rotateEnabled) {
tr.bearing = interpolate(startBearing, bearing, k);
}
if (this.pitching) {
if (this.pitching && this.pitchEnabled) {
tr.pitch = interpolate(startPitch, pitch, k);
}
if (this.padding) {

View File

@ -52,6 +52,8 @@ const DefaultOptions: IMapOptions = {
pitchWithRotate: true,
trackResize: true,
renderWorldCopies: true,
pitchEnabled: true,
rotateEnabled: true,
};
export class EarthMap extends Camera {
public doubleClickZoom: DoubleClickZoomHandler;

View File

@ -61,6 +61,8 @@ export interface IHandlerOptions {
bearingSnap: number;
clickTolerance: number;
pitchWithRotate: boolean;
pitchEnabled: boolean;
rotateEnabled: boolean;
}
class HandlerManager {
@ -80,6 +82,8 @@ class HandlerManager {
private changes: Array<[IHandlerResult, any, any]>;
private previousActiveHandlers: { [key: string]: IHandler };
private bearingChanged: boolean;
private rotateEnabled: boolean;
private pitchEnabled: boolean;
private listeners: Array<
[HTMLElement, string, void | { passive?: boolean; capture?: boolean }]
>;
@ -93,6 +97,8 @@ class HandlerManager {
this.inertia = new HandlerInertia(map);
this.bearingSnap = options.bearingSnap;
this.rotateEnabled = options.rotateEnabled;
this.pitchEnabled = options.pitchEnabled;
this.previousActiveHandlers = {};
// Track whether map is currently moving, to compute start/move/end events
@ -548,10 +554,10 @@ class HandlerManager {
around = around || map.transform.centerPoint;
const loc = tr.pointLocation(panDelta ? around.sub(panDelta) : around);
if (bearingDelta) {
if (bearingDelta && this.rotateEnabled) {
tr.bearing += bearingDelta;
}
if (pitchDelta) {
if (pitchDelta && this.pitchEnabled) {
tr.pitch += pitchDelta;
}
if (zoomDelta) {

View File

@ -30,4 +30,6 @@ export interface IMapOptions {
bearingSnap: number;
clickTolerance: number;
pitchWithRotate: boolean;
pitchEnabled: boolean;
rotateEnabled: boolean;
}

View File

@ -53,6 +53,8 @@ const DefaultOptions: IMapOptions = {
pitchWithRotate: true,
trackResize: true,
renderWorldCopies: true,
pitchEnabled: true,
rotateEnabled: true,
};
export class Map extends Camera {
public doubleClickZoom: DoubleClickZoomHandler;

View File

@ -20,6 +20,8 @@ export default class Demo extends React.Component {
mapSize: 1000,
maxZoom: 4,
minZoom: 2,
pitchEnabled: false,
rotateEnabled: false,
}),
});
scene.setBgColor('rgb(94, 182, 140)');
@ -66,13 +68,11 @@ export default class Demo extends React.Component {
.active(true)
.color('#0e0030')
.style({
// textAnchor: 'center', // 文本相对锚点的位置 center|left|right|top|bottom|top-left
// textOffset: [ 0, 0 ], // 文本相对锚点的偏移量 [水平, 垂直]
textAnchor: 'center', // 文本相对锚点的位置 center|left|right|top|bottom|top-left
spacing: 2, // 字符间距
// padding: [ 1, 1 ], // 文本包围盒 padding [水平,垂直],影响碰撞检测结果,避免相邻文本靠的太近
padding: [1, 1], // 文本包围盒 padding [水平,垂直],影响碰撞检测结果,避免相邻文本靠的太近
stroke: '#ffffff', // 描边颜色
strokeWidth: 1.5, // 描边宽度
// strokeOpacity: 1.0,
textAllowOverlap: true,
});
@ -87,7 +87,7 @@ export default class Demo extends React.Component {
);
scene.on('loaded', () => {
// scene.addLayer(imagelayer);
scene.addLayer(imagelayer);
scene.addLayer(textlayer);
// console.log(scene.mapService.getSize())