Display and hide of ArcGIS API for Silverlight dynamic layer (arcgisdynamicmapservicelayer)

Source: Internet
Author: User

Here, the arcgisdynamicmapservicelayer Service released by ArcGIS Server is controlled. The ListBox below loads all service layers and dynamically controls the display of one or more layers by selecting the check box. The main code is as follows:

<esri:ArcGISDynamicMapServiceLayer ID="MyLayer"  Url="http://192.168.0.89/arcgis/rest/services/AnHuiMap/MapServer/"  Initialized="MyLayer_Initialized" />

<! -- Layer Control --> <! -- <Grid horizontalalignment = "right" margin = "0,260, 209" width = "200" Height = "" verticalalignment = "TOP"> <grid. rowdefinitions> <rowdefinition Height = "0.205 *"/> <rowdefinition Height = "0.795 *"/> </grid. rowdefinitions> <grid. columndefinitions> <columndefinition width = "0.837 *"/> <columndefinition width = "0.163 *"/> </grid. columndefinitions> <border X: Name = "bshowpiccontrol" borderthickness = "1" cursor = "hand" margin = "1, 0, 1" grid. column = "1" width = "33" mouseleftbuttondown = "bshowpiccontrol_mouseleftbuttondown" mouseleftbuttonup = "bshowpiccontrol_mouseleftbuttonup" Height = "34"> <border. background> <imagebrush imagesource = "images/layer_control.png" stretch = "NONE"/> </border. background> <tooltipservice. tooltip> <textblock fontsize = "13.333" fontfamily = "Microsoft yahei"> graphic layer control </textblock> </tooltipservice. tooltip> </Border> <grid X: Name = "grid_control" margin = "0, 1, 0" grid. rowspan = "2" width = "175" Height = "199" visibility = "Collapsed"> <grid Height = "34" background = "# fff3f3" margin = "0" Width = "174" verticalalignment = "TOP" D: layoutoverrides = "height"> <border borderbrush = "# ff0e529b" borderthickness = "1" cornerradius = "5" Height = "34" width = "174"> <stackpanel orientation =" horizontal "width =" 164 "Height =" 32 "> <checkbox X: name = "cb_zm" content = "site name" margin =, 14.667 "width =" 54 "fontsize =" "cursor =" hand "fontfamily =" Microsoft yahei "verticalignment =" center "horizontalalignment =" center "Height =" 18 "Checked = ""cb_zm_checked" unchecked = "cb_zm_unchecked"/> <radiobutton X: name = "V1" width = "54" margin = "14.667" ischecked = "true" fontsize = "" content = "data" Height = "18" groupname = "gn_group "cursor =" hand "fontfamily =" Microsoft yahei "horizontalalignment =" center "verticalignment =" center "Click =" rb_click "/> <radiobutton X: name = "Rb2" width = "54" margin = "14.667" fontsize = "" content = "site code" groupname = "gn_group" cursor = "hand" fontfamily = "Microsoft yahei "horizontalalignment =" center "verticalignment =" center "Click =" rb_click "Height =" 18 "/> </stackpanel> </Border> </GRID> <border Height = "163" margin =, 0, 0 "width =" 175 "D: layoutoverrides =" gridbox "borderbrush =" # ff0e529b "cornerradius =" 5 "borderthickness =" 1 "> <ListBox itemssource =" {binding layers. [mylayer]. layers, elementname = mymap} "borderbrush =" {X: null} "fontsize =" 13.333 "fontfamily =" Microsoft yahei "width =" 173 "Height =" 161 "> <ListBox. itemtemplate> <datatemplate> <checkbox margin = "2" X: name = "mylayer" content = "{binding name}" ischecked = "{binding defadefavisibility}" tag = "{binding ID}" clickmode = "Press" Click = "checkbox_click "/> </datatemplate> </ListBox. itemtemplate> </ListBox> </Border> </GRID> -->

# Region layer control display and hide private void mylayer_initialized (Object sender, eventargs e) {ESRI. arcGIS. client. arcgisdynamicmapservicelayer dynamicservicelayer = sender as ESRI. arcGIS. client. arcgisdynamicmapservicelayer; If (dynamicservicelayer. visiblelayers = NULL) dynamicservicelayer. visiblelayers = getdefaultvisiblelayers (dynamicservicelayer);} private int [] getdefavisvisiblelayers (ESRI. arcGIS. client. arc Gisdynamicmapservicelayer dynamicservice) {list <int> visiblelayeridlist = new list <int> (); ESRI. arcGIS. client. layerinfo [] layerinfoarray = dynamicservice. layers; For (INT Index = 0; index <layerinfoarray. length; index ++) {If (layerinfoarray [Index]. defaultvisibility) visiblelayeridlist. add (INDEX);} return visiblelayeridlist. toarray ();} private void checkbox_click (Object sender, routedeventargs E) {checkbox tickedcheckbox = sender as checkbox; string servicename = tickedcheckbox. name; bool visible = (bool) tickedcheckbox. ischecked; int layerindex = (INT) tickedcheckbox. tag; ESRI. arcGIS. client. arcgisdynamicmapservicelayer dynamicservicelayer = mymap. layers [servicename] as ESRI. arcGIS. client. arcgisdynamicmapservicelayer; List <int> visiblelayerlist = dynamicservicelayer. visiblelayers! = NULL? Dynamicservicelayer. visiblelayers. tolist (): new list <int> (); If (visible) {If (! Visiblelayerlist. contains (layerindex) visiblelayerlist. add (layerindex);} else {If (visiblelayerlist. contains (layerindex) visiblelayerlist. remove (layerindex);} dynamicservicelayer. visiblelayers = visiblelayerlist. toarray () ;}# endregion

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.