Skip to content

Commit

Permalink
add function planar length #182
Browse files Browse the repository at this point in the history
  • Loading branch information
njakuschona committed Oct 26, 2023
1 parent f2c015e commit e711e92
Showing 1 changed file with 33 additions and 8 deletions.
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

0 comments on commit e711e92

Please sign in to comment.