Skip to content

Commit

Permalink
Stew ro/support drag pan for release (#576)
Browse files Browse the repository at this point in the history
* fix: support multiple env files

* fix: support drag pan for release
  • Loading branch information
stew-ro authored Sep 15, 2020
1 parent 0633507 commit 77620ec
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 25 deletions.
58 changes: 33 additions & 25 deletions src/react/components/common/imageMap/imageMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class ImageMap extends React.Component<IImageMapProps> {

private mapElement: HTMLDivElement | null = null;

private dragPan: DragPan;
private draw: Draw;
private dragBox: DragBox;
private modify: Modify;
Expand Down Expand Up @@ -192,7 +193,11 @@ export class ImageMap extends React.Component<IImageMapProps> {

public render() {
return (
<div onMouseLeave={this.handlePonterLeaveImageMap} className="map-wrapper">
<div
onMouseLeave={this.handlePonterLeaveImageMap}
onMouseEnter={this.handlePointerEnterImageMap}
className="map-wrapper"
>
<div style={{cursor: this.getCursor()}} id="map" className="map" ref={(el) => this.mapElement = el}/>
</div>
);
Expand Down Expand Up @@ -640,17 +645,15 @@ export class ImageMap extends React.Component<IImageMapProps> {
return;
}

this.countPointerDown += 1;
if (this.countPointerDown >= 2) {
this.setDragPanInteraction(true /*dragPanEnabled*/);
this.isSwiping = false;
return;
}

const eventPixel = this.map.getEventPixel(event.originalEvent);

const filter = this.getLayerFilterAtPixel(eventPixel);

const isPixelOnFeature = !!filter;
if (isPixelOnFeature) {
this.setDragPanInteraction(false);
}

if (filter && this.props.handleFeatureSelect) {
this.map.forEachFeatureAtPixel(
eventPixel,
Expand All @@ -660,9 +663,6 @@ export class ImageMap extends React.Component<IImageMapProps> {
filter.layerfilter,
);
}
const isPixelOnFeature = !!filter;
this.setDragPanInteraction(!isPixelOnFeature /*dragPanEnabled*/);
this.isSwiping = isPixelOnFeature;
}

private getLayerFilterAtPixel = (eventPixel: any) => {
Expand Down Expand Up @@ -786,18 +786,21 @@ export class ImageMap extends React.Component<IImageMapProps> {
return;
}

this.countPointerDown -= 1;
this.setDragPanInteraction(true /*dragPanEnabled*/);
this.isSwiping = false;
this.pointerMoveEventCount = 0;
this.setDragPanInteraction(true);
}

private setDragPanInteraction = (dragPanEnabled: boolean) => {
this.map.getInteractions().forEach((interaction) => {
if (interaction instanceof DragPan) {
interaction.setActive(dragPanEnabled);
}
});
if (dragPanEnabled) {
this.addInteraction(this.dragPan)
this.setSwiping(false);
} else {
this.removeInteraction(this.dragPan)
this.setSwiping(true);
}
}

public setSwiping = (swiping: boolean) => {
this.isSwiping = swiping;
}

private shouldIgnorePointerMove = () => {
Expand All @@ -809,11 +812,6 @@ export class ImageMap extends React.Component<IImageMapProps> {
return true;
}

if (this.ignorePointerMoveEventCount > this.pointerMoveEventCount) {
++this.pointerMoveEventCount;
return true;
}

return false;
}

Expand Down Expand Up @@ -849,6 +847,8 @@ export class ImageMap extends React.Component<IImageMapProps> {
}

private initializeDefaultSelectionMode = () => {
this.initializeDragPan();
this.setDragPanInteraction(true);
this.initializeSnapCheck();
this.initializePointerOnImageCheck();
this.initializeDragBox();
Expand Down Expand Up @@ -965,6 +965,10 @@ export class ImageMap extends React.Component<IImageMapProps> {
});
}

private initializeDragPan = () => {
this.dragPan = new DragPan();
}

private initializeDragBox = () => {
this.dragBox = new DragBox({
condition: shiftKeyOnly,
Expand Down Expand Up @@ -1060,6 +1064,10 @@ export class ImageMap extends React.Component<IImageMapProps> {
}
}

private handlePointerEnterImageMap = () => {
this.setDragPanInteraction(true);
}

private initializeEditorLayers = (projection: Projection) => {
this.initializeImageLayer(projection);
this.initializeTextLayer();
Expand Down
1 change: 1 addition & 0 deletions src/react/components/pages/editorPage/canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,7 @@ export default class Canvas extends React.Component<ICanvasProps, ICanvasState>
const regionId = feature.get("id");
if (isToggle && this.isRegionSelected(regionId)) {
this.removeFromSelectedRegions(regionId);
this.imageMap.setSwiping(false);
} else {
this.handleMultiSelection(regionId, category);
const polygon = regionId.split(",").map(parseFloat);
Expand Down

0 comments on commit 77620ec

Please sign in to comment.