Custom icon switch to default after select and unselect feature in feature class

1394
10
Jump to solution
11-06-2017 11:48 PM
ZdeněkSoldán
Occasional Contributor

Hello,

I have some feature layers created in my code from feature collection. In the feature collection I have defined a default icon for this layer. Further in the code I change the icon for some features according some parameters. 

When I open Attribute Table widget with this layer and select the feature with different icon than default and after that unselect this feature it have default icon not the icon I defined for this feature. 

How can I preserve the defined icon in such cases?

Thanks a lot!

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Zdeněk,

   It sounds like you are setting the graphics symbol individually. If you use a unique value renderer instead you should not have this issue.

View solution in original post

10 Replies
RobertScheitlin__GISP
MVP Emeritus

Zdeněk,

   It sounds like you are setting the graphics symbol individually. If you use a unique value renderer instead you should not have this issue.

ZdeněkSoldán
Occasional Contributor

Hello Robert,

yes I'm. Can you explain me what do you mean with unique value renderer and how to use it? 

Thanks a lot

0 Kudos
ZdeněkSoldán
Occasional Contributor

Ok, I looked what is unique value renderer and it is not usable for me. I have png icons as a symbols and I need to use them.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Zdeněk,

   There is NO reason why you can not use png files in your implementation of a Unique value renderer.

0 Kudos
ZdeněkSoldán
Occasional Contributor

Robert,

I tried to implement Unique value renderer and I made some progress but still have some issue. In my Layer List widget it looks good. I have there all needed icons but in map there is nothing. No icons for my features.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Zdeněk,

   I would have to see your implementation of the UV renderer.

0 Kudos
ZdeněkSoldán
Occasional Contributor

Here it is.

startup: function () {
        this.inherited(arguments);
        var map = this.map;
        var SSZFeatureLayer;
var SSZFeatureCollection = {
          "layerDefinition": null,
          "featureSet": {
            "features": [],
            "geometryType": "esriGeometryPoint"
          }
        };
SSZFeatureCollection.layerDefinition = {
          "geometryType": "esriGeometryPoint",
          "objectIdField": "ObjectID",
          "spatialReference": {
            "wkid": 4326,
            "latestWkid": 4326
          },
          "drawingInfo": {
            "renderer": {
              "type": "simple",
              // "symbol": {
              //   "type": "esriPMS",
              //   "url": "images/traffic_lights_005826.svg",
              //   "contentType": "image/svg",
              //   "width": 17,
              //   "height": 17
              // }
            }
          },
          //"minScale":50000,
          "fields": [{
            "name": "ObjectID",
            "alias": "ObjectID",
            "type": "esriFieldTypeOID"
          }, {
            "name": "serialno",
            "alias": "ID zařízení",
            "type": "esriFieldTypeString"
          }, {
            "name": "desc",
            "alias": "Popis",
            "type": "esriFieldTypeString"
          }, {
            "name": "devtype",
            "alias": "Typ zařízení",
            "type": "esriFieldTypeString"
          }, {
            "name": "locality",
            "alias": "Lokalita",
            "type": "esriFieldTypeString"
          }, {
            "name": "street1",
            "alias": "Ulice 1",
            "type": "esriFieldTypeString"
          }, {
            "name": "street2",
            "alias": "Ulice 2",
            "type": "esriFieldTypeString"
          }, {
            "name": "timeStamp",
            "alias": "Zmena stavu",
            "type": "esriFieldTypeString"
          }, {
            "name": "color",
            "alias": "Barva",
            "type": "esriFieldTypeString"
          }]
        }
var devPopupTemplate = new PopupTemplate({
          title: "<b>Sériové číslo</b>: {serialno}",
          //descritpion: "<table><tr><th><b>Popis</b>:</th><th>{desc}</th></tr><tr><th><b>Typ zařízení</b>:</th><th>{devtype}</th></tr><tr><th><b>Lokalita</b>:</th><th>{locality}</th></tr><tr><th><b>Ulice 1</b>:</th><th>{street1}</th></tr><tr><th><b>Ulice 2</b>:</th><th>{street2}</th></tr></table>"
          description: "<b>Popis</b>: {desc} </br><b>Typ zařízení</b>: {devtype} </br><b>Lokalita</b>: {locality} </br><b>Ulice 1</b>: {street1} </br><b>Ulice 2</b>: {street2}</br><b>Zmena stavu</b>: {timeStamp} "
        });
SSZFeatureLayer = new FeatureLayer(SSZFeatureCollection, {
          id: 'SSZ',
          infoTemplate: devPopupTemplate,
          visible: false,
          showLabels: true,
          outFields: ["*"]
        })
var defaultSymbol = "images/traffic_lights_005826.svg"
        var renderer = new UniqueValueRenderer(defaultSymbol, "color");
        renderer.addValue("000000",new PictureMarkerSymbol("images/traffic_lights_000000.svg",17,17));
        renderer.addValue("0000A0",new PictureMarkerSymbol("images/traffic_lights_0000A0.svg",17,17));
        renderer.addValue("0000FF",new PictureMarkerSymbol("images/traffic_lights_0000FF.svg",17,17));
        renderer.addValue("7F7F7F",new PictureMarkerSymbol("images/traffic_lights_7F7F7F.svg",17,17));
        renderer.addValue("9E0B0E",new PictureMarkerSymbol("images/traffic_lights_9E0B0E.svg",17,17));
        renderer.addValue("005826",new PictureMarkerSymbol("images/traffic_lights_005826.svg",17,17));
        renderer.addValue("8000FF",new PictureMarkerSymbol("images/traffic_lights_8000FF.svg",17,17));
        renderer.addValue("F7901E",new PictureMarkerSymbol("images/traffic_lights_F7901E.svg",17,17));
        renderer.addValue("FF0000",new PictureMarkerSymbol("images/traffic_lights_FF0000.svg",17,17));
        renderer.addValue("FFF200",new PictureMarkerSymbol("images/traffic_lights_FFF200.svg",17,17));
        SSZFeatureLayer.setRenderer(renderer)

SSZFeatureLayer.on("click", function (evt) {
          map.infoWindow.setFeatures([evt.graphic]);
        });

map.on("layers-add-result", function (results) {
          requestDevices();
        });
map.addLayers([SSZFeatureLayer])

function requestDevices() { Function to request the data}
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Do not include:

          "drawingInfo": {
            "renderer": {
              "type": "simple",
              // "symbol": {
              //   "type": "esriPMS",
              //   "url": "images/traffic_lights_005826.svg",
              //   "contentType": "image/svg",
              //   "width": 17,
              //   "height": 17
              // }
            }
          },
          //"minScale":50000,

in your layerDefinition.

Is the values in your data's color field upper case like?

"7F7F7F"
ZdeněkSoldán
Occasional Contributor

Yes, data's color field is upper case. And I commented the whole part drawingInfo and still nothing in my map.

0 Kudos