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

📄 mapservice.java

📁 基于ArcIMS Java Connector开发的WebGIS
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.esri.aims.mtier.dx;

import java.util.*;

import com.esri.aims.mtier.dx.ConfigService;
import com.esri.aims.mtier.model.acetate.*;
import com.esri.aims.mtier.model.envelope.*;
import com.esri.aims.mtier.model.map.*;
import com.esri.aims.mtier.model.map.layer.*;
import com.esri.aims.mtier.model.map.layer.query.*;
import com.esri.aims.mtier.model.map.layer.renderer.*;
import com.esri.aims.mtier.model.map.layer.renderer.symbol.*;
import com.esri.aims.mtier.model.util.*;

public class MapService extends MapConnection {
  //parameter
  String activeLayerId = null;
  String bufferLayerId = null;

  //layer
  FeatureLayer flyr = null;

  //recordset
  HashMap filterMap = null;
  HashMap bufferMap = null;

  //symbol
  static String fillColor = "255,0,0";
  static String chartColors[] = {"0,255,0","0,0,255","255,255,0","255,0,255","0,255,255","255,0,0"};
  static long chartSize = 10;
  SimpleMarkerSymbol markSymbol = null;
  SimpleLineSymbol lineSymbol = null;
  SimplePolygonSymbol polySymbol = null;

  //buffer distance
  static final double dis = 1.0e-3;

  // join table
  boolean isJoin=false;
  String orignTableName=null;
  String joinTableName=null;
  String joinColName=null;

  public MapService() {
    markSymbol = new SimpleMarkerSymbol();
    lineSymbol = new SimpleLineSymbol();
    polySymbol = new SimplePolygonSymbol();
    filterMap = new HashMap();
    bufferMap = new HashMap();
  }

  /**
   * 设置图例
   */
  public void setLegend() {
    Legend leg = imsmap.getLegend();
    leg.setFont("楷体_GB2312");
    leg.setTitle("");
    leg.setCellSpacing(2);
    leg.setLayerFontSize(16);
    leg.setValueFontSize(12);
    leg.setAutoExtend(true);
    leg.setDisplay(true);
  }

  /**
   * 设置Map显示范围
   * @param maxX double
   * @param maxY double
   * @param minX double
   * @param minY double
   */
  public void setMapExtent(double maxX, double maxY, double minX, double minY) {
    if (Math.abs(maxX - minX) >= dis && Math.abs(maxY - minY) > dis) {
      if (maxX < minX) {
        double tempX = maxX;
        maxX = minX;
        minX = tempX;
      }
      if (maxY < minY) {
        double tempY = maxY;
        maxY = minY;
        minY = tempY;
      }
      imsmap.getEnvelope().setMaxX(maxX);
      imsmap.getEnvelope().setMaxY(maxY);
      imsmap.getEnvelope().setMinX(minX);
      imsmap.getEnvelope().setMinY(minY);
      //Envelope env = imsmap.getEnvelope();
      //imsmap.doZoomToExtent(env);
    }
  }

  /**
   * 设置全图显示
   */
  public void setMapFullExtent() {
    imsmap.doZoomToFullExtent();
  }

  /**
   * 返回Map显示范围MaxX
   * @return double
   */
  public double getMaxX() {
    return imsmap.getEnvelope().getMaxX();
  }

  /**
   * 返回Map显示范围MaxY
   * @return double
   */
  public double getMaxY() {
    return imsmap.getEnvelope().getMaxY();
  }

  /**
   * 返回Map显示范围MinX
   * @return double
   */
  public double getMinX() {
    return imsmap.getEnvelope().getMinX();
  }

  /**
   * 返回Map显示范围MinY
   * @return double
   */
  public double getMinY() {
    return imsmap.getEnvelope().getMinY();
  }

  /**
   * 设置Map高宽
   * @param width 宽度
   * @param height 高度
   */
  public void setMapWidthHeight(long width, long height) {
    imsmap.setWidth(width);
    imsmap.setHeight(height);
  }

  /**
   * 返回Map高度
   * @return long
   */
  public long getMapWidth() {
    return imsmap.getWidth();
  }

  /**
   * 返回Map宽度
   * @return long
   */
  public long getMapHeight() {
    return imsmap.getHeight();
  }

  /**
   * 刷新地图
   */
  public void mapRefresh() {
    imsmap.refresh();
    ConfigService.setLegendUrl(imsmap.getLegend().getLegendOutput().getURL());
    ConfigService.setMapUrl(imsmap.getMapOutput().getURL());
  }

  /**
   * 返回图例路径
   * @return String
   */
  public String getLegendUrl() {
    return ConfigService.getLegendUrl();
  }

  /**
   * 返回地图路径
   * @return String
   */
  public String getMapUrl() {
    return ConfigService.getMapUrl();
  }

