ArcGIS Web apijavascript API4.6 generates Featurelayer and renders in the client browser

Source: Internet
Author: User

When you call a layer of a map service published on ArcGIS Sever, you need to render it based on a specific field, but the service you publish does not have that field, and you can use that method.

/******************************************************************************** **************************FeatureLaye r*********************************** *************************************************************************** *****///New FeaturelayerFeaturelayer.queryfeatures (). Then (function(results) {varfeatures =Results.features;  for(varFeatureinchfeatures) {features[feature].attributes["Nico"] =feature; }        varPopuptemplate ={title:' {NAME} ', Content: [{type:"Fields", Fieldinfos: [{fieldName:"Name"}, {fieldName:"FID"},{fieldName:"XZDM"},{fieldName:"Nico"        }]      }]    }; varFields =[{name:"XZDM", alias:"XZDM", type:"OID",},{name:"FID", alias:"FID", type:"Double",},{name:"Nico", alias:"Nico", type:"Integer",      }]; //See the Sample snippet for the source and fields propertiesConst LAYER =NewFeaturelayer ({source:features, fields:fields, Objectidfield:"XZDM",//field name of the Object IDsGeometrytype: "Polygon",    }); varRenderer ={type:"Simple",//autocasts as New Simplerenderer ()Symbol: {type: "Simple-fill"},//autocasts as New Simplefillsymbol ()visualvariables: [{type:"Color", field:"Nico", stops: [{value:0, color: {r:125, g:255, b:103, a:0.3}}, {value:One, color: {r:255, g:25, b:123, a:0.6} }]      }]    }; Layer.renderer=renderer;    Map.add (layer);}); 

Here are two types of classification rendering methods

First Kind

/******************************************************************************** **************************SimpleRende rer*********************************** ************************************************************************* *******///generate random color, equal spacing classification based on maximum minimum value and number of classificationsvarMinclassvalue = 0;varMaxclassvalue = 10;varClassnum = 4;vardis = Math.Round ((maxclassvalue-minclassvalue)/classnum);//Building stops ArraysvarStops =NewArray (); for(varI=minclassvalue; i<maxclassvalue; i + =dis) {        //building a Color object    varcolor =NewObject (); COLOR.R= parseint (Math.random () *100); COLOR.G= parseint (Math.random () *100); Color.b= parseint (Math.random () *100); COLOR.A= Math.Round (Math.random () *10)/10;//build with value and color Property objects    varA =NewObject (); A.value=i; A.color=color; Stops.push (a);}//SimplerenderervarCitiesRenderer01 ={type:"Simple",//autocasts as New Simplerenderer ()Symbol: {type: "Simple-fill"},//autocasts as New Simplefillsymbol ()visualvariables: [{type:"Color", field:"Nico", Stops:stops,}]};

The second Kind

/******************************************************************************** **************************ClassBreaks renderer*********************************** ******************************************************************** ************///generate random color, equal spacing classification based on maximum minimum value and number of classificationsvarMinclassvalue = 0;varMaxclassvalue = 10;varClassnum = 4;vardis = Math.Round ((maxclassvalue-minclassvalue)/classnum);//Building Classbreakinfos ArraysvarClassbreakinfos =NewArray (); for(varI=minclassvalue; i<maxclassvalue; i + =dis) {        //building a Color object    varcolor =NewObject (); COLOR.R= parseint (Math.random () *100); COLOR.G= parseint (Math.random () *100); Color.b= parseint (Math.random () *100); COLOR.A= Math.Round (Math.random () *10)/10;//to build a symbol object that contains the type and color properties    varSymbol =NewObject (); Symbol.type= "Simple-fill", Symbol.color=color; //build an Obj object that contains MinValue, MaxValue, symbol, label    varobj =NewObject (); Obj.minvalue=I, Obj.maxvalue= i +Dis, Obj.symbol=symbol; Obj.label= i + "~" + i +dis; Classbreakinfos.push (obj);}//ClassbreaksrenderervarCitiesRenderer01 ={type:"Class-breaks",//autocasts as New Classbreaksrenderer ()Field: "Nico", Classbreakinfos:classbreakinfos,};

ArcGIS Web apijavascript API4.6 generates Featurelayer and renders in the client browser

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.