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

📄 esri_task_editing.js

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JS
📖 第 1 页 / 共 2 页
字号:
/*
COPYRIGHT 1995-2005 ESRI

TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
Unpublished material - all rights reserved under the
Copyright Laws of the United States.

For additional information, contact:
Environmental Systems Research Institute, Inc.
Attn: Contracts Dept
380 New York Street
Redlands, California, USA 92373

email: contracts@esri.com
*/

function EsriEditingDrawAction() {
  this.inheritsFrom(new EsriAction());
  this.isEditing = true;

  this.lineOpacity = 0.5;
  this.fillColor = "#ff0";
  this.fillOpacity = 0.25;

  this.snapping = false;
  this.snapDistance = 5;
  this.snapColor = "#f90";
  this.snapWidth = 8;

  this.snappedPoint = null;
  this.snapGraphics = null;
  this.clickTolerance = 3;
}

function EsriEditingDrawPointAction() {
  this.inheritsFrom(new EsriEditingDrawAction());
  this.name = "EsriEditingDrawPointAction";

  var element, callback, contCallback, bounds, timer, currPt, gr;
  var callbackTimeout = 250;
  var self = this;

  this.activate = function(elem, cb, ccb) {
    element = elem;
    callback = cb;
    contCallback = ccb;

    element.style.cursor = this.cursor;
    element.onmousemove = processMouseMove;
    element.onclick = processClick;

    if (this.snapping) {
      gr = EsriUtils.createGraphicsElement(element.id + "gr", element);
      EsriUtils.setElementStyle(gr.gc, "z-index:" + this.graphicsZIndex + ";");
      gr.lineColor = this.lineColor;
      gr.lineWidth = this.lineWidth;
      gr.lineOpacity = this.lineOpacity;
      gr.fillColor = this.fillColor;
      gr.fillOpacity = this.fillOpacity;
      gr.gc.style.cursor = this.cursor;

      this.snapGraphics = EsriUtils.createGraphicsElement(element.id + "sGr", element);
      EsriUtils.setElementStyle(this.snapGraphics.gc, "z-index:" + (this.graphicsZIndex + 1) + ";");
      this.snapGraphics.lineColor = this.snapColor;
      this.snapGraphics.lineWidth = this.snapWidth;
      this.snapGraphics.fillColor = "#fff";
      this.snapGraphics.fillOpacity = 1;
      this.snapGraphics.gc.style.cursor = this.cursor;

      gr.gc.onmousemove = this.snapGraphics.gc.onmousemove = processMouseMove;
      gr.gc.onclick = this.snapGraphics.gc.onclick = processClick;
    }
  }

  this.deactivate = function() {
    if (element != null) {
      element.onmousedown = element.onclick = element.onmousemove = null;
      element.style.cursor = "default";
    }
    if (gr != null) {
      gr.destroy();
      this.snapGraphics.destroy();
      gr.gc.onmousedown = gr.gc.onclick = this.snapGraphics.gc.onmousedown = this.snapGraphics.gc.onclick = null;
    }
    element = callback = gr = this.snapGraphics = this.snappedPoint = null;
  }

  this.reactivate = function() {
    var e = element;
    var c = callback;
    var cc = contCallback;
    this.deactivate();
    this.activate(e, c, cc);
  }

  function getPoint(e) {
    var pt = EsriUtils.getXY(e).offset(-bounds.left, -bounds.top);
    if ((Math.abs(currPt.x - pt.x) <= self.clickTolerance && Math.abs(currPt.y - pt.y) <= self.clickTolerance) && self.snappedPoint) pt = self.snappedPoint;
    return pt;
  }

  function processMouseMove(e) {
    bounds = EsriUtils.getElementPageBounds(element);
    currPt = EsriUtils.getXY(e).offset(-bounds.left, -bounds.top);
    if (gr) {
      self.snapGraphics.clear();
      gr.clear();
      gr.drawCircle(currPt, self.snapDistance);
      restartTimer();
    }
    if (EsriUtils.isNav) EsriUtils.stopEvent(e);
    return false;
  }

  function processClick(e) {
    clearTimeout(timer);
    bounds = EsriUtils.getElementPageBounds(element);
    currPt = getPoint(e);
    EsriUtils.stopEvent(e);
    if (gr) {
      gr.clear();
      self.snapGraphics.clear();
    }
    bounds = null;
    callback(currPt);
  }

  function restartTimer() {
    if (timer) clearTimeout(timer);
    var pt = currPt;
    timer = setTimeout(function() { self.snapGraphics.clear(); self.snappedPoint = null; contCallback(pt); }, callbackTimeout);
  }
}

