AnsweredAssumed Answered

create symbology from json not working correctly

Question asked by casti on Apr 10, 2015
Latest reply on Apr 13, 2015 by casti

I am trying to apply some symbology form a Json like string. I have a point, polyline and polygon datasets and only the polyline and polygon layers are getting symbolized, although not like defined in the Json. So, my guess is that I am doing something really wrong.

Here is the code, in case someone can point me in the right direction.

Thanks!

 

function getSimpleRenderer(tmpLayer) {  
            var jsonSymbologies = {};
            jsonSymbologies.subs_point = '{"color":[250,0,250,255],"size":12,"angle":-30,"xoffset":0,"yoffset":0,"type":"esriSMS","style":"esriSMSCircle","outline":{"color":[255,0,0,255],"width":1,"type":"esriSLS","style":"esriSLSSolid"}}';
            jsonSymbologies.trans_polyline = '{"color": [0,255,0,255], "width": 1, "type": "esriSLS", "style": "esriSLSLongDashDot"}';
            jsonSymbologies.region_polygon = '{"color": [255,0,0,255], "type": "esriSFS","style": "esriSFSSolid", "outline": {"color":  [230,230,230,255], "width": 0.5, "type": "esriSLS", "style": "esriSLSDashDot"}}';
            jsonSymbologies.buildable_polygon = '{"color": [255,255,0,255], "type": "esriSFS","style": "esriSFSSolid", "outline": {"color":  [230,230,230,255], "width": 0.5, "type": "esriSLS", "style": "esriSLSDashDot"}}';


            var layerSemanticTypes = ["subs", "trans", "region", "buildable"];


            var nameParts = tmpLayer.split("_");


            // reduce the synonyms in the semantic types
            var nameSemantic = nameParts[0].toLowerCase();
            arrayUtils.some(layerSemanticTypes, function (dictSemanticType) {
                if (nameSemantic.indexOf(dictSemanticType) > -1) {
                    nameSemantic = dictSemanticType;
                    return false;
                }
            });


            // reduce the synonyms in the geometry types
            var nameGeom = tmpLayer.split("_")[nameParts.length - 1].toLowerCase();
            if (nameGeom === "pnt") {
                nameGeom = "point";
            } else if (nameGeom === "line") {
                nameGeom = "polyline";
            }


            // get the appropiate renderer
            var symbol;
            var baseSymbol;
            var tmpJson;


            if (nameGeom === "point") {
                tmpJson = JSON.parse(jsonSymbologies[nameSemantic + "_point"]);
                baseSymbol = symbolJsonUtils.fromJson(tmpJson);
                symbol = new SimpleMarkerSymbol(baseSymbol)
            } else if (nameGeom === "polyline") {
                tmpJson = JSON.parse(jsonSymbologies[nameSemantic + "_polyline"]);
                baseSymbol = symbolJsonUtils.fromJson(tmpJson)
                symbol = new SimpleLineSymbol(baseSymbol)
            } else if (nameGeom === "polygon") {
                tmpJson = JSON.parse(jsonSymbologies[nameSemantic + "_polygon"]);
                baseSymbol = symbolJsonUtils.fromJson(tmpJson)
                symbol = new SimpleFillSymbol()
            }else{
                console.log(nameGeom + " is an undefined geometry type!");
                return false;
            }
            return new SimpleRenderer(symbol);
        }

Outcomes