@evergis/sgis
Advanced tools
Comparing version 0.5.0-alpha.30 to 0.5.0-alpha.31
@@ -7,5 +7,12 @@ import { Control, ControlWithSymbolParams } from "./Control"; | ||
import { IPoint } from "../Point"; | ||
import { DragEvent, DragStartEvent, sGisClickEvent, sGisMouseMoveEvent } from '../commonEvents'; | ||
import { Poly } from "../features/Poly"; | ||
export interface PolyDragParams extends ControlWithSymbolParams { | ||
/** | ||
* If on polygon feature will be created by click events. | ||
*/ | ||
createByClick?: boolean; | ||
} | ||
/** | ||
* Base class for controls that create polygon feature by dragging some area on the map. When the control is activated, | ||
* Base class for controls that create polygon feature. When the control is activated, | ||
* a new temporary layer is created and added to the map. The feature is drawn on that temp layer. After drawing is | ||
@@ -23,2 +30,3 @@ * finished, if the .activeLayer property is set, the feature is moved to the active layer. | ||
protected _activeFeature: Polygon | null; | ||
private readonly createByClick; | ||
/** | ||
@@ -28,3 +36,3 @@ * @param map - map the control will work with | ||
*/ | ||
constructor(map: Map, { symbol, activeLayer, isActive }?: ControlWithSymbolParams); | ||
constructor(map: Map, { symbol, activeLayer, isActive, createByClick }?: PolyDragParams); | ||
protected _activate(): void; | ||
@@ -35,2 +43,7 @@ protected _deactivate(): void; | ||
private _handleDragEnd; | ||
private _handleClick; | ||
private _handleMousemove; | ||
protected startDrawing(event: DragStartEvent | sGisClickEvent): void; | ||
protected updateDrawing(event: DragEvent | sGisMouseMoveEvent): void; | ||
protected finishDrawing(event: DragStartEvent | sGisClickEvent): void; | ||
private _removeDragListeners; | ||
@@ -37,0 +50,0 @@ /** |
@@ -63,4 +63,4 @@ import { PolyControl } from "./controls/PolyControl"; | ||
export { Control } from "./controls/Control"; | ||
export declare const version = "0.5.0-alpha.30"; | ||
export declare const releaseDate = "29.08.2022"; | ||
export declare const version = "0.5.0-alpha.31"; | ||
export declare const releaseDate = "13.09.2022"; | ||
export declare const controls: { | ||
@@ -67,0 +67,0 @@ Circle: typeof Circle; |
@@ -7,5 +7,12 @@ import { Control, ControlWithSymbolParams } from "./Control"; | ||
import { IPoint } from "../Point"; | ||
import { DragEvent, DragStartEvent, sGisClickEvent, sGisMouseMoveEvent } from '../commonEvents'; | ||
import { Poly } from "../features/Poly"; | ||
export interface PolyDragParams extends ControlWithSymbolParams { | ||
/** | ||
* If on polygon feature will be created by click events. | ||
*/ | ||
createByClick?: boolean; | ||
} | ||
/** | ||
* Base class for controls that create polygon feature by dragging some area on the map. When the control is activated, | ||
* Base class for controls that create polygon feature. When the control is activated, | ||
* a new temporary layer is created and added to the map. The feature is drawn on that temp layer. After drawing is | ||
@@ -23,2 +30,3 @@ * finished, if the .activeLayer property is set, the feature is moved to the active layer. | ||
protected _activeFeature: Polygon | null; | ||
private readonly createByClick; | ||
/** | ||
@@ -28,3 +36,3 @@ * @param map - map the control will work with | ||
*/ | ||
constructor(map: Map, { symbol, activeLayer, isActive }?: ControlWithSymbolParams); | ||
constructor(map: Map, { symbol, activeLayer, isActive, createByClick }?: PolyDragParams); | ||
protected _activate(): void; | ||
@@ -35,2 +43,7 @@ protected _deactivate(): void; | ||
private _handleDragEnd; | ||
private _handleClick; | ||
private _handleMousemove; | ||
protected startDrawing(event: DragStartEvent | sGisClickEvent): void; | ||
protected updateDrawing(event: DragEvent | sGisMouseMoveEvent): void; | ||
protected finishDrawing(event: DragStartEvent | sGisClickEvent): void; | ||
private _removeDragListeners; | ||
@@ -37,0 +50,0 @@ /** |
import { Control, DrawingBeginEvent, DrawingFinishEvent } from "./Control"; | ||
import { PolygonSymbol } from "../symbols/polygon/Simple"; | ||
import { Polygon } from "../features/Polygon"; | ||
import { DragEndEvent, DragEvent, DragStartEvent } from "../commonEvents"; | ||
import { DragEndEvent, DragEvent, DragStartEvent, sGisClickEvent, sGisMouseMoveEvent } from '../commonEvents'; | ||
/** | ||
* Base class for controls that create polygon feature by dragging some area on the map. When the control is activated, | ||
* Base class for controls that create polygon feature. When the control is activated, | ||
* a new temporary layer is created and added to the map. The feature is drawn on that temp layer. After drawing is | ||
@@ -18,26 +18,66 @@ * finished, if the .activeLayer property is set, the feature is moved to the active layer. | ||
*/ | ||
constructor(map, { symbol = new PolygonSymbol(), activeLayer = null, isActive = false } = {}) { | ||
constructor(map, { symbol = new PolygonSymbol(), activeLayer = null, isActive = false, createByClick = false } = {}) { | ||
super(map, { activeLayer, useTempLayer: true }); | ||
this.createByClick = false; | ||
this.symbol = symbol; | ||
this.createByClick = createByClick; | ||
this._handleDragStart = this._handleDragStart.bind(this); | ||
this._handleDrag = this._handleDrag.bind(this); | ||
this._handleDragEnd = this._handleDragEnd.bind(this); | ||
this._handleClick = this._handleClick.bind(this); | ||
this._handleMousemove = this._handleMousemove.bind(this); | ||
this.isActive = isActive; | ||
} | ||
_activate() { | ||
this.map.on(DragStartEvent.type, this._handleDragStart); | ||
if (this.createByClick) { | ||
this.map.on(sGisClickEvent.type, this._handleClick); | ||
this.map.on(sGisMouseMoveEvent.type, this._handleMousemove); | ||
} | ||
else { | ||
this.map.on(DragStartEvent.type, this._handleDragStart); | ||
} | ||
} | ||
_deactivate() { | ||
this._activeFeature = null; | ||
this._removeDragListeners(); | ||
this.map.off(DragStartEvent.type, this._handleDragStart); | ||
if (this.createByClick) { | ||
this.map.off(sGisClickEvent.type, this._handleClick); | ||
this.map.off(sGisMouseMoveEvent.type, this._handleMousemove); | ||
} | ||
else { | ||
this._removeDragListeners(); | ||
this.map.off(DragStartEvent.type, this._handleDragStart); | ||
} | ||
} | ||
_handleDragStart(event) { | ||
this.startDrawing(event); | ||
} | ||
_handleDrag(event) { | ||
this.updateDrawing(event); | ||
} | ||
_handleDragEnd(event) { | ||
this.finishDrawing(event); | ||
} | ||
_handleClick(event) { | ||
if (!this._activeFeature) { | ||
this.startDrawing(event); | ||
} | ||
else { | ||
this.finishDrawing(event); | ||
} | ||
} | ||
_handleMousemove(event) { | ||
if (this._activeFeature) { | ||
this.updateDrawing(event); | ||
} | ||
} | ||
startDrawing(event) { | ||
this._activeFeature = new Polygon(this._getNewCoordinates(event.point), { crs: event.point.crs, symbol: this.symbol }); | ||
this._tempLayer.add(this._activeFeature); | ||
this.map.on(DragEvent.type, this._handleDrag); | ||
this.map.on(DragEndEvent.type, this._handleDragEnd); | ||
if (!this.createByClick) { | ||
this.map.on(DragEvent.type, this._handleDrag); | ||
this.map.on(DragEndEvent.type, this._handleDragEnd); | ||
} | ||
this.fire(new DrawingBeginEvent()); | ||
} | ||
_handleDrag(event) { | ||
updateDrawing(event) { | ||
this._activeFeature.rings = this._getUpdatedCoordinates(event.point); | ||
@@ -47,3 +87,3 @@ this._tempLayer.redraw(); | ||
} | ||
_handleDragEnd(event) { | ||
finishDrawing(event) { | ||
let feature = this._activeFeature; | ||
@@ -54,3 +94,5 @@ this._activeFeature = null; | ||
} | ||
this._removeDragListeners(); | ||
if (!this.createByClick) { | ||
this._removeDragListeners(); | ||
} | ||
if (this.activeLayer) | ||
@@ -57,0 +99,0 @@ this.activeLayer.add(feature); |
@@ -63,4 +63,4 @@ import { PolyControl } from "./controls/PolyControl"; | ||
export { Control } from "./controls/Control"; | ||
export declare const version = "0.5.0-alpha.30"; | ||
export declare const releaseDate = "29.08.2022"; | ||
export declare const version = "0.5.0-alpha.31"; | ||
export declare const releaseDate = "13.09.2022"; | ||
export declare const controls: { | ||
@@ -67,0 +67,0 @@ Circle: typeof Circle; |
@@ -65,4 +65,4 @@ import { PolyControl } from "./controls/PolyControl"; | ||
export { Control } from "./controls/Control"; | ||
export const version = "0.5.0-alpha.30"; | ||
export const releaseDate = "29.08.2022"; | ||
export const version = "0.5.0-alpha.31"; | ||
export const releaseDate = "13.09.2022"; | ||
let utilsModulesExt = {}; | ||
@@ -69,0 +69,0 @@ Object.assign(utilsModulesExt, utilsModule, { Color: Color }); |
{ | ||
"name": "@evergis/sgis", | ||
"version": "0.5.0-alpha.30", | ||
"version": "0.5.0-alpha.31", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/sGis_bundle.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
2940761
36447