<?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: Zooming to the Wrong Location in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zooming-to-the-wrong-location/m-p/1488996#M84837</link>
    <description>&lt;P&gt;The problem here is that you're zooming in as much as possible upon the geometry of the cluster graphic itself.&amp;nbsp; However, there's no guarantee that any of the points represented by that cluster will be within the extent of the view after zooming in.&lt;/P&gt;&lt;P&gt;Instead, you need to get a reference to the points represented by the cluster, and zoom to the extent of those points.&amp;nbsp; Therefore, you'll need something more like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;view.on("click", (event) =&amp;gt; {
  view.hitTest(event,{include:geojsonLayer}).then(({ results }) =&amp;gt; {
    console.log(results[0])
    if(results[0].graphic.attributes.cluster_count &amp;amp;&amp;amp; results[0].graphic.attributes.cluster_count &amp;gt; 1){
      //get a reference to the LayerView in order to do a client-side query
      var layerView = view.layerViews.find(function(layerView) { return (layerView.layer == geojsonLayer); });

      //create the query that will return the features associated with the cluster
      var query = layerView.createQuery();
      query.aggregateIds = [results[0].graphic.getObjectId()];

      //get the associated features and zoom to them
      layerView.queryFeatures(query).then(function(featureSet) {
        if (featureSet.features.length !== 0)
          view.goTo(featureSet.features);
      });
    }
  });
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What you're trying to achieve may not be an "exact science" though.&amp;nbsp; Although this will zoom to the minimum bounding rectangle of the points in the original cluster, some of those points may be close enough together that they appear as a new cluster of their own.&amp;nbsp; &amp;nbsp; Or in other cases, there may be other points still in the view that weren't part of the original cluster as well.&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jun 2024 17:56:44 GMT</pubDate>
    <dc:creator>JoelBennett</dc:creator>
    <dc:date>2024-06-11T17:56:44Z</dc:date>
    <item>
      <title>Zooming to the Wrong Location</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zooming-to-the-wrong-location/m-p/1488718#M84827</link>
      <description>&lt;P class=""&gt;Hi all,&lt;/P&gt;&lt;P class=""&gt;My have a small issue, but it feels challenging as I am new here. When a cluster image is clicked, it should zoom to the maximum level and display only the points data without the cluster.&lt;/P&gt;&lt;P class=""&gt;The code below handles the click event on each cluster image and zooms to the maximum level, but it zooms to the wrong location. I expect it to zoom to the specific location where all the data inside the clicked cluster image is available.&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;please provide guidance on how to handle this scenario?&lt;/P&gt;&lt;P class=""&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;html lang="en"&amp;gt;

&amp;lt;head&amp;gt;
  &amp;lt;meta charset="utf-8" /&amp;gt;
  &amp;lt;meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /&amp;gt;
  &amp;lt;title&amp;gt;GeoJSONLayer | Sample | ArcGIS Maps SDK for JavaScript 4.29&amp;lt;/title&amp;gt;

  &amp;lt;style&amp;gt;
    html,
    body,
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }

  &amp;lt;/style&amp;gt;

  &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.29/esri/themes/light/main.css" /&amp;gt;
  &amp;lt;script src="https://js.arcgis.com/4.29/"&amp;gt;&amp;lt;/script&amp;gt;

  &amp;lt;script&amp;gt;
    require(["esri/Map", "esri/layers/GeoJSONLayer", "esri/views/MapView"], (
      Map,
      GeoJSONLayer,
      MapView
    ) =&amp;gt; {
      const url = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.geojson";

      
      const template = {
        title: "Earthquake Info",
        content: "Magnitude {mag} {type} hit {place} on {time}",
        fieldInfos: [
          {
            fieldName: 'time',
            format: {
              dateFormat: 'short-date-short-time'
            }
          }
        ]
      };

      const renderer = {
        type: "simple",
        field: "mag",
        symbol: {
          type: "simple-marker",
          color: "orange",
          outline: {
            color: "white"
          }
        },
        visualVariables: [{
          type: "size",
          field: "mag",
          stops: [{
              value: 2.5,
              size: "4px"
            },
            {
              value: 8,
              size: "40px"
            }
          ]
        }]
      };

      const geojsonLayer = new GeoJSONLayer({
        url: url,
        featureReduction: {
            type: "cluster",
            clusterRadius: "150px",
              popupTemplate: {
                title: "Cluster summary",
                content: "This cluster contains {cluster_count} points."
              },
              symbol: {
                type: "picture-marker", 
                url: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQa88gtYlcIGYRv5X5yEs7NbJ5JkJdDvzCmLf41BtSCgHqCodZV2fa4ZIjCjroPj27SQCE&amp;amp;usqp=CAU",
                },
            },
        popupTemplate: template,
        renderer: renderer,
        orderBy: {
          field: "mag"
        }
      });

      const map = new Map({
        basemap: "gray-vector",
        layers: [geojsonLayer]
      });

      const view = new MapView({
        container: "viewDiv",
        center: [-168, 46],
        zoom: 2,
        map: map
      });
      
      //onclick of cluster image
      view.on("click", (event) =&amp;gt; {
        view.hitTest(event).then(({ results }) =&amp;gt; {
          console.log(results[0])
          if(results[0].graphic.attributes.cluster_count &amp;amp;&amp;amp; results[0].graphic.attributes.cluster_count &amp;gt; 1){
            view.goTo(results[0].graphic.geometry).then(() =&amp;gt; {
              view.zoom = 23;
            })
          }
        });
      });
    
    });

  &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
  &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2024 07:21:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zooming-to-the-wrong-location/m-p/1488718#M84827</guid>
      <dc:creator>TapanPatra1</dc:creator>
      <dc:date>2024-06-11T07:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: Zooming to the Wrong Location</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zooming-to-the-wrong-location/m-p/1488996#M84837</link>
      <description>&lt;P&gt;The problem here is that you're zooming in as much as possible upon the geometry of the cluster graphic itself.&amp;nbsp; However, there's no guarantee that any of the points represented by that cluster will be within the extent of the view after zooming in.&lt;/P&gt;&lt;P&gt;Instead, you need to get a reference to the points represented by the cluster, and zoom to the extent of those points.&amp;nbsp; Therefore, you'll need something more like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;view.on("click", (event) =&amp;gt; {
  view.hitTest(event,{include:geojsonLayer}).then(({ results }) =&amp;gt; {
    console.log(results[0])
    if(results[0].graphic.attributes.cluster_count &amp;amp;&amp;amp; results[0].graphic.attributes.cluster_count &amp;gt; 1){
      //get a reference to the LayerView in order to do a client-side query
      var layerView = view.layerViews.find(function(layerView) { return (layerView.layer == geojsonLayer); });

      //create the query that will return the features associated with the cluster
      var query = layerView.createQuery();
      query.aggregateIds = [results[0].graphic.getObjectId()];

      //get the associated features and zoom to them
      layerView.queryFeatures(query).then(function(featureSet) {
        if (featureSet.features.length !== 0)
          view.goTo(featureSet.features);
      });
    }
  });
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What you're trying to achieve may not be an "exact science" though.&amp;nbsp; Although this will zoom to the minimum bounding rectangle of the points in the original cluster, some of those points may be close enough together that they appear as a new cluster of their own.&amp;nbsp; &amp;nbsp; Or in other cases, there may be other points still in the view that weren't part of the original cluster as well.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2024 17:56:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zooming-to-the-wrong-location/m-p/1488996#M84837</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2024-06-11T17:56:44Z</dc:date>
    </item>
  </channel>
</rss>