function EsriEditingDrawLineAction() {
  this.inheritsFrom(new EsriEditingDrawAction());
  this.name = "EsriEditingDrawLineAction";

  var element, callback, bounds, timer, startPt, gr, tGr, currPt, contCallback;
  var callbackTimeout = 250;
  var self = this;

  this.activate = function(elem, cbF, ccbF) {
    element = elem;
    callback = cbF;
    contCallback = ccbF;

    gr = EsriUtils.createGraphicsElement(element.id + "gr", element);
    EsriUtils.setElementStyle(gr.gc, "z-index:" + this.graphicsZIndex + ";");
    gr.lineColor = this.lineColor;
    gr.lineWidth = this.lineWidth;

    element.style.cursor = gr.gc.style.cursor = this.cursor;
    element.onmousedown = gr.gc.onmousedown = processMouseDown;
    element.onmousemove = gr.gc.onmousemove = processMouseMove;

    if (this.snapping) {
      tGr = EsriUtils.createGraphicsElement(element.id + "tGr", element);
      EsriUtils.setElementStyle(tGr.gc, "z-index:" + (this.graphicsZIndex + 1) + ";");
      tGr.lineColor = this.lineColor;
      tGr.lineWidth = this.lineWidth;
      tGr.lineOpacity = this.lineOpacity;
      tGr.fillColor = this.fillColor;
      tGr.fillOpacity = this.fillOpacity;

      this.snapGraphics = EsriUtils.createGraphicsElement(element.id + "sGr", element);
      EsriUtils.setElementStyle(this.snapGraphics.gc, "z-index:" + (this.graphicsZIndex + 1) + ";");
      this.snapGraphics.lineColor = this.snapColor;
      this.snapGraphics.lineWidth = this.snapWidth;
      this.snapGraphics.fillColor = "#fff";
      this.snapGraphics.fillOpacity = 1;
      this.snapGraphics.gc.style.cursor = this.cursor;

      tGr.gc.style.cursor = this.snapGraphics.gc.style.cursor = this.cursor;
      tGr.gc.onmousedown = this.snapGraphics.gc.onmousedown = processMouseDown;
      tGr.gc.onmousemove = this.snapGraphics.gc.onmousemove = processMouseMove;
    }
  }

  this.deactivate = function() {
    if (element != null) {
      element.onmouseup = element.onmousemove = element.onmousedown = null;
      element.style.cursor = "default";
    }
    if (gr != null) {
      gr.destroy();
      gr.gc.onmouseup = gr.gc.onmousemove = gr.gc.onmousedown = null;
    }
    if (tGr) {
      tGr.destroy();
      this.snapGraphics.destroy();
      tGr.gc.onmouseup = this.snapGraphics.gc.onmouseup = tGr.gc.onmousemove = this.snapGraphics.gc.onmousemove = tGr.gc.onmousedown = this.snapGraphics.gc.onmousedown = null;
    }
    element = startPt = gr = this.snapGraphics = this.snappedPoint = null;
  }

  this.reactivate = function() {
    var e = element;
    var c = callback;
    var ccb = contCallback;
    this.deactivate();
    this.activate(e, c, ccb);
  }

  function getPoint(e) {
    var pt = EsriUtils.getXY(e).offset(-bounds.left, -bounds.top);
    if ((Math.abs(currPt.x - pt.x) <= self.clickTolerance && Math.abs(currPt.y - pt.y) <= self.clickTolerance) && self.snappedPoint) pt = self.snappedPoint;
    return pt;
  }

  function processMouseDown(e) {
    bounds = EsriUtils.getElementPageBounds(element);
    element.onmousedown = gr.gc.onmousedown = null;
    element.onmouseup = gr.gc.onmouseup = processMouseUp;
    if (tGr) {
      tGr.gc.onmousedown = self.snapGraphics.gc.onmousedown = null;
      tGr.gc.onmouseup = self.snapGraphics.gc.onmouseup = processMouseUp;
    }
    startPt = getPoint(e);
    gr.clear();
    EsriUtils.stopEvent(e);
    return false;
  }

  function processMouseMove(e) {
    if (! bounds) bounds = EsriUtils.getElementPageBounds(element);
    currPt = EsriUtils.getXY(e).offset(-bounds.left, -bounds.top);
    if (startPt) {
      gr.clear();
      gr.drawLine(startPt, currPt);
    }
    if (tGr) {
      self.snapGraphics.clear();
      tGr.clear();
      tGr.drawCircle(currPt, self.snapDistance);
      restartTimer();
    }
    EsriUtils.stopEvent(e);
    return false;
  }

  function processMouseUp(e) {
    clearTimeout(timer);
    var sPt = startPt;
    startPt = null;
    gr.clear();
    element.onmouseup = gr.gc.onmouseup = null;
    element.onmousedown = gr.gc.onmousedown = processMouseDown;
    if (tGr) {
      tGr.clear();
      self.snapGraphics.clear();
      tGr.gc.onmouseup = self.snapGraphics.gc.onmouseup = null;
      tGr.gc.onmousedown = self.snapGraphics.gc.onmousedown = processMouseDown;
    }
    callback(sPt, getPoint(e));
    EsriUtils.stopEvent(e);
    return false;
  }

  function restartTimer() {
    if (timer) clearTimeout(timer);
    var pt = currPt;
    timer = setTimeout(function() { self.snapGraphics.clear(); self.snappedPoint = null; contCallback(pt); }, callbackTimeout);
  }
}

function EsriEditingDrawPolyShapeAction(isPolygon) {
  this.inheritsFrom(new EsriEditingDrawAction());
  this.name = (isPolygon) ? "EsriEditingDrawPolygonAction" : "EsriEditingDrawPolylineAction";

  var isPgon = isPolygon;
  var element, callback, contCallback, bounds, pts, index, gr, tGr, timer, currPt;
  var callbackTimeout = 250;
  var self = this;

  this.activate = function(elem, cb, ccb) {
    element = elem;
    callback = cb;
    contCallback = ccb;
    pts = [];

    gr = EsriUtils.createGraphicsElement(element.id + "gr", element);
    EsriUtils.setElementStyle(gr.gc, "z-index:" + this.graphicsZIndex + ";");
    gr.lineColor = this.lineColor;
    gr.lineWidth = this.lineWidth;
    gr.lineOpacity = this.lineOpacity;

    tGr = EsriUtils.createGraphicsElement(element.id + "tGr", element);
    EsriUtils.setElementStyle(tGr.gc, "z-index:" + this.graphicsZIndex + ";");
    tGr.lineColor = this.lineColor;
    tGr.lineWidth = this.lineWidth;
    tGr.lineOpacity = this.lineOpacity;
    tGr.fillColor = this.fillColor;
    tGr.fillOpacity = this.fillOpacity;

⌨️ 快捷键说明

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