layer对象

来源:互联网 发布:谭浩强c语言视频讲解 编辑:程序博客网 时间:2024/04/29 18:27

 

1,使用数据提供方定义图层

要将图层添加到layers集合中,必须先对其进行定义。数据提供方式定义图层的关键所在。

每一个图层都有一个内部对象用与访问图层数据,这个对象就是数据提供方。

数据提供方不是由用户创建的,但是其说明了定义了图层。以下三个接口用于说明数据提供方:

TableDescHelper-------------说明数据

DataProviderHelper----------定义数据源

DataProviderRef----------------说明如何获取数据

 

<1>添加图层的常规步骤

 

1,创建TableDescHelper对象

2,创建DataProviderHelper对象

3,创建DataProviderRef对象【需要DataProviderHelper作为输出】

DataProviderRef:有两个实现类,

1,  LocalDataProviderRef:应用程序将直接于数据源通信,这意味着应用程序必须可以使用访问数据源但是有资源,例如:JDBC驱动程序比保存在应用程序的classpath中,以便于直接访问RDBMS的数据

LocalDataProviderRef   localDPR=new LocalDataProviderRef(数据提供方);

//数据提供方是tabTableDescHelper 或者是OraSoTableDescHelper对象

2,  MapXtremeDataProviderRef:客户机借助mapxtremeServlet获取数据时将会使用MapXtremeDataProviderRef,通过mapxtremeServlet访问数据源,只需要在中间层进行数据库的访问,这样无需在客户机内部署JDBC驱动程序

 MapXtremeDataProviderRef   mxtDPR= MapXtremeDataProviderRef ( 数据提供方,mapxtremeURL);

 

<2>tab数据提供方示例:

以下是创建tabDataProvider并将图层指定给MAPJ

 

//参数:tab文件名

TABTableDescHelper tabTDHelper=new TABTableDescHelper("fujian.tab");

 

//参数:表目录路径

TABDataProviderHelper tabDPHelpet=new TABDataProviderHelper("d://fjcs//map");

 

String mapxtremeURL="http://localhost:8080/mapxtreme47/mapxtreme";

 

//参数:DataProviderHelper对象作为输出,mapxtreme servlet路径

MapXtremeDataProviderRef   mxtDPRef

=new MapXtremeDataProviderRef(tabDPHelprt,mapxtremeURL);

 

mapJ.getLayers.addLayer(mxtDPRef,tabTDHelper,"newLayer");//添加到最后面

 

mapJ.getLayers.insertLayer(mxtDPRef,tabTDHelper,0,"newLayer");//可以设置图层的位置,0表示最上面

 

TABTableDescHelper构造函数2

 

String table = "states_rend";

String rendCol = "LabelRendition";

RenditionType rendType = RenditionType.mapxtreme;

 

//参数:tab文件名,字段名【在这个表里面的一个字段】,渲染类型

//第二个参数的意思是说使用这个字段下面的数据进行渲染

TABTableDescHelper tabTDHelper = new TABTableDescHelper(table, rendCol, rendType);

OraSoTableDescHelper  的构造函数:

1 OraSoTableDescHelper   tableTDH=new  OraSoTableDescHelper(表名,false,主键数组,空间数据库名,渲染列,渲染类型,标签渲染列,渲染类型,坐标系统,地理规模,表所有者);

 

String host = "dbName";
int port = 1521;
String sid = "dbSid";
String usr = "mary";
String pwd = "mary123";
DriverType driverType = DriverType.thin;
String driver = "oracle.jdbc.driver.OracleDriver";
OraSoDataProviderHelper oraDPHelper = new OraSoDataProviderHelper(host, port, sid,
      usr, pwd, driverType, driver);
 
// Create a String array with the name(s) of the column(s) to use as a unique key for
// records in the table
String[] idColumns = {"mi_prinx"};//空间数据库中唯一的列名

 

String table = "states";
boolean bUseQuotes = false;
String spatialCol = "geoloc";
String rendCol = null;
RenditionType perFeatureType = RenditionType.none;
String labelRendCol = null;
RenditionType perFeatureLabelType = RenditionType.none;
CoordSys csys = CoordSys.longLatWGS84;//坐标系统基本不变
int dimensions = 2;//不变
String owner = "mary";
 
 
OraSoTableDescHelper tableTDH = new OraSoTableDescHelper(table, bUseQuotes, idColumns,
      spatialCol, rendCol, perFeatureType, labelRendCol, perFeatureLabelType, csys,
      dimensions, owner);
 
 

2 OraSoTableDescHelper   queryTDH=new  OraSoTableDescHelper(查询sql,false,主键数组,空间数据库名,渲染列,渲染类型,标签渲染列,渲染类型,坐标系统,地理规模);

 

 

