<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Point along a line in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479200#M44537</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am creating a web application, using javascript api and the requirement is to get a point on the line based on certain distance. If you have worked with ArcObject, then you would have used the &lt;SPAN style="font-family: courier new,courier;"&gt;QueryPoint &lt;/SPAN&gt;method in &lt;SPAN style="font-family: courier new,courier;"&gt;IPolyline&lt;/SPAN&gt;. Does anybody know how this can be achieved in javascript api.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 02 Jun 2015 18:34:59 GMT</pubDate>
    <dc:creator>thejuskambi</dc:creator>
    <dc:date>2015-06-02T18:34:59Z</dc:date>
    <item>
      <title>Point along a line</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479200#M44537</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am creating a web application, using javascript api and the requirement is to get a point on the line based on certain distance. If you have worked with ArcObject, then you would have used the &lt;SPAN style="font-family: courier new,courier;"&gt;QueryPoint &lt;/SPAN&gt;method in &lt;SPAN style="font-family: courier new,courier;"&gt;IPolyline&lt;/SPAN&gt;. Does anybody know how this can be achieved in javascript api.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jun 2015 18:34:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479200#M44537</guid>
      <dc:creator>thejuskambi</dc:creator>
      <dc:date>2015-06-02T18:34:59Z</dc:date>
    </item>
    <item>
      <title>Re: Point along a line</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479201#M44538</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thejus,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; The JS API does not contain any functionality like this currently. What I suggest is create a GP service for this.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jun 2015 18:42:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479201#M44538</guid>
      <dc:creator>RobertScheitlin__GISP</dc:creator>
      <dc:date>2015-06-02T18:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: Point along a line</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479202#M44539</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Robert,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am aware the js api does not have such functionality currently. But, isnt there a way to achieve this without having to use GP service. some sort of calculation or sort. Surely somebody would have needed or implemented this functionality.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jun 2015 19:04:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479202#M44539</guid>
      <dc:creator>thejuskambi</dc:creator>
      <dc:date>2015-06-02T19:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: Point along a line</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479203#M44540</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thejus,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; I have seen a couple of people ask this question over the last couple of years and no one has come up with a way to do it clientside (unless they just choose not to share).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jun 2015 19:11:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479203#M44540</guid>
      <dc:creator>RobertScheitlin__GISP</dc:creator>
      <dc:date>2015-06-02T19:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: Point along a line</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479204#M44541</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Based on code I found here:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://stackoverflow.com/questions/3120357/get-closest-point-to-a-line" title="http://stackoverflow.com/questions/3120357/get-closest-point-to-a-line" rel="nofollow noopener noreferrer" target="_blank"&gt;c# - get closest point to a line - Stack Overflow&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have implemented the following function, which has been working well.&amp;nbsp; As you can see, it is entirely client-side, and I have assigned the function to the Polyline "type" so I can simply call polyline.getClosestPoint(etc), but you can make it a standalone function like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;function getClosestPoint(polyline, point) {&lt;/P&gt;&lt;P&gt;//code&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;...and changing "this" to "polyline".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp; Polyline.prototype.getClosestPoint = function(point) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; var closestDistance = Number.MAX_VALUE;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var closestPoint = null;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var abapProduct;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var sqMagnitude;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var distance;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var vectorAP;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var vectorAB;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var pointA;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var pointB;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var pointC;
