Control Layer reality

Source: Internet
Author: User

Bytes -------------------------------------------------------------------------------------------------------------

Method 1:

Bytes -------------------------------------------------------------------------------------------------------------

/// <Summary>
/// Control whether the layer is displayed
/// </Summary>
/// <Param name = "strlayername"> layer name </param>
/// <Param name = "blchecked"> show layer </param>
/// <Param name = "map1"> map control </param>
Public void layercheck (string strlayername, bool blchecked, map map1)
{

Imapfunctionality mf = map1.getfunctionality ("NorthAmerica") as imapfunctionality;
Igisresource gisresource = mf. resource;


Iqueryfunctionality qfunc = NULL;
Qfunc = (iqueryfunctionality) gisresource. createfunctionality (typeof (iqueryfunctionality), null );

String [] lids;
String [] lnames;
// Obtain the ID and name of all layers
Qfunc. getqueryablelayers (null, out lids, out lnames );

Int layer_index = 0;
For (INT I = 0; I <lnames. length; I ++)
{
// Find the required layer number
If (lnames= Strlayername)
{
Layer_index = I;
Break;
}
}
If (strlayername! = String. Empty)
{
Mf. setlayervisibility (layer_index.tostring (), blchecked );
}
Map1.refresh ();
}

Bytes -------------------------------------------------------------------------------------------------------------

Method 2:

-----------------------------------------------------------------------------------------------

ArcGIS Server development-control whether the layer is visible

You can use
Imapdescription mapdescription = webmap. mapdescription;
Webmap. managelifetime (mapdescription );

Ilayerdescriptions layerdec = mapdescription. layerdescriptions;

For (INT I = 0; I <mapdescription. layerdescriptions. Count; I ++)
{
Ilayerdescription onelayerdesc = layerdec. get_element (I );
Onelayerdesc. Visible = true;
}

-----------------------------------------------------------------------------------------------

Method 3:

-----------------------------------------------------------------------------------------------

The premise of reading this article is to read CJ's "Custom functionality ".

This article is about how to customize the display layer. As we all know, map is composed of layers. Several maps in the same region are actually composed of only a limited number of layers. By combining these layers, We can display the relevant maps. There are two prerequisites for doing so:
1. Know the list of layers composed of a map;
2. Know the MAP range;

In this way, we can pass in the layer list and MAP range from the outside to display the map we want to see.
With the following code, we can understand:
1. How to display the layers we want from all the layers of a map service; (as mentioned in a CJ article, I just changed it)
2. How to obtain the attributes in the session in the Web ADF. The method for obtaining a session in JSF does not work. Only the external context

package com.brsc;

import com.esri.adf.web.ags.data.AGSMapFunctionality;
………………
public class CustomLayerFunctionality implements GISFunctionality {
       private ArrayList layerList;
       private AGSMapResource resource;
       //
       public void destroyFunctionality() {
              // TODO Auto-generated method stub

       }

       public GISResource getResource() {
              // TODO Auto-generated method stub
              return null;
       }

Public void initfunctionality (gisresource arg0 ){
Try {
// Obtain the arraylist of layers from the session object
Facescontext cxt = webutil. getfacescontext ();
If (cxt = NULL ){
Return;
}
Externalcontext excxt = cxt. getexternalcontext ();
If (excxt = NULL ){
Return;
}
Java. util. Map layersessionmap = excxt. getsessionmap ();
Layerlist = (arraylist) layersessionmap. Get ("layerlist ");
//
This. Resource = (agsmapresource) arg0;
Agsmapfunctionality mapfunc = (agsmapfunctionality) resource. getfunctionality ("map ");
Mapserverinfo serverinfo = mapfunc. getmapserverinfo ();
// Rotation Angle of the image
// Serverinfo. getdefamapmapdescription (). setrotation (60 );
// Create a required Layer
Serverinfo. getdefamapmapdescription (). setlayerdescriptions (createnewlayerdescription (layerlist, serverinfo ));
// Set the MAP range
Hashmap hmap = (hashmap) layersessionmap. Get ("mapenvelope ");
If (hmap = NULL ){
Return;
}
Webextent ext = mapfunc. getfullextent ();
//
Double Minx = (double) hmap. Get ("Minx"). doublevalue ();
Double miny = (double) hmap. Get ("miny"). doublevalue ();
Double Maxx = (double) hmap. Get ("Maxx"). doublevalue ();
Double Maxy = (double) hmap. Get ("Maxy"). doublevalue ();
// Determine whether the value is within the MAP range
Webpoint pmin = new webpoint (Minx, miny );
Webpoint Pmax = new webpoint (Maxx, Maxy );
If (! Ext. Contains (pmin )){
Return;
}
If (! Ext. Contains (Pmax )){
Return;
}
Ext. setminx (Minx );
Ext. setminy (miny );
Ext. setmaxx (Maxx );
Ext. setmaxy (Maxy );
// Set the initial range
Mapfunc. setfullextent (EXT );
Mapfunc. setinitialextent (EXT );
} Catch (exception ex ){
Ex. printstacktrace ();
}
}
/**
* Create a New layerdescription Based on the layer list in the session.
* @ Param layerlist layer list
* @ Param serverinfo
* @ Return layerdescription []
*/
Private layerdescription [] createnewlayerdescription (arraylist layerlist, mapserverinfo serverinfo ){
Maplayerinfo [] oldlayerinfos = serverinfo. getmaplayerinfos ();
Maplayerinfo [] maplayerinfos = new maplayerinfo [layerlist. Size ()];
For (INT I = 0; I <maplayerinfos. length; I ++ ){
Maplayerinfos = agsutil. getlayerinfo (string) layerlist. Get (I), oldlayerinfos );
}
Serverinfo. setmaplayerinfos (maplayerinfos );
//
Layerdescription [] oldlayerdes = serverinfo. getdefamapmapdescription (). getlayerdescriptions ();
Layerdescription [] layerdescriptions = new layerdescription [maplayerinfos. Length];
For (Int J = 0; j <layerdescriptions. length; j ++ ){
Layerdescriptions [J] = agsutil. getlayerdescription (maplayerinfos [J]. getlayerid (), oldlayerdes );
}
Return layerdescriptions;
}
//
Public arraylist getlayerlist (){
Return layerlist;
}

       public void setLayerList(ArrayList layerList) {
              this.layerList = layerList;
       }

}

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.