<?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 If, Else Popups in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/if-else-popups/m-p/1236398#M79491</link>
    <description>&lt;P&gt;Hi all&lt;/P&gt;&lt;P&gt;I'd like my map to display two different popups. 'If' I click on the feature layer it return the popup related to that layer, 'Else' if I click anywhere other than the feature it returns a different popup.&lt;/P&gt;&lt;P&gt;I currently have two separate maps , each with their own different type of popup.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. On this map you only return a popup if you hit the feature (street line): this has a customContent template directly related to the feature layer. Clicking anywhere else nothing is returned.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const customContent = new CustomContent({
              outFields: ["*"],
              creator: (event) =&amp;gt; {
              const location = view.popup.location;
              const locationContent = `X: ${location.x.toFixed(0)}&amp;lt;br&amp;gt;Y: ${location.y.toFixed(0)}&amp;lt;br&amp;gt;`;
              const name = `&amp;lt;font size='3px'&amp;gt;&amp;lt;b&amp;gt;Street:&amp;lt;/b&amp;gt; ${event.graphic.attributes["SITE_NAME"]}&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Town:&amp;lt;/b&amp;gt; ${event.graphic.attributes["TOWN_NAME"]}&amp;lt;br&amp;gt;`;
              const link = `&amp;lt;br&amp;gt;&amp;lt;a href=\"https://east-riding-self.test.achieveservice.com/service/Dangerous_building_or_structure_issue?` +
 `street=${event.graphic.attributes["SITE_NAME"]}&amp;amp;town=${event.graphic.attributes["TOWN_NAME"]}&amp;amp;USRN=${event.graphic.attributes["SITE_CODE"]}&amp;amp;Easting=${location.x.toFixed(0)}&amp;amp;Northing=${location.y.toFixed(0)}"` +
			          ` rel="nofollow ugc" style="display: block; height: 60px; width: 242px; background: #CC5500; color: #ffffff; text-align: center; font-weight: bold; font-size: 140%; line-height: 60px; padding: 7px;  font-family: Arial; border-radius: 8px; text-decoration: none;"&amp;gt;Report a traffic safety concern&amp;lt;/a&amp;gt;`;
                
              return name + link;
              },
           });
            
            const template = new PopupTemplate({
                outFields: ["*"],
                content: [customContent],
            });
                
        const streetLayer = new FeatureLayer({
          url: "https://services6.arcgis.com/Qptn479QktK11k72/arcgis/rest/services/New_Achieve_Streets_layer/FeatureServer/0",
          outFields: ["*"],
          });
          
       streetLayer.maxScale=350;
       streetLayer.minScale=2500;
       streetLayer.popupTemplate = template;
          map.add(streetLayer);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. On this map you can click anywhere and it returns the popup (it never interacts with the feature layer).&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;view.popup.autoOpenEnabled = false;
      view.on("click", (event) =&amp;gt; {
      if (view.scale &amp;lt;= 2500) {
      const x = Math.round(event.mapPoint.x * 1) / 1;
      const y = Math.round(event.mapPoint.y * 1) / 1;
      
      view.popup.open({
      content: `&amp;lt;a href=\"https://east-riding-self.test.achieveservice.com/service/Fly_posting_or_illegal_signs?` + `Easting=${x}&amp;amp;Northing=${y}"` + `target="_blank" rel="nofollow ugc" style="display: block; height: 60px; width: 242px; background: #CC5500; color: #ffffff; text-align: center; font-weight: bold; font-size: 160%; line-height: 60px; padding: 6px;  font-family: Arial; border-radius: 7px; text-decoration: none;"&amp;gt;Report fly-posting or an illegal sign&amp;lt;/a&amp;gt;`,
    location: event.mapPoint
      });
      }
      });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried putting the two sets of code onto the same map. However the '2' code (click anywhere) just seems to override everything and if I click on the feature (street layer) it just displays the 2nd popup.&lt;BR /&gt;&lt;BR /&gt;I'm guessing I need a, 'If' you hit the feature display that popup, 'Else' display the click anywhere popup.&lt;BR /&gt;&lt;BR /&gt;How do I go about this please? My attempts have failed.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks Ricky&lt;/P&gt;</description>
    <pubDate>Wed, 30 Nov 2022 15:44:43 GMT</pubDate>
    <dc:creator>ITApplications</dc:creator>
    <dc:date>2022-11-30T15:44:43Z</dc:date>
    <item>
      <title>If, Else Popups</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/if-else-popups/m-p/1236398#M79491</link>
      <description>&lt;P&gt;Hi all&lt;/P&gt;&lt;P&gt;I'd like my map to display two different popups. 'If' I click on the feature layer it return the popup related to that layer, 'Else' if I click anywhere other than the feature it returns a different popup.&lt;/P&gt;&lt;P&gt;I currently have two separate maps , each with their own different type of popup.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. On this map you only return a popup if you hit the feature (street line): this has a customContent template directly related to the feature layer. Clicking anywhere else nothing is returned.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const customContent = new CustomContent({
              outFields: ["*"],
              creator: (event) =&amp;gt; {
              const location = view.popup.location;
              const locationContent = `X: ${location.x.toFixed(0)}&amp;lt;br&amp;gt;Y: ${location.y.toFixed(0)}&amp;lt;br&amp;gt;`;
              const name = `&amp;lt;font size='3px'&amp;gt;&amp;lt;b&amp;gt;Street:&amp;lt;/b&amp;gt; ${event.graphic.attributes["SITE_NAME"]}&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Town:&amp;lt;/b&amp;gt; ${event.graphic.attributes["TOWN_NAME"]}&amp;lt;br&amp;gt;`;
              const link = `&amp;lt;br&amp;gt;&amp;lt;a href=\"https://east-riding-self.test.achieveservice.com/service/Dangerous_building_or_structure_issue?` +
 `street=${event.graphic.attributes["SITE_NAME"]}&amp;amp;town=${event.graphic.attributes["TOWN_NAME"]}&amp;amp;USRN=${event.graphic.attributes["SITE_CODE"]}&amp;amp;Easting=${location.x.toFixed(0)}&amp;amp;Northing=${location.y.toFixed(0)}"` +
			          ` rel="nofollow ugc" style="display: block; height: 60px; width: 242px; background: #CC5500; color: #ffffff; text-align: center; font-weight: bold; font-size: 140%; line-height: 60px; padding: 7px;  font-family: Arial; border-radius: 8px; text-decoration: none;"&amp;gt;Report a traffic safety concern&amp;lt;/a&amp;gt;`;
                
              return name + link;
              },
           });
            
            const template = new PopupTemplate({
                outFields: ["*"],
                content: [customContent],
            });
                
        const streetLayer = new FeatureLayer({
          url: "https://services6.arcgis.com/Qptn479QktK11k72/arcgis/rest/services/New_Achieve_Streets_layer/FeatureServer/0",
          outFields: ["*"],
          });
          
       streetLayer.maxScale=350;
       streetLayer.minScale=2500;
       streetLayer.popupTemplate = template;
          map.add(streetLayer);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. On this map you can click anywhere and it returns the popup (it never interacts with the feature layer).&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;view.popup.autoOpenEnabled = false;
      view.on("click", (event) =&amp;gt; {
      if (view.scale &amp;lt;= 2500) {
      const x = Math.round(event.mapPoint.x * 1) / 1;
      const y = Math.round(event.mapPoint.y * 1) / 1;
      
      view.popup.open({
      content: `&amp;lt;a href=\"https://east-riding-self.test.achieveservice.com/service/Fly_posting_or_illegal_signs?` + `Easting=${x}&amp;amp;Northing=${y}"` + `target="_blank" rel="nofollow ugc" style="display: block; height: 60px; width: 242px; background: #CC5500; color: #ffffff; text-align: center; font-weight: bold; font-size: 160%; line-height: 60px; padding: 6px;  font-family: Arial; border-radius: 7px; text-decoration: none;"&amp;gt;Report fly-posting or an illegal sign&amp;lt;/a&amp;gt;`,
    location: event.mapPoint
      });
      }
      });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried putting the two sets of code onto the same map. However the '2' code (click anywhere) just seems to override everything and if I click on the feature (street layer) it just displays the 2nd popup.&lt;BR /&gt;&lt;BR /&gt;I'm guessing I need a, 'If' you hit the feature display that popup, 'Else' display the click anywhere popup.&lt;BR /&gt;&lt;BR /&gt;How do I go about this please? My attempts have failed.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks Ricky&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 15:44:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/if-else-popups/m-p/1236398#M79491</guid>
      <dc:creator>ITApplications</dc:creator>
      <dc:date>2022-11-30T15:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: If, Else Popups</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/if-else-popups/m-p/1236518#M79500</link>
      <description>&lt;P&gt;If you had the features in the same map, you could search the View's onclick for any graphics related to one layer, and if they exist, only show the popup for that layer (by only gathering up the features for that layer). Then, if features weren't found for that layer, you could use those for that feature's popup (by only passing the features for that layer).&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is how I'd approach it:&lt;/P&gt;&lt;LI-CODE lang="javascript"&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 FeatureLayer | Sample | ArcGIS API for JavaScript 4.25&amp;lt;/title&amp;gt;

    &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.25/esri/themes/light/main.css" /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.25/"&amp;gt;&amp;lt;/script&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;script&amp;gt;
      require([
        "esri/Map", 
        "esri/views/MapView", 
        "esri/layers/FeatureLayer",
        "esri/PopupTemplate"], (Map, MapView, FeatureLayer, PopupTemplate) =&amp;gt; {
        const map = new Map({
          basemap: "hybrid"
        });

        const view = new MapView({
          container: "viewDiv",
          map: map,
          extent: {
            // autocasts as new Extent()
            xmin: -9177500,
            ymin: 4247200,
            xmax: -9176900,
            ymax: 4247600,
            spatialReference: 102100
          }
        });

        /********************
         * Add feature layer
         ********************/

        // Carbon storage of trees in Warren Wilson College.
        const treeLayer = new FeatureLayer({
          url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0",
          id: "treeLayer",
          popupTemplate: {
            title: "Trees Layer",
            content: [
              { type: "fields", // FieldsContentElement
                fieldInfos: [
                  { fieldName: "Tree_ID"},
                  { fieldName: "Collected"}
                ]
             }]
          }
        });
        
        const dTileLayer = new FeatureLayer({
          url: "https://services.arcgis.com/QCty4ZXRXx9qyVVL/arcgis/rest/services/Download_Tiles_Ashville_NC/FeatureServer/0",
          id: "dTileLayer",
          popupTemplate: {
            title: "Download Tiles Layer",
            content: [
              { type: "fields", // FieldsContentElement
                fieldInfos: [
                  { fieldName: "Name"},
                  { fieldName: "Path"}
                ]
             }]
          }
        });

        map.addMany([treeLayer, dTileLayer]);
        
        view.popup.autoOpenEnabled = false;
        
        
        view.on("immediate-click", (event) =&amp;gt; {
          view.hitTest(event).then((response) =&amp;gt; {
            let treeGraphics = response.results.filter(function (result) {
              return result.graphic.layer === treeLayer;
            });
            let dTileGraphics = response.results.filter(function (result) {
              return result.graphic.layer === dTileLayer;
            });
            
            var features2Use = [];
            if (treeGraphics.length &amp;gt; 0) {
              for (var i = 0; i &amp;lt; treeGraphics.length; i++) {
                features2Use.push(treeGraphics[i].graphic);
              }
            }
            else if (dTileGraphics.length &amp;gt; 0) {
              for (var i = 0; i &amp;lt; dTileGraphics.length; i++) {
                features2Use.push(dTileGraphics[i].graphic);
              }
            }
            view.popup.open({
             features: features2Use
            });
            
          });
        });
        
      });
    &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;</description>
      <pubDate>Wed, 30 Nov 2022 18:49:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/if-else-popups/m-p/1236518#M79500</guid>
      <dc:creator>JeffreyWilkerson</dc:creator>
      <dc:date>2022-11-30T18:49:51Z</dc:date>
    </item>
    <item>
      <title>Re: If, Else Popups</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/if-else-popups/m-p/1237693#M79552</link>
      <description>&lt;P&gt;Hi Jeffrey&lt;/P&gt;&lt;P&gt;Thank you for your advice. I've taken a look at what you have advised and I've managed to adapt if for what I require.&lt;/P&gt;&lt;P&gt;I only have one feature layer on my map and I needed to return its defined popup if the feature was interacted with, else just return a generic popup (that was just recording the X/Y of where a user clicked).&lt;BR /&gt;&lt;BR /&gt;This has worked for me.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;view.popup.autoOpenEnabled = false;
      
      view.on("click", (event) =&amp;gt; {
        if (view.scale &amp;lt;= 2500) {
          view.hitTest(event).then((response) =&amp;gt; {
            let streetGraphics = response.results.filter(function (result) {
              return result.graphic.layer === streetLayer;
            });
      
            var features2Use = [];
            if (streetGraphics.length &amp;gt; 0) {
              for (var i = 0; i &amp;lt; streetGraphics.length; i++) {
                features2Use.push(streetGraphics[i].graphic);
              }
            }
             view.popup.open({
             features: features2Use
            });
            });
        }
        });
      
      
      view.on("click", (event) =&amp;gt; {
      const x = Math.round(event.mapPoint.x * 1) / 1;
      const y = Math.round(event.mapPoint.y * 1) / 1;
      
      view.popup.open({
      content: `&amp;lt;a `Easting=${x}&amp;amp;Northing=${y}"` + `target="_blank" rel="nofollow ugc" style="display: block; height: 40px; width: 242px; background: #CC5500; color: #ffffff; text-align: center; font-weight: bold; font-size: 185%; line-height: 40px; padding: 6px;  font-family: Arial; border-radius: 7px; text-decoration: none;"&amp;gt;Click anywhere popup&amp;lt;/a&amp;gt;`,
    location: event.mapPoint
      });
      });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks for your help and advice, Ricky&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2022 11:38:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/if-else-popups/m-p/1237693#M79552</guid>
      <dc:creator>ITApplications</dc:creator>
      <dc:date>2022-12-05T11:38:15Z</dc:date>
    </item>
  </channel>
</rss>

