<?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 Re: What is the best way to find a point or midpoint for a highlighted polyline from the 'geometry' or 'feature' of the component ? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-is-the-best-way-to-find-a-point-or-midpoint/m-p/1012339#M71192</link>
    <description>&lt;P&gt;To account for multi-line features, you should use flat() to flatten the array.&lt;/P&gt;&lt;P&gt;To find the true middle vertex, using Math.round() would be better since it actually gets the center as parseInt() only turns numbers into ints. For example, if my line has 5 vertices, parseInt() would return 2 as the mid point, when Math.round() would return 3 which is not the mathematical middle, but is the middle as far as lines are concerned.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var combinedLine = new Polyline({
 paths:selectedResult.feature.geometry.paths.flat(),
 spatialReference:selectedResult.feature.geometry.spatialReference
});
var midIndex = Math.round(combinedLine.paths.length / 2);
var midPoint = new Point({
 x:combinedLine.paths[midIndex][0],
 y:combinedLine.paths[midIndex][1],
 spatialReference:combinedLine.spatialReference
});

mapView.popup.open ({

   location: midPoint,

   features: [selectedResult.feature]

});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 26 Dec 2020 02:47:00 GMT</pubDate>
    <dc:creator>LiamWelter-Reed</dc:creator>
    <dc:date>2020-12-26T02:47:00Z</dc:date>
    <item>
      <title>What is the best way to find a point or midpoint for a highlighted polyline from the 'geometry' or 'feature' of the component ?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-is-the-best-way-to-find-a-point-or-midpoint/m-p/79375#M7264</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a scenario I am working on where when I click the sidebar with results, I need to open a popup and highlight the graphic of the selected result from the sidebar.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Although the graphic is always highlighted correctly for the polyline, the popup is not always consistently pointing to the polyline. Most of the time the popup points few inches away or in some case really far away from the highlighted graphic. Since the user is not directly clicking on the map, but on the sidebar, I need to explicitly pass the location for the popUp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;What is the best way to figure out the location of the polyLine for its popUp ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Currently I am using the following to find the location for polyline. But as you can see in the screenshot, the popUp is displayed away from the polyline.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca;"&gt;mapView.popup.open ({&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca;"&gt;&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; &lt;SPAN style="color: #e23d39;"&gt;location: selectedResult.feature.geometry.extent.center,&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca;"&gt;&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; features: [selectedResult.feature]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3334ca;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-2 jive-image" height="359" src="https://community.esri.com/legacyfs/online/213242_pastedImage_0.png" style="width: 507px; height: 358.989px;" width="507" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am able to correctly point the popUp for &lt;SPAN style="color: #eb7a3d;"&gt;point : selectedResult.feature.geometry&lt;/SPAN&gt; and for a&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #eb7a3d;"&gt;polygon : selectedResult.feature.geometry.centroid,&lt;/SPAN&gt; but for the polyLine it is not working correctly.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Jul 2016 16:12:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-is-the-best-way-to-find-a-point-or-midpoint/m-p/79375#M7264</guid>
      <dc:creator>MaryAnnChiramattel</dc:creator>
      <dc:date>2016-07-26T16:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: What is the best way to find a point or midpoint for a highlighted polyline from the 'geometry' or 'feature' of the component ?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-is-the-best-way-to-find-a-point-or-midpoint/m-p/79376#M7265</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure that there is really an easy way to do this. You could continue to do what you're already doing, but instead of snapping the popup box to the selectedResult.feature.geometry.extent.center, you could take that extent center, then pass it in to geometryEngine.nearestCoordinate() or geometryEngine.nearestVertex() to get the closest coordinate or vertex on the polyline. Then you snap the popup to the resulting geometry of the method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But, its still probably not going to get the center of the polyline, because the extent center for the polyline can be a long way away from the polyline depending on its shape. Here's a horrible example from MS Paint!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="213282" class="image-1 jive-image" height="182" src="https://community.esri.com/legacyfs/online/213282_pastedImage_0.png" style="height: 182px; width: 216.462px;" width="216" /&gt;&lt;/P&gt;&lt;P&gt;If the red line is your polyline, then the extent of that polyline is essentially the box surrounding it. Therefore, the extent center would be the black dot, which is nowhere near the line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another method could be to find the middle index for the polylines paths property and try snapping to that. But again, that is all dependent on the paths and if you have a straight line polyline with only two paths (start and end) then you will have no middle to snap too.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Jul 2016 23:58:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-is-the-best-way-to-find-a-point-or-midpoint/m-p/79376#M7265</guid>
      <dc:creator>JordanKing3</dc:creator>
      <dc:date>2016-07-26T23:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: What is the best way to find a point or midpoint for a highlighted polyline from the 'geometry' or 'feature' of the component ?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-is-the-best-way-to-find-a-point-or-midpoint/m-p/79377#M7266</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could use the middle vertex of the polyline path array:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var mid = parseInt( &lt;SPAN style="color: #303030; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;selectedResult.feature.geometry.paths[0].length / 2);&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit; color: #303030;"&gt;mapView.popup.open ({&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit; color: #303030;"&gt;&lt;SPAN style="color: #3334ca; font-weight: inherit; font-family: inherit; font-style: inherit;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit;"&gt;location: selectedResult.feature.geometry.paths[0][mid],&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit; color: #303030;"&gt;&amp;nbsp;&amp;nbsp; features: [selectedResult.feature]&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; font-family: inherit; color: #303030;"&gt;});&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:03:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-is-the-best-way-to-find-a-point-or-midpoint/m-p/79377#M7266</guid>
      <dc:creator>FC_Basson</dc:creator>
      <dc:date>2021-12-10T23:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: What is the best way to find a point or midpoint for a highlighted polyline from the 'geometry' or 'feature' of the component ?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-is-the-best-way-to-find-a-point-or-midpoint/m-p/79378#M7267</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was thinking on the same page as you ...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Jul 2016 06:50:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-is-the-best-way-to-find-a-point-or-midpoint/m-p/79378#M7267</guid>
      <dc:creator>YousefQuran</dc:creator>
      <dc:date>2016-07-27T06:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: What is the best way to find a point or midpoint for a highlighted polyline from the 'geometry' or 'feature' of the component ?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-is-the-best-way-to-find-a-point-or-midpoint/m-p/79379#M7268</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for the explanations, I was able to resolve the issue by following the above pattern :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am pasting the exact pattern I wrote&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For opening a&amp;nbsp; polyline popup, I needed to fill out the x &amp;amp; y components of&amp;nbsp; geometry, which I can retrieve using the following:&lt;/P&gt;&lt;P&gt;&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; &lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var mid: number = selectedResult.geometry.paths[0].length / 2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&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; selectedResult.feature.geometry.x = selectedResult.feature.geometry.paths[0][mid][0];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&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; selectedResult.feature.geometry.y = selectedResult.feature.geometry.paths[0][mid][1];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After assigning x &amp;amp; y values popup.Open worked perfectly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;self.mapView.popup.open({&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&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; location:&amp;nbsp; selectedResult.feature.geometry,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&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; features: [selectedResult.feature],&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Jul 2016 16:21:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-is-the-best-way-to-find-a-point-or-midpoint/m-p/79379#M7268</guid>
      <dc:creator>MaryAnnChiramattel</dc:creator>
      <dc:date>2016-07-28T16:21:22Z</dc:date>
    </item>
    <item>
      <title>Re: What is the best way to find a point or midpoint for a highlighted polyline from the 'geometry' or 'feature' of the component ?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-is-the-best-way-to-find-a-point-or-midpoint/m-p/1012339#M71192</link>
      <description>&lt;P&gt;To account for multi-line features, you should use flat() to flatten the array.&lt;/P&gt;&lt;P&gt;To find the true middle vertex, using Math.round() would be better since it actually gets the center as parseInt() only turns numbers into ints. For example, if my line has 5 vertices, parseInt() would return 2 as the mid point, when Math.round() would return 3 which is not the mathematical middle, but is the middle as far as lines are concerned.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var combinedLine = new Polyline({
 paths:selectedResult.feature.geometry.paths.flat(),
 spatialReference:selectedResult.feature.geometry.spatialReference
});
var midIndex = Math.round(combinedLine.paths.length / 2);
var midPoint = new Point({
 x:combinedLine.paths[midIndex][0],
 y:combinedLine.paths[midIndex][1],
 spatialReference:combinedLine.spatialReference
});

