⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maplayersall.java

📁 webGIS的经典资料
💻 JAVA
字号:
package com.esri.aims.mtier.dx;

import java.util.*;

import com.esri.aims.mtier.dx.ConfigService;
import com.esri.aims.mtier.model.map.Map;
import com.esri.aims.mtier.model.map.layer.*;

public class MapLayersAll {
  Map imsmap = null;
  HashMap<String, Vector<String>> layerAttribute = null;
  Vector<String> layerName = null;
  Vector<String> layerId = null;
  Vector<String> layerType = null;
  Vector<String> layerMaxScale = null;
  Vector<String> layerMinScale = null;
  Vector<String> layerVisible = null;
  Vector<String> layerFeatureType = null;

  /**
   * 空构造函数
   */
  public MapLayersAll() {
    imsmap = new Map();
  }

  /**
   * 带参数的构造函数
   * @param map Map
   */
  public MapLayersAll(Map map){
    imsmap = new Map();
    imsmap = map;
  }

  /**
   * 设置初始Map实例
   * @param map Map
   */
  public void setMapInstance(Map map) {
    imsmap = map;
  }

  /**
   * 获取图层数
   * @return int
   */
  protected int getLayerCount() {
    return imsmap.getLayers().getCount();
  }

  /**
   * 获取图层属性集
   * layerName,layerId,layerType,layerMaxScale,layerMinScale,layerVisible,layerFeatureType
   */
  public void setLayerAttribute() {
    if (layerName == null) {
      layerName = new Vector<String>();
    }
    if (layerId == null) {
      layerId = new Vector<String>();
    }
    if (layerType == null) {
      layerType = new Vector<String>();
    }
    if (layerMaxScale == null) {
      layerMaxScale = new Vector<String>();
    }
    if (layerMinScale == null) {
      layerMinScale = new Vector<String>();
    }
    if (layerVisible == null) {
      layerVisible = new Vector<String>();
    }
    if (layerFeatureType == null) {
      layerFeatureType = new Vector<String>();
    }
    layerName.clear();
    layerId.clear();
    layerType.clear();
    layerMaxScale.clear();
    layerMinScale.clear();
    layerVisible.clear();
    layerFeatureType.clear();

    for (int i = 0; i < getLayerCount(); i++) {
      layerId.add(imsmap.getLayers().item(i).getID());
      layerName.add(imsmap.getLayers().item(i).getName());
      if (imsmap.getLayers().item(i).getMaxScale() == null) {
        layerMaxScale.add("1.0E+10");
      }
      else {
        layerMaxScale.add(imsmap.getLayers().item(i).getMaxScale());
      }
      if (imsmap.getLayers().item(i).getMinScale() == null) {
        layerMinScale.add("0");
      }
      else {
        layerMinScale.add(imsmap.getLayers().item(i).getMinScale());
      }
      if (imsmap.getLayers().item(i).isVisible() == true) {
        layerVisible.add("true");
      }
      else {
        layerVisible.add("false");
      }
      if (imsmap.getLayers().item(i) instanceof FeatureLayer) {
        FeatureLayer flyr = (FeatureLayer) imsmap.getLayers().item(i);
        layerType.add(flyr.getType());
        layerFeatureType.add(flyr.getFeatureClass());
      }
      else if (imsmap.getLayers().item(i) instanceof ImageLayer) {
        ImageLayer ilyr = (ImageLayer) imsmap.getLayers().item(i);
        layerType.add(ilyr.getType());
        layerFeatureType.add("image");
      }
      else if (imsmap.getLayers().item(i) instanceof AcetateLayer) {
        AcetateLayer alyr = (AcetateLayer) imsmap.getLayers().item(i);
        layerType.add(alyr.getType());
        layerFeatureType.add("acetate");
      }
      else {
        layerType.add(imsmap.getLayers().item(i).getType());
        layerFeatureType.add("none");
      }
    }

    /**
     * 保存图层属性到 HashMap
     */
    if (layerAttribute == null) {
      layerAttribute = new HashMap<String, Vector<String>>();
    }
    layerAttribute.clear();
    layerAttribute.put(ConfigService.MAP_LAYER_ID, layerId);
    layerAttribute.put(ConfigService.MAP_LAYER_NAME, layerName);
    layerAttribute.put(ConfigService.MAP_LAYER_TYPE, layerType);
    layerAttribute.put(ConfigService.MAP_LAYER_VISIBLE, layerVisible);
    layerAttribute.put(ConfigService.MAP_LAYER_MAXSCALE, layerMaxScale);
    layerAttribute.put(ConfigService.MAP_LAYER_MINSCALE, layerMinScale);
    layerAttribute.put(ConfigService.MAP_LAYER_FEATURETYPE, layerFeatureType);
  }

  /**
   * 返回所有图层的属性
   * @return HashMap
   */
  public HashMap getLayerAttribute() {
    return layerAttribute;
  }

  /**
   * 控制图层显示状态
   * @param lyrVis 输入格式="true,true,false,false",有几层输入几层
   */
  public void setLayersVisible(String lyrVis) {
    String[] lys = lyrVis.split(",");
    if (lys.length == getLayerCount()) {
      for (int i = 0; i < lys.length; i++) {
        boolean isLayer = (lys[i].equalsIgnoreCase("true") ||
                           lys[i].equalsIgnoreCase("1"));
        imsmap.getLayers().item(i).setVisible(isLayer);
      }
    }
  }

  /**
   * 获取所有图层显示状态
   * @return String
   */
  public String getLayersVisible() {
    String lyrVis = "";
    try{
      for (int i = 0; i < getLayerCount() - 1; i++) {
        lyrVis += Boolean.toString(imsmap.getLayers().item(i).isVisible()) + ",";
      }
      lyrVis +=
          Boolean.toString(imsmap.getLayers().item(getLayerCount() - 1).isVisible());
    }catch(Exception ex){

    }
    return lyrVis;
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -