fix: 绘制组件高德地图mousedown事件不能监听的问题

This commit is contained in:
thinkinggis 2020-04-07 15:24:23 +08:00
parent f7ab0c0ec5
commit 23f3cd824b
13 changed files with 82 additions and 19 deletions

View File

@ -98,7 +98,6 @@ export default class PickingService implements IPickingService {
layer.hooks.afterPickingEncode.call(); layer.hooks.afterPickingEncode.call();
const isPicked = this.pickFromPickingFBO(layer, target); const isPicked = this.pickFromPickingFBO(layer, target);
return isPicked && !layer.getLayerConfig().enablePropagation; return isPicked && !layer.getLayerConfig().enablePropagation;
// return false;
}); });
}); });
} }

View File

@ -2,7 +2,7 @@
* @Author: lzxue * @Author: lzxue
* @Date: 2020-04-03 19:24:16 * @Date: 2020-04-03 19:24:16
* @Last Modified by: mikey.zhaopeng * @Last Modified by: mikey.zhaopeng
* @Last Modified time: 2020-04-03 19:30:39 * @Last Modified time: 2020-04-07 15:17:21
*/ */
import { Control, IControlOption, PositionType, Scene } from '@antv/l7'; import { Control, IControlOption, PositionType, Scene } from '@antv/l7';
import { DOM } from '@antv/l7-utils'; import { DOM } from '@antv/l7-utils';
@ -104,7 +104,7 @@ export class DrawControl extends Control {
} }
private onButtonClick = (type: string, e: MouseEvent) => { private onButtonClick = (type: string, e: MouseEvent) => {
e.stopPropagation(); // e.stopPropagation();
for (const draw in this.draw) { for (const draw in this.draw) {
if (draw === type) { if (draw === type) {
this.draw[draw].enable(); this.draw[draw].enable();
@ -115,7 +115,7 @@ export class DrawControl extends Control {
}; };
private onDeleteMode = (type: string, e: MouseEvent) => { private onDeleteMode = (type: string, e: MouseEvent) => {
e.stopPropagation(); // e.stopPropagation();
if (!this.currentDraw) { if (!this.currentDraw) {
return; return;
} }

View File

@ -49,7 +49,9 @@ export default abstract class DrawMode extends EventEmitter {
return; return;
} }
// @ts-ignore // @ts-ignore
this.scene.map.dragPan.disable(); this.scene.setMapStatus({
dragEnable: false,
});
this.scene.on('dragstart', this.onDragStart); this.scene.on('dragstart', this.onDragStart);
this.scene.on('dragging', this.onDragging); this.scene.on('dragging', this.onDragging);
this.scene.on('dragend', this.onDragEnd); this.scene.on('dragend', this.onDragEnd);
@ -68,7 +70,9 @@ export default abstract class DrawMode extends EventEmitter {
this.scene.off('click', this.onClick); this.scene.off('click', this.onClick);
this.resetCursor(); this.resetCursor();
// @ts-ignore // @ts-ignore
this.scene.map.dragPan.enable(); this.scene.setMapStatus({
dragEnable: true,
});
this.isEnable = false; this.isEnable = false;
} }
public setCurrentFeature(feature: Feature) { public setCurrentFeature(feature: Feature) {

View File

@ -44,7 +44,7 @@ export default class DrawPoint extends DrawFeature {
}; };
protected onClick = (e: any) => { protected onClick = (e: any) => {
const lngLat = e.lngLat; const lngLat = e.lngLat || e.lnglat;
const feature = this.createFeature(lngLat); const feature = this.createFeature(lngLat);
this.drawRender.update(featureCollection([feature])); this.drawRender.update(featureCollection([feature]));
this.drawVertexLayer.update(featureCollection([feature])); this.drawVertexLayer.update(featureCollection([feature]));

View File

@ -110,7 +110,7 @@ export default class DrawPolygon extends DrawFeature {
}; };
protected onClick = (e: any) => { protected onClick = (e: any) => {
const lngLat = e.lngLat; const lngLat = e.lngLat || e.lnglat;
this.endPoint = lngLat; this.endPoint = lngLat;
this.points.push(lngLat); this.points.push(lngLat);
const feature = this.createFeature(this.points); const feature = this.createFeature(this.points);
@ -123,7 +123,7 @@ export default class DrawPolygon extends DrawFeature {
}; };
protected onMouseMove = (e: any) => { protected onMouseMove = (e: any) => {
const lngLat = e.lngLat; const lngLat = e.lngLat || e.lnglat;
if (this.points.length === 0) { if (this.points.length === 0) {
return; return;
} }
@ -134,7 +134,7 @@ export default class DrawPolygon extends DrawFeature {
}; };
protected onDblClick = (e: any) => { protected onDblClick = (e: any) => {
const lngLat = e.lngLat; const lngLat = e.lngLat || e.lnglat;
if (this.points.length < 2) { if (this.points.length < 2) {
return; return;
} }

View File

@ -36,8 +36,7 @@ export default class DrawSelect extends DrawFeature {
} }
protected onDragStart = (e: IInteractionTarget) => { protected onDragStart = (e: IInteractionTarget) => {
// @ts-ignore this.scene.setMapStatus({ dragEnable: false });
this.scene.map.dragPan.disable();
this.dragStartPoint = e.lngLat; this.dragStartPoint = e.lngLat;
}; };
protected getDefaultOptions() { protected getDefaultOptions() {

View File

@ -24,7 +24,7 @@ export default class DrawLayer extends BaseRender {
layer.on('mouseenter', this.onMouseMove); layer.on('mouseenter', this.onMouseMove);
layer.on('mouseout', this.onUnMouseMove); layer.on('mouseout', this.onUnMouseMove);
layer.on('click', this.onClick); layer.on('click', this.onClick);
layer.on('unmousedown', this.onUnClick); layer.on('unmouseup', this.onUnClick);
this.isEnableDrag = true; this.isEnableDrag = true;
} }
public disableDrag() { public disableDrag() {
@ -35,7 +35,7 @@ export default class DrawLayer extends BaseRender {
layer.off('mouseenter', this.onMouseMove); layer.off('mouseenter', this.onMouseMove);
layer.off('mouseout', this.onUnMouseMove); layer.off('mouseout', this.onUnMouseMove);
layer.off('click', this.onClick); layer.off('click', this.onClick);
layer.off('unmousedown', this.onUnClick); layer.off('unmouseup', this.onUnClick);
this.isEnableDrag = false; this.isEnableDrag = false;
} }

View File

@ -38,11 +38,9 @@ export default class DrawVertexLayer extends BaseRender {
private onMouseEnter = (e: any) => { private onMouseEnter = (e: any) => {
this.draw.setCursor('pointer'); this.draw.setCursor('pointer');
// this.draw.editMode.enable();
}; };
private onMouseOut = (e: any) => { private onMouseOut = (e: any) => {
this.draw.resetCursor(); this.draw.resetCursor();
// this.draw.editMode.disable();
}; };
private onClick = (e: any) => { private onClick = (e: any) => {
this.draw.addVertex(e.feature); this.draw.addVertex(e.feature);

View File

@ -18,7 +18,9 @@ export function renderFeature(fe: FeatureCollection, style: any): ILayer[] {
} }
function drawPoint(fe: FeatureCollection, style: any) { function drawPoint(fe: FeatureCollection, style: any) {
const layer = new PointLayer() const layer = new PointLayer({
zIndex: 2,
})
.source(fe) .source(fe)
.shape('circle') .shape('circle')
.color(style.color) .color(style.color)

View File

@ -109,7 +109,9 @@ export default class AMapService
} }
public getMapCanvasContainer(): HTMLElement { public getMapCanvasContainer(): HTMLElement {
return this.map.getContainer() as HTMLElement; return this.map
.getContainer()
?.getElementsByClassName('amap-maps')[0] as HTMLElement;
} }
public getSize(): [number, number] { public getSize(): [number, number] {

View File

@ -308,7 +308,7 @@ class Scene
this.mapService.setMapStyle(style); this.mapService.setMapStyle(style);
} }
public setMapStatus(options: IStatusOptions) { public setMapStatus(options: Partial<IStatusOptions>) {
this.mapService.setMapStatus(options); this.mapService.setMapStatus(options);
} }

View File

@ -0,0 +1,57 @@
import { Scene } from '@antv/l7';
import { DrawControl } from '@antv/l7-draw';
import { GaodeMap, Mapbox } from '@antv/l7-maps';
import * as React from 'react';
export default class AMapDraw extends React.Component {
private scene: Scene;
public componentWillUnmount() {
this.scene.destroy();
}
public async componentDidMount() {
const scene = new Scene({
id: 'map',
map: new GaodeMap({
pitch: 0,
style: 'dark', // hosted style id
center: [112.874, 32.76], // starting position
zoom: 12, // starting zoom
}),
});
this.scene = scene;
scene.on('loaded', () => {
const drawControl = new DrawControl(scene, {
position: 'topright',
layout: 'horizontal', // horizontal vertical
controls: {
point: true,
polygon: true,
line: true,
circle: true,
rect: true,
delete: true,
},
});
scene.on('click', () => {});
scene.addControl(drawControl);
});
}
public render() {
return (
<div
id="map"
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
}}
/>
);
}
}

View File

@ -1,5 +1,6 @@
import { storiesOf } from '@storybook/react'; import { storiesOf } from '@storybook/react';
import * as React from 'react'; import * as React from 'react';
import AMapDraw from './Components/AmapDraw';
import Circle from './Components/Circle'; import Circle from './Components/Circle';
import DrawCircle from './Components/DrawCircle'; import DrawCircle from './Components/DrawCircle';
import DrawControl from './Components/DrawControl'; import DrawControl from './Components/DrawControl';
@ -17,4 +18,5 @@ storiesOf('绘制', module)
.add('路径', () => <Line />, {}) .add('路径', () => <Line />, {})
.add('绘制组件', () => <DrawControl />, {}) .add('绘制组件', () => <DrawControl />, {})
.add('绘制圆', () => <DrawCircle />, {}) .add('绘制圆', () => <DrawCircle />, {})
.add('高德地图', () => <AMapDraw />, {})
.add('绘制面', () => <DrawPolygon />, {}); .add('绘制面', () => <DrawPolygon />, {});