mapView.popup.open ({

   location: midPoint,

   features: [selectedResult.feature]

});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Dec 2020 02:47:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-is-the-best-way-to-find-a-point-or-midpoint/m-p/1012339#M71192</guid>
      <dc:creator>LiamWelter-Reed</dc:creator>
      <dc:date>2020-12-26T02:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: What is the best way to find a point or midpoint for a highlighted polyline from the 'geometry' or 'feature' of the component ?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-is-the-best-way-to-find-a-point-or-midpoint/m-p/1648777#M87598</link>
      <description>&lt;P&gt;To find the midpoint of a polyline, I am using&amp;nbsp;&lt;SPAN&gt;the &lt;/SPAN&gt;&lt;STRONG&gt;along()&lt;/STRONG&gt;&lt;SPAN&gt; function in &lt;/SPAN&gt;&lt;STRONG&gt;Turfjs&lt;/STRONG&gt;&lt;SPAN&gt;. To use that function though I firstly need to convert the ArcGIS polyline to GeoJSON LineString by using the Terraformer library.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The JavaScript code looks like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const calculateMidpoint = (polyline: Polyline): Point | null =&amp;gt; {
  const halfwayLength = lengthOperator.execute(polyline) / 2;
  const gpsPolyline = webMercatorUtils.webMercatorToGeographic(polyline);
  const geoJsonLineString = arcgisToGeoJSON(gpsPolyline) as GeoJSON.LineString;
  const geoJsonMidPoint = along(geoJsonLineString, halfwayLength, {units: "meters"});
  return new Point({
    x: geoJsonMidPoint.geometry.coordinates[0],
    y: geoJsonMidPoint.geometry.coordinates[1],
    spatialReference: gpsPolyline.spatialReference
  });
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Sep 2025 22:58:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/what-is-the-best-way-to-find-a-point-or-midpoint/m-p/1648777#M87598</guid>
      <dc:creator>HenryKo2</dc:creator>
      <dc:date>2025-09-08T22:58:22Z</dc:date>
    </item>
  </channel>
</rss>

