Select to view content in your preferred language

Generating featurelayer from esriJson

761
2
06-20-2017 04:31 AM
BjörnPaulström
Deactivated User

Hello, I am having some problems with the esriJson format, I tried replacing the javascript new SimpleRenderer with esriJson but I get an error:

"Uncaught (in promise) TypeError: f.getSymbol is not a function"

However when i create it with javascript it works. I actually want to create a PictureMarker with esrijson but i thought i would start simple with a cricle. Please help me locate the problem.

var template = {
   title: "<font color='black'>Basestation ID: {idBasestation}</font>",
   content: "Hello: {idBasestationData}",
};

var graphics = [
{
   geometry: new Point({
      x: -100,
      y: 38
   }),
   attributes: {
      idBasestationData : 3,
      idBasestation: 3000,
   }
}];

var lyr = new FeatureLayer({
   fields: [
   {
      name: "idBasestationData",
      alias: "idBasestationData",
      type: "oid"
   }, {
      name: "idBasestation",
      alias: "idBasestation",
      type: "integer"
   }],
   objectIdField: "ObjectID",
   geometryType: "point",
   spatialReference: { wkid: 4326 },
   source: graphics,
   renderer:
   {
      type: "simple",
      symbol:
      {
         type: "esriSMS",
         style: "esriSMSCircle",
         color: [255,0,0,255],
         size: 5,
         angle: 0,
         xoffset: 0,
         yoffset: 0,
         outline:
         {
            color: [0,0,0,255],
            width: 1
         },
      },
      label: "",
      description: "",
      rotationType: "geographic",
      rotationExpression: 0

   },
   popupTemplate: template
});

/* If I use the code below it works

renderer : new SimpleRenderer({
   symbol: new PictureMarkerSymbol({
      url: "https://webapps-cdn.esri.com/Apps/MegaMenu/img/logo.jpg",
      width: "30px",
      height: "30px"
   })
})
*/

map.add(lyr);
});

0 Kudos
2 Replies
ThomasSolow
Frequent Contributor

It looks to me like the renderer JSON is not automatically being used to construct a new instance of esri/renderers/SimpleRenderer.  This needs to happen (although technically you may be able to add a .getSymbol function to your renderer JSON and have it work fine, I would not recommend this).  I'm not sure if it matters whether you make the call to create a new renderer or if the API is smart enough to recognize that it needs to make the call.

If you're starting from JSON, you can use SimpleRenderer.fromJSON(<renderer JSON>) in the 4.XX API or new SimpleRenderer(<renderer JSON>) in the 3.XX API.

0 Kudos
thejuskambi
Frequent Contributor

Which version of the api are you using?

You could a always use the json to create the renderer like below

renderer: new SimpleRenderer({
    "type": "simple",
    "label": "",
    "description": "",
    "symbol": {
      "color": [210,105,30,191],
      "size": 6,
      "angle": 0,
      "xoffset": 0,
      "yoffset": 0,
      "type": "esriSMS",
      "style": "esriSMSCircle",
      "outline": {
        "color": [0,0,128,255],
        "width": 0,
        "type": "esriSLS",
        "style": "esriSLSSolid"
      }
    }
  })

Make sure all the properties provided are valid, otherwise they will be ignored.

0 Kudos