Use union instead of enum for geometry type
This commit is contained in:
committed by
Andreas Hocevar
parent
04ad0e0c5a
commit
9a6f8493fb
+16
-20
@@ -6,7 +6,6 @@ import Event from '../events/Event.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import Feature from '../Feature.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import GeometryType from '../geom/GeometryType.js';
|
||||
import InteractionProperty from './Property.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import MapBrowserEvent from '../MapBrowserEvent.js';
|
||||
@@ -35,7 +34,7 @@ import {squaredDistance as squaredCoordinateDistance} from '../coordinate.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {import("../geom/GeometryType.js").default} type Geometry type of
|
||||
* @property {import("../geom/Geometry.js").Type} type Geometry type of
|
||||
* the geometries being drawn with this instance.
|
||||
* @property {number} [clickTolerance=6] The maximum distance in pixels between
|
||||
* "down" and "up" for a "up" event to be considered a "click" event and
|
||||
@@ -282,10 +281,10 @@ class Draw extends PointerInteraction {
|
||||
|
||||
/**
|
||||
* Geometry type.
|
||||
* @type {import("../geom/GeometryType.js").default}
|
||||
* @type {import("../geom/Geometry.js").Type}
|
||||
* @private
|
||||
*/
|
||||
this.type_ = /** @type {import("../geom/GeometryType.js").default} */ (
|
||||
this.type_ = /** @type {import("../geom/Geometry.js").Type} */ (
|
||||
options.type
|
||||
);
|
||||
|
||||
@@ -890,10 +889,7 @@ class Draw extends PointerInteraction {
|
||||
const sketchPointGeom = this.sketchPoint_.getGeometry();
|
||||
sketchPointGeom.setCoordinates(coordinate);
|
||||
}
|
||||
if (
|
||||
geometry.getType() === GeometryType.POLYGON &&
|
||||
this.mode_ !== Mode.POLYGON
|
||||
) {
|
||||
if (geometry.getType() === 'Polygon' && this.mode_ !== Mode.POLYGON) {
|
||||
this.createOrUpdateCustomSketchLine_(/** @type {Polygon} */ (geometry));
|
||||
} else if (this.sketchLineCoords_) {
|
||||
const sketchLineGeom = this.sketchLine_.getGeometry();
|
||||
@@ -970,7 +966,7 @@ class Draw extends PointerInteraction {
|
||||
this.createOrUpdateSketchPoint_(finishCoordinate);
|
||||
}
|
||||
this.geometryFunction_(coordinates, geometry, projection);
|
||||
if (geometry.getType() === GeometryType.POLYGON && this.sketchLine_) {
|
||||
if (geometry.getType() === 'Polygon' && this.sketchLine_) {
|
||||
this.createOrUpdateCustomSketchLine_(/** @type {Polygon} */ (geometry));
|
||||
}
|
||||
} else if (mode === Mode.POLYGON) {
|
||||
@@ -1019,15 +1015,15 @@ class Draw extends PointerInteraction {
|
||||
}
|
||||
|
||||
// cast multi-part geometries
|
||||
if (this.type_ === GeometryType.MULTI_POINT) {
|
||||
if (this.type_ === 'MultiPoint') {
|
||||
sketchFeature.setGeometry(
|
||||
new MultiPoint([/** @type {PointCoordType} */ (coordinates)])
|
||||
);
|
||||
} else if (this.type_ === GeometryType.MULTI_LINE_STRING) {
|
||||
} else if (this.type_ === 'MultiLineString') {
|
||||
sketchFeature.setGeometry(
|
||||
new MultiLineString([/** @type {LineCoordType} */ (coordinates)])
|
||||
);
|
||||
} else if (this.type_ === GeometryType.MULTI_POLYGON) {
|
||||
} else if (this.type_ === 'MultiPolygon') {
|
||||
sketchFeature.setGeometry(
|
||||
new MultiPolygon([/** @type {PolyCoordType} */ (coordinates)])
|
||||
);
|
||||
@@ -1274,21 +1270,21 @@ export function createBox() {
|
||||
/**
|
||||
* Get the drawing mode. The mode for multi-part geometries is the same as for
|
||||
* their single-part cousins.
|
||||
* @param {import("../geom/GeometryType.js").default} type Geometry type.
|
||||
* @param {import("../geom/Geometry.js").Type} type Geometry type.
|
||||
* @return {Mode} Drawing mode.
|
||||
*/
|
||||
function getMode(type) {
|
||||
switch (type) {
|
||||
case GeometryType.POINT:
|
||||
case GeometryType.MULTI_POINT:
|
||||
case 'Point':
|
||||
case 'MultiPoint':
|
||||
return Mode.POINT;
|
||||
case GeometryType.LINE_STRING:
|
||||
case GeometryType.MULTI_LINE_STRING:
|
||||
case 'LineString':
|
||||
case 'MultiLineString':
|
||||
return Mode.LINE_STRING;
|
||||
case GeometryType.POLYGON:
|
||||
case GeometryType.MULTI_POLYGON:
|
||||
case 'Polygon':
|
||||
case 'MultiPolygon':
|
||||
return Mode.POLYGON;
|
||||
case GeometryType.CIRCLE:
|
||||
case 'Circle':
|
||||
return Mode.CIRCLE;
|
||||
default:
|
||||
throw new Error('Invalid type: ' + type);
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
import Event from '../events/Event.js';
|
||||
import Feature from '../Feature.js';
|
||||
import GeometryType from '../geom/GeometryType.js';
|
||||
import MapBrowserEventType from '../MapBrowserEventType.js';
|
||||
import Point from '../geom/Point.js';
|
||||
import PointerInteraction from './Pointer.js';
|
||||
@@ -478,7 +477,7 @@ class Extent extends PointerInteraction {
|
||||
function getDefaultExtentStyleFunction() {
|
||||
const style = createEditingStyle();
|
||||
return function (feature, resolution) {
|
||||
return style[GeometryType.POLYGON];
|
||||
return style['Polygon'];
|
||||
};
|
||||
}
|
||||
|
||||
@@ -490,7 +489,7 @@ function getDefaultExtentStyleFunction() {
|
||||
function getDefaultPointerStyleFunction() {
|
||||
const style = createEditingStyle();
|
||||
return function (feature, resolution) {
|
||||
return style[GeometryType.POINT];
|
||||
return style['Point'];
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import CollectionEventType from '../CollectionEventType.js';
|
||||
import Event from '../events/Event.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import Feature from '../Feature.js';
|
||||
import GeometryType from '../geom/GeometryType.js';
|
||||
import MapBrowserEventType from '../MapBrowserEventType.js';
|
||||
import Point from '../geom/Point.js';
|
||||
import PointerInteraction from './Pointer.js';
|
||||
@@ -905,38 +904,38 @@ class Modify extends PointerInteraction {
|
||||
}
|
||||
|
||||
switch (geometry.getType()) {
|
||||
case GeometryType.POINT:
|
||||
case 'Point':
|
||||
coordinates = vertex;
|
||||
segment[0] = vertex;
|
||||
segment[1] = vertex;
|
||||
break;
|
||||
case GeometryType.MULTI_POINT:
|
||||
case 'MultiPoint':
|
||||
coordinates = geometry.getCoordinates();
|
||||
coordinates[segmentData.index] = vertex;
|
||||
segment[0] = vertex;
|
||||
segment[1] = vertex;
|
||||
break;
|
||||
case GeometryType.LINE_STRING:
|
||||
case 'LineString':
|
||||
coordinates = geometry.getCoordinates();
|
||||
coordinates[segmentData.index + index] = vertex;
|
||||
segment[index] = vertex;
|
||||
break;
|
||||
case GeometryType.MULTI_LINE_STRING:
|
||||
case 'MultiLineString':
|
||||
coordinates = geometry.getCoordinates();
|
||||
coordinates[depth[0]][segmentData.index + index] = vertex;
|
||||
segment[index] = vertex;
|
||||
break;
|
||||
case GeometryType.POLYGON:
|
||||
case 'Polygon':
|
||||
coordinates = geometry.getCoordinates();
|
||||
coordinates[depth[0]][segmentData.index + index] = vertex;
|
||||
segment[index] = vertex;
|
||||
break;
|
||||
case GeometryType.MULTI_POLYGON:
|
||||
case 'MultiPolygon':
|
||||
coordinates = geometry.getCoordinates();
|
||||
coordinates[depth[1]][depth[0]][segmentData.index + index] = vertex;
|
||||
segment[index] = vertex;
|
||||
break;
|
||||
case GeometryType.CIRCLE:
|
||||
case 'Circle':
|
||||
segment[0] = vertex;
|
||||
segment[1] = vertex;
|
||||
if (segmentData.index === CIRCLE_CENTER_INDEX) {
|
||||
@@ -1011,7 +1010,7 @@ class Modify extends PointerInteraction {
|
||||
}
|
||||
|
||||
if (
|
||||
segmentDataMatch.geometry.getType() === GeometryType.CIRCLE &&
|
||||
segmentDataMatch.geometry.getType() === 'Circle' &&
|
||||
segmentDataMatch.index === CIRCLE_CIRCUMFERENCE_INDEX
|
||||
) {
|
||||
const closestVertex = closestOnSegmentData(
|
||||
@@ -1049,15 +1048,15 @@ class Modify extends PointerInteraction {
|
||||
let coordinates = segmentDataMatch.geometry.getCoordinates();
|
||||
switch (segmentDataMatch.geometry.getType()) {
|
||||
// prevent dragging closed linestrings by the connecting node
|
||||
case GeometryType.LINE_STRING:
|
||||
case GeometryType.MULTI_LINE_STRING:
|
||||
case 'LineString':
|
||||
case 'MultiLineString':
|
||||
continue;
|
||||
// if dragging the first vertex of a polygon, ensure the other segment
|
||||
// belongs to the closing vertex of the linear ring
|
||||
case GeometryType.MULTI_POLYGON:
|
||||
case 'MultiPolygon':
|
||||
coordinates = coordinates[depth[1]];
|
||||
/* falls through */
|
||||
case GeometryType.POLYGON:
|
||||
case 'Polygon':
|
||||
if (
|
||||
segmentDataMatch.index !==
|
||||
coordinates[depth[0]].length - 2
|
||||
@@ -1105,7 +1104,7 @@ class Modify extends PointerInteraction {
|
||||
for (let i = this.dragSegments_.length - 1; i >= 0; --i) {
|
||||
const segmentData = this.dragSegments_[i][0];
|
||||
const geometry = segmentData.geometry;
|
||||
if (geometry.getType() === GeometryType.CIRCLE) {
|
||||
if (geometry.getType() === 'Circle') {
|
||||
// Update a circle object in the R* bush:
|
||||
const coordinates = geometry.getCenter();
|
||||
const centerSegmentData = segmentData.featureSegments[0];
|
||||
@@ -1190,7 +1189,7 @@ class Modify extends PointerInteraction {
|
||||
feature.getGeometry()
|
||||
);
|
||||
if (
|
||||
geometry.getType() === GeometryType.POINT &&
|
||||
geometry.getType() === 'Point' &&
|
||||
includes(this.features_.getArray(), feature)
|
||||
) {
|
||||
hitPointGeometry = geometry;
|
||||
@@ -1237,7 +1236,7 @@ class Modify extends PointerInteraction {
|
||||
this.delta_[1] = vertex[1] - pixelCoordinate[1];
|
||||
}
|
||||
if (
|
||||
node.geometry.getType() === GeometryType.CIRCLE &&
|
||||
node.geometry.getType() === 'Circle' &&
|
||||
node.index === CIRCLE_CIRCUMFERENCE_INDEX
|
||||
) {
|
||||
this.snappedToVertex_ = true;
|
||||
@@ -1313,19 +1312,19 @@ class Modify extends PointerInteraction {
|
||||
}
|
||||
|
||||
switch (geometry.getType()) {
|
||||
case GeometryType.MULTI_LINE_STRING:
|
||||
case 'MultiLineString':
|
||||
coordinates = geometry.getCoordinates();
|
||||
coordinates[depth[0]].splice(index + 1, 0, vertex);
|
||||
break;
|
||||
case GeometryType.POLYGON:
|
||||
case 'Polygon':
|
||||
coordinates = geometry.getCoordinates();
|
||||
coordinates[depth[0]].splice(index + 1, 0, vertex);
|
||||
break;
|
||||
case GeometryType.MULTI_POLYGON:
|
||||
case 'MultiPolygon':
|
||||
coordinates = geometry.getCoordinates();
|
||||
coordinates[depth[1]][depth[0]].splice(index + 1, 0, vertex);
|
||||
break;
|
||||
case GeometryType.LINE_STRING:
|
||||
case 'LineString':
|
||||
coordinates = geometry.getCoordinates();
|
||||
coordinates.splice(index + 1, 0, vertex);
|
||||
break;
|
||||
@@ -1441,22 +1440,22 @@ class Modify extends PointerInteraction {
|
||||
component = coordinates;
|
||||
deleted = false;
|
||||
switch (geometry.getType()) {
|
||||
case GeometryType.MULTI_LINE_STRING:
|
||||
case 'MultiLineString':
|
||||
if (coordinates[segmentData.depth[0]].length > 2) {
|
||||
coordinates[segmentData.depth[0]].splice(index, 1);
|
||||
deleted = true;
|
||||
}
|
||||
break;
|
||||
case GeometryType.LINE_STRING:
|
||||
case 'LineString':
|
||||
if (coordinates.length > 2) {
|
||||
coordinates.splice(index, 1);
|
||||
deleted = true;
|
||||
}
|
||||
break;
|
||||
case GeometryType.MULTI_POLYGON:
|
||||
case 'MultiPolygon':
|
||||
component = component[segmentData.depth[1]];
|
||||
/* falls through */
|
||||
case GeometryType.POLYGON:
|
||||
case 'Polygon':
|
||||
component = component[segmentData.depth[0]];
|
||||
if (component.length > 4) {
|
||||
if (index == component.length - 1) {
|
||||
@@ -1575,7 +1574,7 @@ function projectedDistanceToSegmentDataSquared(
|
||||
) {
|
||||
const geometry = segmentData.geometry;
|
||||
|
||||
if (geometry.getType() === GeometryType.CIRCLE) {
|
||||
if (geometry.getType() === 'Circle') {
|
||||
let circleGeometry = /** @type {import("../geom/Circle.js").default} */ (
|
||||
geometry
|
||||
);
|
||||
@@ -1617,7 +1616,7 @@ function closestOnSegmentData(pointCoordinates, segmentData, projection) {
|
||||
const geometry = segmentData.geometry;
|
||||
|
||||
if (
|
||||
geometry.getType() === GeometryType.CIRCLE &&
|
||||
geometry.getType() === 'Circle' &&
|
||||
segmentData.index === CIRCLE_CIRCUMFERENCE_INDEX
|
||||
) {
|
||||
let circleGeometry = /** @type {import("../geom/Circle.js").default} */ (
|
||||
@@ -1651,7 +1650,7 @@ function closestOnSegmentData(pointCoordinates, segmentData, projection) {
|
||||
function getDefaultStyleFunction() {
|
||||
const style = createEditingStyle();
|
||||
return function (feature, resolution) {
|
||||
return style[GeometryType.POINT];
|
||||
return style['Point'];
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
import Collection from '../Collection.js';
|
||||
import CollectionEventType from '../CollectionEventType.js';
|
||||
import Event from '../events/Event.js';
|
||||
import GeometryType from '../geom/GeometryType.js';
|
||||
import Interaction from './Interaction.js';
|
||||
import VectorLayer from '../layer/Vector.js';
|
||||
import {TRUE} from '../functions.js';
|
||||
@@ -569,11 +568,8 @@ class Select extends Interaction {
|
||||
*/
|
||||
function getDefaultStyleFunction() {
|
||||
const styles = createEditingStyle();
|
||||
extend(styles[GeometryType.POLYGON], styles[GeometryType.LINE_STRING]);
|
||||
extend(
|
||||
styles[GeometryType.GEOMETRY_COLLECTION],
|
||||
styles[GeometryType.LINE_STRING]
|
||||
);
|
||||
extend(styles['Polygon'], styles['LineString']);
|
||||
extend(styles['GeometryCollection'], styles['LineString']);
|
||||
|
||||
return function (feature) {
|
||||
if (!feature.getGeometry()) {
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
import CollectionEventType from '../CollectionEventType.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import GeometryType from '../geom/GeometryType.js';
|
||||
import PointerInteraction from './Pointer.js';
|
||||
import RBush from '../structs/RBush.js';
|
||||
import VectorEventType from '../source/VectorEventType.js';
|
||||
|
||||
Reference in New Issue
Block a user