Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add function planar length #182 #186

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import SketchingEnhancedModel from "dn_sketchingenhanced/SketchingEnhancedModel"
import ConstructionModel from "./ConstructionModel";
import ConstructionHistory from "./ConstructionHistory";
import Circle from "esri/geometry/Circle";
import { Polygon, Polyline } from "esri/geometry";
import { pointFromDistance } from "esri/geometry/support/geodesicUtils";
import { Point, Polygon, Polyline } from "esri/geometry";
import { pointFromDistance, geodesicDistance } from "esri/geometry/support/geodesicUtils";
import type CoordinateTransformer from "coordinatetransformer/CoordinateTransformer";

export default class ConstructionController {
Expand Down Expand Up @@ -113,6 +113,17 @@ export default class ConstructionController {
graphic.geometry = poly;
}

private pointFromPlanarDistance(point: __esri.Point, distance: number, angle:number){
angle = 360 - (angle - 90);
if (angle <0 ){
angle + 360;
}
const radians = angle * (Math.PI / 180);
const x = point.x + distance * Math.cos(radians);
const y = point.y + distance * Math.sin(radians);
return({x, y});
}

private async createPolyline(graphic: __esri.Graphic, length: number): Promise<void> {
if (!graphic) {
return;
Expand All @@ -126,12 +137,26 @@ export default class ConstructionController {
}
const angle = this.getAngleBetweenTwoPoints(point1, point2);

// transform first point to 4326
const tPoint1 = await this._coordinateTransformer.transform(point1, "4326");
// calculate new point from distance and angle
const point = pointFromDistance(tPoint1, length, angle);
// transform new calculated endpoint back to map wkid
const tPoint = await this._coordinateTransformer.transform(point, geometry.spatialReference.wkid);
let geodesic = false;
if (geometry.spatialReference.wkid === 3857
|| geometry.spatialReference.wkid === 4326
|| geometry.spatialReference.latestWkid === 3857
|| geometry.spatialReference.latestWkid === 4326) {
geodesic = true;
}

let tPoint= null;
if (geodesic){
// transform first point to 4326
const tPoint1 = await this._coordinateTransformer.transform(point1, "4326");
// calculate new point from distance and angle
const point = pointFromDistance(tPoint1, length, angle);
// transform new calculated endpoint back to map wkid
tPoint = await this._coordinateTransformer.transform(point, geometry.spatialReference.wkid);
}
else {
tPoint = this.pointFromPlanarDistance(point1, length, angle);
}

path.pop();
path.push([tPoint.x, tPoint.y]);
Expand Down
Loading