// Construct the query
String query = "select pop_1980, pop_1990, state_name, geoloc, mi_prinx from states " +
      "where pop_1990 < pop_1980 * 1.03";
 
// This code uses the constructor required when using a query
OraSoTableDescHelper queryTDH = new OraSoTableDescHelper(query, idColumns, spatialCol,
      rendCol, perFeatureType, labelRendCol, perFeatureLabelType, csys, dimensions);

 

 

 

OraSoDataProvidreHelper 构造函数:

 

1,  OraSoDataProvidreHelper

OraSoDataProviderHelper oraDPHelper = new OraSoDataProviderHelper(host, port, sid,

      usr, pwd, driverType, driver);

 

2OraSoDataProviderHelper oraDPHelper = new OraSoDataProviderHelper(“连接池的名字nullnull);

 

2.注释图层

该图层包含在特定地图区域上标志或放置的重点的图元。网元通常是添加到注释图层中

创建注释图层的三个步骤:

<1>创建AnnontationTableDescHepler 对象

AnnontationTableDescHepler antTDH=AnnontationTableDescHepler(表名);

<2>创建AnnontationDataProviderHepler 对象

两种方式:

1,   AnnontationDataProviderHepler  atDPH=new  AnnontationDataProviderHepler()

 

2,  AnnontationDataProviderHepler atDPH=new  AnnontationDataProviderHepler(TableInfoImpl  tableInfo)

 

 

TableInfoImpl :为表的信息

 

 

1,生成一个图层字段结构信息

 

    TableInfoImpl tii=GisMgr.genTableInfo(config.getLayerName(),new String[]{"SYS_ID"},

                                          new int[]{TableInfo.COLUMN_TYPE_STRING},new int[]{0},null);

 

 

 

  /**

   * 生成一个图层字段结构信息

   * @param layerName String       图层名

   * @param colNames String[]    字段名列表--------------默认是col0,col1,col2,col3...

   * @param colTypes int[]       字段类型列表

   * @param pkCols int[]         主键索引列表----0开始

   * @param coordSys CoordSys    坐标系(为null时使用WGS84做为默认值)

   * @return TableInfoImpl

   */

  public static TableInfoImpl genTableInfo(String layerName, String[] colNames, int[] colTypes,

      int[] pkCols, CoordSys coordSys){

    if(coordSys == null)

      coordSys = CoordSys.longLatWGS84;

    return new TableInfoImpl(layerName, coordSys, colNames, colTypes, colNames.length, pkCols, false);

  }

 

 

 

  2,增加注释图层

 

  FeatureLayer lyrNebCell = GisMgr.addAnnotationLayer(mapj, config.getLayerName(), tii, true);

 

 

    /**

   * 增加注释图层

   * @param mapj MapJ

   * @param layerName String

   * @param tii TableInfoImpl

   * @param renew boolean        //是否强制新建(会删除原先存在的临时图层)

   * @return FeatureLayer

   */

  public static FeatureLayer addAnnotationLayer(MapJ mapj, String layerName, TableInfoImpl tii, boolean renew){

    Layers layers = mapj.getLayers();

    return addAnnotationLayer(layers, layerName, tii, renew);

  }

 

 

 

 

 

 

 

/**

   * 增加注释图层

   * @param layers Layers

   * @param layerName String    图层名称

   * @param tii TableInfoImpl   图层字段结构信息(null时使用默认字段结构,col0,col1...)

   * @return FeatureLayer       添加成功的图层

   */

  public static FeatureLayer addAnnotationLayer(Layers layers, String layerName,

      TableInfoImpl tii, boolean renew){

    FeatureLayer lyr = null;

    try{

      lyr = (FeatureLayer)layers.get(layerName);

      if(lyr!=null && renew){

        layers.remove(layerName);

        lyr = null;

      }

      if(lyr == null){

        AnnotationTableDescHelper atdh = new AnnotationTableDescHelper(layerName);

        AnnotationDataProviderHelper adph = (tii == null ? new AnnotationDataProviderHelper()

                                            : new AnnotationDataProviderHelper(tii));

        LocalDataProviderRef ldpr = new LocalDataProviderRef(adph);

        lyr = (FeatureLayer)layers.insertLayer(ldpr, atdh, 0, layerName);

      }

      return lyr;

    } catch(Exception e){

      log.error("无法添加临时图层:" + layerName, e);

      return null;

    }

  }

 

 

 

 

 

<3> 创建LoaclDataProviderRef 对象。输出AnnontationDataProviderHelper对象

LocalDataProviderRef ldpr = new LocalDataProviderRef(atDPH);

<4> 添加图层

FeatureLayer  lyr = (FeatureLayer)layers.insertLayer(ldpr, antTDH, 0, layerName);

 

原创粉丝点击