Javascript API attribution widget copyright text

2702
5
Jump to solution
10-18-2017 03:00 AM
JohnFannon
Occasional Contributor III

I've recently used the javascript API (4.5) and found that the default attribution widget only picks up copyright text from the basemap. However, if feature services displayed require copyright to be displayed, then the attribution widget does not currently pick up the copyright text from feature layers included in the map, despite these being populated in the service definition.

It does not appear possible to update the copyright text through code as this is read only, so does anyone know how to go about showing the copyright text in the existing widget? Or do I need to write my own?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

John,

   OK, here is a way to manually add text to the maps attribution:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>FeatureLayer - 4.5</title>

  <link rel="stylesheet" href="https://js.arcgis.com/4.5/esri/css/main.css">
  <script src="https://js.arcgis.com/4.5/"></script>

  <style>
    html,
    body,
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  </style>

  <script>
    require([
        "esri/Map",
        "esri/views/MapView",

        "esri/layers/FeatureLayer",
        "dojo/query",
        "esri/core/watchUtils",
        "dojo/domReady!"
      ],
      function(
        Map, MapView,
        FeatureLayer,
        dojoQuery,
        watchUtils
      ) {

        var map = new Map({
          basemap: "hybrid"
        });

        var view = new MapView({
          container: "viewDiv",
          map: map,

          extent: { // autocasts as new Extent()
            xmin: -9177811,
            ymin: 4247000,
            xmax: -9176791,
            ymax: 4247784,
            spatialReference: 102100
          }
        });

        /********************
         * Add feature layer
         ********************/

        // Carbon storage of trees in Warren Wilson College.
        var featureLayer = new FeatureLayer({
          url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0"
        });
        featureLayer.watch("loaded", function(){
          watchUtils.whenFalseOnce(view, "updating", function(){
             var attribs = dojoQuery(".esri-attribution__sources")[0];
             console.info(attribs);
             attribs.innerHTML += " Blah Blah";
          });
        });

        map.add(featureLayer);

      });
  </script>
</head>

<body>
  <div id="viewDiv"></div>
</body>

</html>

View solution in original post

5 Replies
RobertScheitlin__GISP
MVP Emeritus

John,

   When using this sample and toggling the "US Demographics" layer visibility, I see that the attribution on the map update automatically.

ArcGIS API for JavaScript Sandbox 

0 Kudos
JohnFannon
Occasional Contributor III

Hi Robert

Thanks, but the sample you reference only includes MapImageLayers and not feature layers. I have a basemap plus feature layers from an ArcGIS online feature service and the copyright text from the feature service definition doesn't display in the default attribution widget.

John

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

John,

   OK, here is a way to manually add text to the maps attribution:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>FeatureLayer - 4.5</title>

  <link rel="stylesheet" href="https://js.arcgis.com/4.5/esri/css/main.css">
  <script src="https://js.arcgis.com/4.5/"></script>

  <style>
    html,
    body,
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  </style>

  <script>
    require([
        "esri/Map",
        "esri/views/MapView",

        "esri/layers/FeatureLayer",
        "dojo/query",
        "esri/core/watchUtils",
        "dojo/domReady!"
      ],
      function(
        Map, MapView,
        FeatureLayer,
        dojoQuery,
        watchUtils
      ) {

        var map = new Map({
          basemap: "hybrid"
        });

        var view = new MapView({
          container: "viewDiv",
          map: map,

          extent: { // autocasts as new Extent()
            xmin: -9177811,
            ymin: 4247000,
            xmax: -9176791,
            ymax: 4247784,
            spatialReference: 102100
          }
        });

        /********************
         * Add feature layer
         ********************/

        // Carbon storage of trees in Warren Wilson College.
        var featureLayer = new FeatureLayer({
          url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0"
        });
        featureLayer.watch("loaded", function(){
          watchUtils.whenFalseOnce(view, "updating", function(){
             var attribs = dojoQuery(".esri-attribution__sources")[0];
             console.info(attribs);
             attribs.innerHTML += " Blah Blah";
          });
        });

        map.add(featureLayer);

      });
  </script>
</head>

<body>
  <div id="viewDiv"></div>
</body>

</html>
JohnFannon
Occasional Contributor III

Thanks Robert - I've been working on something similar this morning. My version gets the copyright string by making a request to each unique service url as the layers load, then updates the attribution text as in your example. 

I'm still testing it, but it appears to be working.

It would really help if Esri's documentation was clearer on exactly where the copyright text is derived from for the attribution widget. 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Glad to help. Have sure to mark this question as answered.

0 Kudos