&amp;nbsp;&amp;nbsp;&amp;nbsp; for (var pathIndex = 0; pathIndex &amp;lt; this.paths.length; pathIndex++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (var pointIndex = 1; pointIndex &amp;lt; this.paths[pathIndex].length; pointIndex++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pointA = this.getPoint(pathIndex, pointIndex);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pointB = this.getPoint(pathIndex, pointIndex - 1);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vectorAP = [point.x - pointA.x, point.y - pointA.y];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vectorAB = [pointB.x - pointA.x, pointB.y - pointA.y];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sqMagnitude = Math.pow(vectorAB[0], 2) + Math.pow(vectorAB[1], 2);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; abapProduct = (vectorAB[0] * vectorAP[0]) + (vectorAB[1] * vectorAP[1]);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; distance = abapProduct / sqMagnitude;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (distance &amp;lt; 0)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pointC = pointA;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if (distance &amp;gt; 1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pointC = pointB;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pointC = new Point(pointA.x + (vectorAB[0] * distance), pointA.y + (vectorAB[1] * distance), this.spatialReference);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; distance = pointC.distanceTo(point);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (distance &amp;lt; closestDistance) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; closestDistance = distance;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; closestPoint = pointC;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; return closestPoint;
&amp;nbsp;&amp;nbsp; };&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:09:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479204#M44541</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2021-12-11T21:09:14Z</dc:date>
    </item>
    <item>
      <title>Re: Point along a line</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479205#M44542</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just realized that included a call to another custom function - distanceTo.&amp;nbsp; Here's the function definition:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp; Point.prototype.distanceTo = function(point) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; return Math.sqrt(Math.pow(this.x - point.x, 2) + (Math.pow(this.y - point.y, 2)));
&amp;nbsp;&amp;nbsp; };&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:09:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479205#M44542</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2021-12-11T21:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: Point along a line</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479206#M44543</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There is a library called &lt;A href="http://turfjs.org/"&gt;turf&lt;/A&gt; that is supposed to &lt;A href="http://turfjs.org/static/docs/module-turf_along.html"&gt;allow you to do this&lt;/A&gt;. (Note that I haven't tried it myself, though.) Since turf uses GeoJSON, you can use &lt;A href="http://terraformer.io/"&gt;Terraformer&lt;/A&gt; to &lt;A href="http://terraformer.io/arcgis-parser/"&gt;convert from ArcGIS geometries to GeoJSON&lt;/A&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Jun 2015 00:25:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479206#M44543</guid>
      <dc:creator>JeffJacobson</dc:creator>
      <dc:date>2015-06-04T00:25:22Z</dc:date>
    </item>
    <item>
      <title>Re: Point along a line</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479207#M44544</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So I noticed I answered a question you didn't ask...I should keep that in mind next time somebody does the same to me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyhow, try this, which is also entirely client side.&amp;nbsp; I've attached a copy since this forum software eliminates my extra line breaks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that I've tested this against ESRI's Measure widget, and concluded the Measure widget doesn't work properly.&amp;nbsp; I've hand calculated the distance between two points after acquiring their coordinates from the map, and it's quite a bit different from what the Measure tool measures between those points. I tested with data in Web Mercator...not sure if that would make a difference.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As such, I think this works properly.&amp;nbsp; It assumes a few things, like a valid polyline with at least one path that has at least 2 points.&amp;nbsp; It returns null if the distance is greater than the path's length, or if the distance is negative.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;function distanceBetweenPoints(x1, y1, x2, y2) {
 return Math.sqrt(Math.pow(x2 - x1, 2) + (Math.pow(y2 - y1, 2)));
}
function getPointAlongLine(polyline, distance, pathIndex) {
 if (!pathIndex)
&amp;nbsp; pathIndex = 0;
 if (!distance)
&amp;nbsp; distance = 0;
 if ((pathIndex &amp;gt;= 0) &amp;amp;&amp;amp; (pathIndex &amp;lt; polyline.paths.length)) {
&amp;nbsp; var path = polyline.paths[pathIndex];
&amp;nbsp; var x1, x2, x3, y1, y2, y3;
&amp;nbsp; var travelledDistance = 0;
&amp;nbsp; var pathDistance;
&amp;nbsp; var distanceDiff;
&amp;nbsp; var angle;
&amp;nbsp; if (distance === 0)
&amp;nbsp;&amp;nbsp; return polyline.getPoint(pathIndex, 0);
&amp;nbsp; else if (distance &amp;gt; 0) {
&amp;nbsp;&amp;nbsp; for (var i = 1; i &amp;lt; path.length; i++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; x1 = path[i-1][0];
&amp;nbsp;&amp;nbsp;&amp;nbsp; y1 = path[i-1][1];
&amp;nbsp;&amp;nbsp;&amp;nbsp; x2 = path&lt;I&gt;[0];
&amp;nbsp;&amp;nbsp;&amp;nbsp; y2 = path&lt;I&gt;[1];&lt;/I&gt;&lt;/I&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; pathDistance = this._distanceBetweenPoints(x1, y1, x2, y2);
&amp;nbsp;&amp;nbsp;&amp;nbsp; travelledDistance += pathDistance;
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (travelledDistance === distance)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return polyline.getPoint(pathIndex, i);
&amp;nbsp;&amp;nbsp;&amp;nbsp; else if (travelledDistance &amp;gt; distance) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; distanceDiff = pathDistance - (travelledDistance - distance);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; angle = Math.atan2(y2-y1, x2-x1);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x3 = distanceDiff * Math.cos(angle);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y3 = distanceDiff * Math.sin(angle);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return new Point(x1 + x3, y1 + y3, polyline.spatialReference);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp; }
&amp;nbsp; }
 }
 return null;
}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:09:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479207#M44544</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2021-12-11T21:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: Point along a line</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479208#M44545</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is exactly what I was looking for. Thanks Joel.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jun 2015 13:20:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479208#M44545</guid>
      <dc:creator>thejuskambi</dc:creator>
      <dc:date>2015-06-08T13:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: Point along a line</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479209#M44546</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Joel,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for posting this function.&amp;nbsp; It should be in the API.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FYI the measurement widget works with "geodesic" math so that you get "true/real world" lengths and areas.&amp;nbsp; The Web Mercator system makes a "nice" picture for web maps but it's really bad for calculating length and area (almost double at the US level latitudes).&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Aug 2016 15:05:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/point-along-a-line/m-p/479209#M44546</guid>
      <dc:creator>FredSpataro</dc:creator>
      <dc:date>2016-08-12T15:05:30Z</dc:date>
    </item>
  </channel>
</rss>

