<?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 Popup overflows on first click in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/popup-overflows-on-first-click/m-p/1371986#M83393</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am experiencing an issue where on the first click after a page load, (with default settings) the popup always opens above the click location, causing it to overflow the div and end up out of view. Every click after first seems to reliably work and doesn't collide with the edge of the map. Is this a known issue or am I missing a way to avoid this without docking the popup or something? I am able to reproduce this problem in the sample code snippets. &lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/intro-popup/" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/javascript/latest/sample-code/intro-popup/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;See below:&lt;BR /&gt;&lt;BR /&gt;first click after page load&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Clinton_Lunn_0-1705616499958.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/92086i507DA1A1E50CF75F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Clinton_Lunn_0-1705616499958.png" alt="Clinton_Lunn_0-1705616499958.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;second click (and beyond) after page load&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Clinton_Lunn_2-1705616746655.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/92088i4C7065E84C5CB41E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Clinton_Lunn_2-1705616746655.png" alt="Clinton_Lunn_2-1705616746655.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Jan 2024 22:27:18 GMT</pubDate>
    <dc:creator>Clinton_Lunn</dc:creator>
    <dc:date>2024-01-18T22:27:18Z</dc:date>
    <item>
      <title>Popup overflows on first click</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/popup-overflows-on-first-click/m-p/1371986#M83393</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am experiencing an issue where on the first click after a page load, (with default settings) the popup always opens above the click location, causing it to overflow the div and end up out of view. Every click after first seems to reliably work and doesn't collide with the edge of the map. Is this a known issue or am I missing a way to avoid this without docking the popup or something? I am able to reproduce this problem in the sample code snippets. &lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/intro-popup/" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/javascript/latest/sample-code/intro-popup/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;See below:&lt;BR /&gt;&lt;BR /&gt;first click after page load&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Clinton_Lunn_0-1705616499958.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/92086i507DA1A1E50CF75F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Clinton_Lunn_0-1705616499958.png" alt="Clinton_Lunn_0-1705616499958.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;second click (and beyond) after page load&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Clinton_Lunn_2-1705616746655.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/92088i4C7065E84C5CB41E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Clinton_Lunn_2-1705616746655.png" alt="Clinton_Lunn_2-1705616746655.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 22:27:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/popup-overflows-on-first-click/m-p/1371986#M83393</guid>
      <dc:creator>Clinton_Lunn</dc:creator>
      <dc:date>2024-01-18T22:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: Popup overflows on first click</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/popup-overflows-on-first-click/m-p/1372004#M83394</link>
      <description>&lt;P&gt;I've found the default Popup positioning tends to be unreliable, but fortunately you can override the default behavior by assigning a function to the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Popup.html#alignment" target="_self"&gt;alignment&lt;/A&gt; property.&amp;nbsp; I've modified the aforementioned &lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=intro-popup" target="_self"&gt;sample&lt;/A&gt; below with what my apps use.&amp;nbsp; In particular, I added lines 52-80, and also the reference to &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-core-reactiveUtils.html" target="_self"&gt;reactiveUtils&lt;/A&gt; on line 35.&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;Intro to popups | Sample | ArcGIS Maps SDK for JavaScript 4.28&amp;lt;/title&amp;gt;

    &amp;lt;style&amp;gt;
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }

      #instruction {
        z-index: 99;
        position: absolute;
        top: 15px;
        left: 50%;
        padding: 5px;
        margin-left: -175px;
        height: 30px;
        width: 355px;
        background: rgba(25, 25, 25, 0.8);
        color: white;
      }
    &amp;lt;/style&amp;gt;

    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.28/esri/themes/light/main.css" /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.28/"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;script&amp;gt;
      require(["esri/rest/locator", "esri/Map", "esri/views/MapView", "esri/core/reactiveUtils"], (locator, Map, MapView, reactiveUtils) =&amp;gt; {
        // Set up a locator url using the world geocoding service
        const locatorUrl = "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer";

        // Create the Map
        const map = new Map({
          basemap: "streets-navigation-vector"
        });

        // Create the MapView
        const view = new MapView({
          container: "viewDiv",
          map: map,
          center: [-71.6899, 43.7598],
          zoom: 12
        });

        reactiveUtils.watch(() =&amp;gt; view.popup?.id, function() {
    			view.popup.alignment = function() {
    				var location = this.location;
    				var view = this.view;
    
    				if ((location) &amp;amp;&amp;amp; (view)) {
    					var viewPoint = view.toScreen(location);
    					var y2 = view.height / 2;
    					var x2 = view.width / 3;
    					var x3 = x2 * 2;
    
    					if (viewPoint.y &amp;gt;= y2) {
    						if (viewPoint.x &amp;lt; x2)
    							return "top-right";
    						else if (viewPoint.x &amp;gt; x3)
    							return "top-left";
    					} else {
    						if (viewPoint.x &amp;lt; x2)
    							return "bottom-right";
    						else if (viewPoint.x &amp;gt; x3)
    							return "bottom-left";
    						else
    							return "bottom-center";
    					}
    				}
    
    				return "top-center";
    			};
        });

        /*******************************************************************
         * This click event sets generic content on the popup not tied to
         * a layer, graphic, or popupTemplate. The location of the point is
         * used as input to a reverse geocode method and the resulting
         * address is printed to the popup content.
         *******************************************************************/
        view.popupEnabled = false;
        view.on("click", (event) =&amp;gt; {
          // Get the coordinates of the click on the view
          const lat = Math.round(event.mapPoint.latitude * 1000) / 1000;
          const lon = Math.round(event.mapPoint.longitude * 1000) / 1000;

          view.openPopup({
            // Set the popup's title to the coordinates of the location
            title: "Reverse geocode: [" + lon + ", " + lat + "]",
            location: event.mapPoint // Set the location of the popup to the clicked location
          });

          const params = {
            location: event.mapPoint
          };

          // Display the popup
          // Execute a reverse geocode using the clicked location
          locator
            .locationToAddress(locatorUrl, params)
            .then((response) =&amp;gt; {
              // If an address is successfully found, show it in the popup's content
              view.popup.content = response.address;
            })
            .catch(() =&amp;gt; {
              // If the promise fails and no result is found, show a generic message
              view.popup.content = "No address was found for this location";
            });
        });
      });
    &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;div id="instruction" class="esri-widget"&amp;gt;Click any location on the map to see its street address&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;</description>
      <pubDate>Thu, 18 Jan 2024 23:52:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/popup-overflows-on-first-click/m-p/1372004#M83394</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2024-01-18T23:52:56Z</dc:date>
    </item>
    <item>
      <title>Re: Popup overflows on first click</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/popup-overflows-on-first-click/m-p/1378962#M83589</link>
      <description>&lt;P&gt;Thanks for this! Worked great, I packaged it up into a little function:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Set the popup alignment based on the location of the popup
export function setPopupAlignment(view: SceneView | MapView) {
    reactiveUtils.watch(() =&amp;gt; view.popup?.id, function () {
        view.popup.alignment = function () {
            const { location, view } = this;

            if ((location) &amp;amp;&amp;amp; (view)) {
                const viewPoint = view.toScreen(location);
                const y2 = view.height / 2;
                const x2 = view.width / 3;
                const x3 = x2 * 2;

                if (viewPoint.y &amp;gt;= y2) {
                    if (viewPoint.x &amp;lt; x2)
                        return "top-right";
                    else if (viewPoint.x &amp;gt; x3)
                        return "top-left";
                } else {
                    if (viewPoint.x &amp;lt; x2)
                        return "bottom-right";
                    else if (viewPoint.x &amp;gt; x3)
                        return "bottom-left";
                    else
                        return "bottom-center";
                }
            }

            return "top-center";
        };
    });
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2024 06:56:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/popup-overflows-on-first-click/m-p/1378962#M83589</guid>
      <dc:creator>Clinton_Lunn</dc:creator>
      <dc:date>2024-02-07T06:56:44Z</dc:date>
    </item>
  </channel>
</rss>

