Select to view content in your preferred language

Change default symbology for Add Data widget in Dev

3223
8
Jump to solution
07-29-2019 01:27 PM
LeeAllen
Frequent Contributor

I'm looking to change the default symbol when using the "Add Data" widget.  I am using the developer edition, but can't find the code to set the symbol anywhere in the widget code. The default point icon  is way too small. Thanks!

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Lee,

   Here is what you will need to change.

\widgets\AddData\search\AddFromFilePane.js (added Lines 23-26 and 32)

define(["dojo/_base/declare",
    "dojo/_base/lang",
    "dojo/_base/array",
    "dojo/_base/json",
    "dojo/on",
    "dojo/Deferred",
    "dojo/dom-class",
    "dijit/Viewport",
    "dojo/sniff",
    "dijit/_WidgetBase",
    "dijit/_TemplatedMixin",
    "dijit/_WidgetsInTemplateMixin",
    "dojo/text!./templates/AddFromFilePane.html",
    "dojo/i18n!../nls/strings",
    "./LayerLoader",
    "./util",
    "dojo/_base/kernel",
    "esri/request",
    "esri/layers/FeatureLayer",
    "esri/layers/KMLLayer",
    "esri/geometry/scaleUtils",
    "jimu/dijit/Message",
    "esri/symbols/SimpleMarkerSymbol",
    "esri/renderers/SimpleRenderer",
    "esri/symbols/SimpleLineSymbol", 
    "esri/Color",
    "jimu/dijit/CheckBox"
  ],
  function(declare, lang, array, dojoJson, on, Deferred, domClass, Viewport, sniff,
    _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin,template, i18n,
     LayerLoader, util, kernel, esriRequest, FeatureLayer, KMLLayer, scaleUtils,
     Message, SimpleMarkerSymbol, SimpleRenderer, SimpleLineSymbol, Color) {
...

Same file (added 16 - 21)

...
      _addFeatures: function(job,featureCollection) {
        //var triggerError = null; triggerError.length;
        var fullExtent, layers = [], map = job.map, nLayers = 0;
        var loader = new LayerLoader();
        if (featureCollection.layers) {
          nLayers = featureCollection.layers.length;
        }
        array.forEach(featureCollection.layers,function(layer) {
          var featureLayer = new FeatureLayer(layer, {
            id: loader._generateLayerId(),
            outFields: ["*"]
          });
          featureLayer.xtnAddData = true;
          if (featureLayer.graphics) {
            if(featureLayer.graphics[0].geometry.type === "point"){
              featureLayer.renderer = new SimpleRenderer(new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE, 10,
                new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
                new Color([255,0,0]), 1),
                new Color([0,255,0,0.25])));
            }
            job.numFeatures += featureLayer.graphics.length;
          }
...

View solution in original post

8 Replies
RobertScheitlin__GISP
MVP Emeritus

Lee,

   Here is what you will need to change.

\widgets\AddData\search\AddFromFilePane.js (added Lines 23-26 and 32)

define(["dojo/_base/declare",
    "dojo/_base/lang",
    "dojo/_base/array",
    "dojo/_base/json",
    "dojo/on",
    "dojo/Deferred",
    "dojo/dom-class",
    "dijit/Viewport",
    "dojo/sniff",
    "dijit/_WidgetBase",
    "dijit/_TemplatedMixin",
    "dijit/_WidgetsInTemplateMixin",
    "dojo/text!./templates/AddFromFilePane.html",
    "dojo/i18n!../nls/strings",
    "./LayerLoader",
    "./util",
    "dojo/_base/kernel",
    "esri/request",
    "esri/layers/FeatureLayer",
    "esri/layers/KMLLayer",
    "esri/geometry/scaleUtils",
    "jimu/dijit/Message",
    "esri/symbols/SimpleMarkerSymbol",
    "esri/renderers/SimpleRenderer",
    "esri/symbols/SimpleLineSymbol", 
    "esri/Color",
    "jimu/dijit/CheckBox"
  ],
  function(declare, lang, array, dojoJson, on, Deferred, domClass, Viewport, sniff,
    _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin,template, i18n,
     LayerLoader, util, kernel, esriRequest, FeatureLayer, KMLLayer, scaleUtils,
     Message, SimpleMarkerSymbol, SimpleRenderer, SimpleLineSymbol, Color) {
...

Same file (added 16 - 21)

...
      _addFeatures: function(job,featureCollection) {
        //var triggerError = null; triggerError.length;
        var fullExtent, layers = [], map = job.map, nLayers = 0;
        var loader = new LayerLoader();
        if (featureCollection.layers) {
          nLayers = featureCollection.layers.length;
        }
        array.forEach(featureCollection.layers,function(layer) {
          var featureLayer = new FeatureLayer(layer, {
            id: loader._generateLayerId(),
            outFields: ["*"]
          });
          featureLayer.xtnAddData = true;
          if (featureLayer.graphics) {
            if(featureLayer.graphics[0].geometry.type === "point"){
              featureLayer.renderer = new SimpleRenderer(new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE, 10,
                new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
                new Color([255,0,0]), 1),
                new Color([0,255,0,0.25])));
            }
            job.numFeatures += featureLayer.graphics.length;
          }
...
LeeAllen
Frequent Contributor

Thank you Robert, works perfectly!

0 Kudos
ErfanGoharian
Occasional Contributor

Can you help me (or someone) help me to modify this code in a way that it shows the "polygon" with the red outline and none fill?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus
            if(featureLayer.graphics[0].geometry.type === "point"){
              featureLayer.renderer = new SimpleRenderer(new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE, 10,
                new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
                new Color([255,0,0]), 1),
                new Color([0,255,0,0.25])));
            }else if(featureLayer.graphics[0].geometry.type === "polygon"){
              featureLayer.renderer = new SimpleRenderer(new SimpleFillSymbol(SimpleFillSymbol.STYLE_NULL,
                new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
                new Color([255,0,0]), 1),
                new Color([0,0,0,0])));
            }
ErfanGoharian
Occasional Contributor

THANKS!

Is there a way to also add some coordination (like coordination of shapefile vertices or centroid) of the uploaded shapefile?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

sorry that is a bit beyond the context of this thread.

0 Kudos
abureaux
MVP Frequent Contributor

I am trying this out, but am getting this when I add a test file to the widget to load:

There was an issue.

I.set is not a function

Has anyone encountered this? Currently looking for a solution. Will let you know if I find one.

Edit: This is with WAB 2.20 and a GEOjson file which was not present in 2.12. I will work with AddFromFilePane.js from 2.12 and see if I can get that to work.

0 Kudos
JoeCatanzarita
Emerging Contributor

Hey there -- wondering if you've found a solution to this? I'm currently running into the same issue. Looking at the possibility of using PictureMarker instead of SimpleSymbol but would prefer a symbol over a picture. 

 

@RobertScheitlin__GISP Curious if you might have encountered the above error before?

 

EDIT: Was able to figure out the e.set is not a function error. It had to do with the order in which libraries were defined at the top of the script.

Prior order (failure): CheckBox, SimpleMarkerSymbol, SimpleRenderer, SimpleLineSymbol, Color.

Current Order (succes): SimpleMarkerSymbol, SimpleRenderer, SimpleLineSymbol, Color, CheckBox

0 Kudos