  /**
   * 设置 ActiveFeaturelayer
   * @param layerId String
   */
  public void setActiveFeatureLayer(String layerId) {
    flyr = null;
    for (int i = 0; i < getLayerCount(); i++) {
      if (imsmap.getLayers().item(i) instanceof FeatureLayer) {
        if (imsmap.getLayers().item(i).getID().equalsIgnoreCase(layerId)) {
          flyr = (FeatureLayer) imsmap.getLayers().item(i);
          activeLayerId = imsmap.getLayers().item(i).getID();
          break;
        }
      }
    }
  }

  /**
   * 返回 ActiveFeaturelayerId
   * @return String
   */
  public String getActiveFeatureLayerId() {
    if (activeLayerId == null) {
      for (int i = 0; i < getLayerCount(); i++) {
        if (imsmap.getLayers().item(i) instanceof FeatureLayer) {
          activeLayerId = imsmap.getLayers().item(i).getID();
          break;
        }
      }
    }
    return activeLayerId;
  }

  /**
   * 设置高亮显示要素颜色
   * @param color 颜色,输入格式="255,255,255"
   */
  public static void setFillColor(String color) {
    fillColor = color;
  }

  /**
   * 返回高亮显示要素颜色
   * @return String
   */
  public static String getFillColor() {
    return fillColor;
  }

  /**
   * 设置高亮显示要素填充的Symbol
   * @param type 图层类型,输入类型="point","line","polygon"
   */
  protected void setDisplaySymbol(String type) {
    if (markSymbol == null) {
      markSymbol = new SimpleMarkerSymbol();
    }
    if (lineSymbol == null) {
      lineSymbol = new SimpleLineSymbol();
    }
    if (polySymbol == null) {
      polySymbol = new SimplePolygonSymbol();
    }
    if (type.equalsIgnoreCase("point")) {
      markSymbol.setColor(fillColor);
      markSymbol.setOverlap(true);
      markSymbol.setWidth(16);
      markSymbol.setMarkerType(SimpleMarkerSymbol.STAR);
    }
    if (type.equalsIgnoreCase("line")) {
      lineSymbol.setColor(fillColor);
      lineSymbol.setOverlap(true);
      lineSymbol.setWidth(2);
      lineSymbol.setLineType(SimpleLineSymbol.SOLID);
    }
    if (type.equalsIgnoreCase("polygon")) {
      polySymbol.setBoundary(false);
      polySymbol.setOverlap(true);
      polySymbol.setFillColor(fillColor);
      polySymbol.setFillTransparency(0.6);
      polySymbol.setFillType(SimplePolygonSymbol.FDIAGONAL);
    }
  }

  /**
   * 查询的要素集设置显示范围
   * @param rs Recordset
   */
  public void setFilterExtent(Recordset rs) {
    if (rs != null && rs.getEnvelopeCount() != 0) {
      double tmaxX = rs.getEnvelope(0).getMaxX();
      double tmaxY = rs.getEnvelope(0).getMaxY();
      double tminX = rs.getEnvelope(0).getMinX();
      double tminY = rs.getEnvelope(0).getMinY();
      for (int i = 0; i < rs.getEnvelopeCount(); i++) {
        if (tmaxX < rs.getEnvelope(i).getMaxX()) {
          tmaxX = rs.getEnvelope(i).getMaxX();
        }
        if (tmaxY < rs.getEnvelope(i).getMaxY()) {
          tmaxY = rs.getEnvelope(i).getMaxY();
        }
        if (tminX > rs.getEnvelope(i).getMinX()) {
          tminX = rs.getEnvelope(i).getMinX();
        }
        if (tminY > rs.getEnvelope(i).getMinY()) {
          tminY = rs.getEnvelope(i).getMinY();
        }
      }

      tmaxX = tmaxX +(fullMaxX - fullMinX) / 64;
      tmaxY = tmaxY +(fullMaxY - fullMinY) / 64;
      tminX = tminX -(fullMaxX - fullMinX) / 64;
      tminY = tminY -(fullMaxY - fullMinY) / 64;
      System.out.println("tmaxX:" + tmaxX + " tmaxY:" + tmaxY + " tminX:" + tminX + " tminY:" + tminY);
      setMapExtent(tmaxX, tmaxY, tminX, tminY);
    }
  }

  /**
   * 检验 SubField
   * @param lyr FeatureLayer
   * @param fd String
   * @return boolean
   */
  protected boolean checkSubField(FeatureLayer lyr,String fd) {
    boolean isField = false;
    TableDesc td = lyr.getRecordset().getTableDesc();
    for (int jj = 0; jj < td.getCount(); jj++) {
      if (fd.equalsIgnoreCase(td.getFieldName(jj))) {
        isField = true;
        break;
      }
    }
    return isField;
  }

  /**
   *
   * @param tab TableDesc
   * @return String
   */
  protected String getFieldTitle(TableDesc tab){
    String title="";
    for(int t=0;t<tab.getCount();t++){
      if(!(tab.getFieldName(t).equalsIgnoreCase("#shape#") || tab.getFieldName(t).equalsIgnoreCase("#id#"))){
        title=tab.getFieldName(t);
        break;

⌨️ 快捷键说明

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