Modify and snap to circle in user coordinates
Correct modify interaction at center and at drawn circle circumference Correct snap interaction at drawn circle circumference Test circle geometry in a user projection
This commit is contained in:
@@ -14,13 +14,14 @@ import {always, primaryAction, altKeyOnly, singleClick} from '../events/conditio
|
||||
import {boundingExtent, buffer as bufferExtent, createOrUpdateFromCoordinate as createExtent} from '../extent.js';
|
||||
import GeometryType from '../geom/GeometryType.js';
|
||||
import Point from '../geom/Point.js';
|
||||
import {fromCircle} from '../geom/Polygon.js';
|
||||
import PointerInteraction from './Pointer.js';
|
||||
import VectorLayer from '../layer/Vector.js';
|
||||
import VectorSource from '../source/Vector.js';
|
||||
import VectorEventType from '../source/VectorEventType.js';
|
||||
import RBush from '../structs/RBush.js';
|
||||
import {createEditingStyle} from '../style/Style.js';
|
||||
import {fromUserExtent, toUserExtent, fromUserCoordinate, toUserCoordinate} from '../proj.js';
|
||||
import {getUserProjection, fromUserExtent, toUserExtent, fromUserCoordinate, toUserCoordinate} from '../proj.js';
|
||||
|
||||
|
||||
/**
|
||||
@@ -657,7 +658,14 @@ class Modify extends PointerInteraction {
|
||||
centerSegmentData.featureSegments = featureSegments;
|
||||
circumferenceSegmentData.featureSegments = featureSegments;
|
||||
this.rBush_.insert(createExtent(coordinates), centerSegmentData);
|
||||
this.rBush_.insert(geometry.getExtent(), circumferenceSegmentData);
|
||||
let circleGeometry = /** @type {import("../geom/Geometry.js").default} */ (geometry);
|
||||
const userProjection = getUserProjection();
|
||||
if (userProjection && this.getMap()) {
|
||||
const projection = this.getMap().getView().getProjection();
|
||||
circleGeometry = circleGeometry.clone().transform(userProjection, projection);
|
||||
circleGeometry = fromCircle(/** @type {import("../geom/Circle.js").default} */ (circleGeometry)).transform(projection, userProjection);
|
||||
}
|
||||
this.rBush_.insert(circleGeometry.getExtent(), circumferenceSegmentData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -785,7 +793,16 @@ class Modify extends PointerInteraction {
|
||||
this.changingFeature_ = false;
|
||||
} else { // We're dragging the circle's circumference:
|
||||
this.changingFeature_ = true;
|
||||
geometry.setRadius(coordinateDistance(geometry.getCenter(), vertex));
|
||||
const projection = evt.map.getView().getProjection();
|
||||
let radius = coordinateDistance(fromUserCoordinate(geometry.getCenter(), projection),
|
||||
fromUserCoordinate(vertex, projection));
|
||||
const userProjection = getUserProjection();
|
||||
if (userProjection) {
|
||||
const circleGeometry = geometry.clone().transform(userProjection, projection);
|
||||
circleGeometry.setRadius(radius);
|
||||
radius = circleGeometry.transform(projection, userProjection).getRadius();
|
||||
}
|
||||
geometry.setRadius(radius);
|
||||
this.changingFeature_ = false;
|
||||
}
|
||||
break;
|
||||
@@ -898,7 +915,14 @@ class Modify extends PointerInteraction {
|
||||
circumferenceSegmentData.segment[0] = coordinates;
|
||||
circumferenceSegmentData.segment[1] = coordinates;
|
||||
this.rBush_.update(createExtent(coordinates), centerSegmentData);
|
||||
this.rBush_.update(geometry.getExtent(), circumferenceSegmentData);
|
||||
let circleGeometry = geometry;
|
||||
const userProjection = getUserProjection();
|
||||
if (userProjection) {
|
||||
const projection = evt.map.getView().getProjection();
|
||||
circleGeometry = circleGeometry.clone().transform(userProjection, projection);
|
||||
circleGeometry = fromCircle(circleGeometry).transform(projection, userProjection);
|
||||
}
|
||||
this.rBush_.update(circleGeometry.getExtent(), circumferenceSegmentData);
|
||||
} else {
|
||||
this.rBush_.update(boundingExtent(segmentData.segment), segmentData);
|
||||
}
|
||||
@@ -1249,11 +1273,15 @@ function projectedDistanceToSegmentDataSquared(pointCoordinates, segmentData, pr
|
||||
const geometry = segmentData.geometry;
|
||||
|
||||
if (geometry.getType() === GeometryType.CIRCLE) {
|
||||
const circleGeometry = /** @type {import("../geom/Circle.js").default} */ (geometry);
|
||||
let circleGeometry = /** @type {import("../geom/Circle.js").default} */ (geometry);
|
||||
|
||||
if (segmentData.index === CIRCLE_CIRCUMFERENCE_INDEX) {
|
||||
const userProjection = getUserProjection();
|
||||
if (userProjection) {
|
||||
circleGeometry = /** @type {import("../geom/Circle.js").default} */ (circleGeometry.clone().transform(userProjection, projection));
|
||||
}
|
||||
const distanceToCenterSquared =
|
||||
squaredCoordinateDistance(circleGeometry.getCenter(), pointCoordinates);
|
||||
squaredCoordinateDistance(circleGeometry.getCenter(), fromUserCoordinate(pointCoordinates, projection));
|
||||
const distanceToCircumference =
|
||||
Math.sqrt(distanceToCenterSquared) - circleGeometry.getRadius();
|
||||
return distanceToCircumference * distanceToCircumference;
|
||||
@@ -1280,7 +1308,12 @@ function closestOnSegmentData(pointCoordinates, segmentData, projection) {
|
||||
const geometry = segmentData.geometry;
|
||||
|
||||
if (geometry.getType() === GeometryType.CIRCLE && segmentData.index === CIRCLE_CIRCUMFERENCE_INDEX) {
|
||||
return geometry.getClosestPoint(pointCoordinates);
|
||||
let circleGeometry = /** @type {import("../geom/Circle.js").default} */ (geometry);
|
||||
const userProjection = getUserProjection();
|
||||
if (userProjection) {
|
||||
circleGeometry = /** @type {import("../geom/Circle.js").default} */ (circleGeometry.clone().transform(userProjection, projection));
|
||||
}
|
||||
return toUserCoordinate(circleGeometry.getClosestPoint(fromUserCoordinate(pointCoordinates, projection)), projection);
|
||||
}
|
||||
const coordinate = fromUserCoordinate(pointCoordinates, projection);
|
||||
tempSegment[0] = fromUserCoordinate(segmentData.segment[0], projection);
|
||||
|
||||
Reference in New Issue
Block a user