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

📄 esri_map.js

📁 ARCGIS程序,可以实现查、缩放等功能
💻 JS
📖 第 1 页 / 共 3 页
字号:
  }

  this.continuousAction = function(x, y) {
    if (! map || ! mapToOvRatioWd) self.update();
    for (var i=0;i<map.mapSourceNames.length;i++) map.mapSources[map.mapSourceNames[i]].updateImages(map.viewBounds.offset(-x, -y));
    if (overview) overview.update(ovBox.left + -(x * mapToOvRatioWd), ovBox.top + -(y * mapToOvRatioHt), ovBox.width, ovBox.height);
  }

  this.postAction = function(x, y) {
    if (x == 0 && y == 0) return;
    if (! map) self.update();
    map.viewBounds = map.viewBounds.offset(-x, -y);
    var bounds = map.bounds.offset(-x, -y);
    mapToOvRatioWd = mapToOvRatioHt = null;

    for (var i=0;i<map.mapSourceNames.length;i++) {
      var mapSource = map.mapSources[map.mapSourceNames[i]];
      mapSource.centerAt(Math.round(bounds.center.x), Math.round(bounds.center.y));
    }
  }
}

function EsriMapPoint(id, toolName, isMarkerTool, isPin) {
	this.inheritsFrom(new EsriMapToolItem(id, toolName, new EsriDrawPointAction(), isMarkerTool));
  this.isPin = isPin;
  var self = this;

  this.update = function() { self = this; }
	this.postAction = function(point) {
    self.update();
    var map = self.control;

    if (self.isMarker) {
      if (self.isPin) map.graphics.drawPin(point);
      else map.graphics.drawPoint(point);
    }
    else {
      if (self.showLoading) map.showLoading();
      point = point.offset(-map.viewBounds.left, -map.viewBounds.top);

      EsriUtils.addFormElement(map.formId, map.id, map.id);
      EsriUtils.addFormElement(map.formId, map.id + "_mode", self.id);
      EsriUtils.addFormElement(map.formId, map.id + "_minx", point.x);
      EsriUtils.addFormElement(map.formId, map.id + "_miny", point.y);
      if (self.clientPostBack) EsriUtils.addFormElement(map.formId, "doPostBack", "doPostBack");
      EsriUtils.submitForm(map.formId, self.clientPostBack, EsriControls.processPostBack);
    }
	}
}

function EsriMapLine(id, toolName, isMarkerTool) {
  this.inheritsFrom(new EsriMapToolItem(id, toolName, new EsriDrawLineAction(), isMarkerTool));
  var self = this;

  this.update = function() { self = this; }
  this.postAction = function(from, to) {
    if (from.x == to.x && from.y == to.y) return;

    self.update();
    var map = self.control;

    if (self.isMarker) map.graphics.drawLine(from, to);
    else {
      if (self.showLoading) map.showLoading();
      from = from.offset(-map.viewBounds.left, -map.viewBounds.top);
      to = to.offset(-map.viewBounds.left, -map.viewBounds.top);

      EsriUtils.addFormElement(map.formId, map.id, map.id);
      EsriUtils.addFormElement(map.formId, map.id + "_mode", self.id);
      EsriUtils.addFormElement(map.formId, map.id + "_coords", from.x + ":" + from.y + "|" + to.x + ":" + to.y);
      if (self.clientPostBack) EsriUtils.addFormElement(map.formId, "doPostBack", "doPostBack");
      EsriUtils.submitForm(map.formId, self.clientPostBack, EsriControls.processPostBack);
    }
  }
}

function EsriMapPoly(id, toolName, isMarkerTool, isPolygon) {
  this.inheritsFrom(new EsriMapToolItem(id, toolName, ((isPolygon) ? new EsriDrawPolygonAction() : EsriDrawPolylineAction()), isMarkerTool));
  this.isPgon = isPolygon;
  var self = this;

  this.update = function() { self = this; }
  this.postAction = function(points) {
    if (points.length <= 1) return;

    self.update();
    var map = self.control;

    if (self.isMarker) {
      if (self.isPgon) map.graphics.drawPolygon(points);
      else map.graphics.drawPolyline(points);
    }
    else {
      if (self.showLoading) map.showLoading();
      var pts = "";
      var viewLeft = map.viewBounds.left;
      var viewTop = map.viewBounds.top;
      for (var i=0;i<points.length;i++) {
        points[i] = points[i].offset(-viewLeft, -viewTop);
        if (i == 0) pts += points[i].x + ":" + points[i].y;
        else pts += "|" + points[i].x + ":" + points[i].y;
      }
      EsriUtils.addFormElement(map.formId, map.id, map.id);
      EsriUtils.addFormElement(map.formId, map.id + "_mode", self.id);
      EsriUtils.addFormElement(map.formId, map.id + "_coords", pts);
      if (self.clientPostBack) EsriUtils.addFormElement(map.formId, "doPostBack", "doPostBack");
      EsriUtils.submitForm(map.formId, self.clientPostBack, EsriControls.processPostBack);
    }
  }
}

function EsriMapPolyline(id, toolName, isMarkerTool) { return new EsriMapPoly(id, toolName, isMarkerTool, false); }
function EsriMapPolygon(id, toolName, isMarkerTool) { return new EsriMapPoly(id, toolName, isMarkerTool, true); }

function EsriMapCircle(id, toolName, isMarkerTool) {
  this.inheritsFrom(new EsriMapToolItem(id, toolName, new EsriDrawCircleAction(), isMarkerTool));
  var self = this;

  this.update = function() { self = this; }
  this.postAction = function(center, radius) {
    if (radius == 0) return;

    self.update();
    var map = self.control;

    if (self.isMarker) map.graphics.drawCircle(center, radius);
    else {
      if (self.showLoading) map.showLoading();
      center = center.offset(-map.viewBounds.left, -map.viewBounds.top);

      EsriUtils.addFormElement(map.formId, map.id, map.id);
      EsriUtils.addFormElement(map.formId, map.id + "_mode", self.id);
      EsriUtils.addFormElement(map.formId, map.id + "_coords", center.x + ":" + center.y + ":" + radius);
      if (self.clientPostBack) EsriUtils.addFormElement(map.formId, "doPostBack", "doPostBack");
      EsriUtils.submitForm(map.formId, self.clientPostBack, EsriControls.processPostBack);
    }
  }
}

function EsriMapOval(id, toolName, isMarkerTool) {
  this.inheritsFrom(new EsriMapToolItem(id, toolName, new EsriDrawOvalAction(), isMarkerTool));
  var self = this;

  this.update = function() { self = this; }
  this.postAction = function(rect) {
    if (rect.width == 0 && rect.height == 0) return;

    self.update();
    var map = self.control;

    if (self.isMarker) map.graphics.drawOval(rect);
    else {
      if (self.showLoading) map.showLoading();
      rect = rect.offset(-map.viewBounds.left, -map.viewBounds.top);

      EsriUtils.addFormElement(map.formId, map.id, map.id);
      EsriUtils.addFormElement(map.formId, map.id + "_mode", self.id);
      EsriUtils.addFormElement(map.formId, map.id + "_coords", rect.center.x + ":" + rect.center.y + ":" + rect.width + ":" + rect.height);
      if (self.clientPostBack) EsriUtils.addFormElement(map.formId, "doPostBack", "doPostBack");
      EsriUtils.submitForm(map.formId, self.clientPostBack, EsriControls.processPostBack);
    }
  }
}

function EsriMapImage(id, toolName) {
  this.inheritsFrom(new EsriMapToolItem(id, toolName, new EsriDrawPointAction(), true));
  this.imageUrl = "images/pixel.gif";
  this.imageWidth = this.imageHeight = 1;
  var self = this;

  this.update = function() { self = this; }
  this.postAction = function(point) {
    self.update();
    var map = self.control;
    map.graphics.drawImage(self.imageUrl, point.x - (self.imageWidth / 2), point.y - (self.imageHeight / 2), self.imageWidth, self.imageHeight);
  }
}

function EsriMapKeyNavigation(id, toolName, panSpeed) {
  this.inheritsFrom(new EsriMapToolItem(id, toolName, new EsriKeyInputAction()));
  var map;
  var KEY_PLUS = EsriUtils.isIE ? 187 : 61;
  var KEY_PLUS_NUM = 107;
  var KEY_MINUS = EsriUtils.isIE ? 189 : 109;
  var KEY_MINUS_NUM = 109;
  var KEY_UPPER_RIGHT = 33;
  var KEY_UPPER_LEFT = 36;
  var KEY_LOWER_RIGHT = 34;
  var KEY_LOWER_LEFT = 35;
  var keyCodes = [EsriUtils.KEY_ESCAPE, EsriUtils.KEY_RIGHT, EsriUtils.KEY_LEFT, EsriUtils.KEY_DOWN, EsriUtils.KEY_UP, KEY_PLUS, KEY_PLUS_NUM, KEY_MINUS, KEY_MINUS_NUM, KEY_UPPER_RIGHT, KEY_UPPER_LEFT, KEY_LOWER_RIGHT, KEY_LOWER_LEFT];
  var self = this;
  var xDiff = 0, yDiff = 0;
  var speed = (panSpeed) ? panSpeed : 5;
  var timeStep = 2500;
  var maxSpeed = 3;
  var sTime = null;

  this.update = function() {
    self = this;
    map = this.control;
  }

  this.activate = function() {
    this.action.activate(this.element, this.postAction, this.continuousAction);
    this.isActive = true;
  }

  this.continuousAction = function(keyCode) {
    if (keyCodes.indexOf(keyCode) == -1) return true;
    if (keyCode == EsriUtils.KEY_ESCAPE || keyCode == KEY_PLUS || keyCode == KEY_PLUS_NUM || keyCode == KEY_MINUS || keyCode == KEY_MINUS_NUM) return true;
    if (! map) self.update();

    if (! sTime) sTime = new Date().getTime();
    var delta = new Date().getTime() - sTime;
    var m = Math.min(Math.floor(delta / timeStep), maxSpeed);
    var s = speed + (speed * m);

    if (keyCode == EsriUtils.KEY_RIGHT) xDiff -= s;
    else if (keyCode == EsriUtils.KEY_LEFT) xDiff += s;
    else if (keyCode == EsriUtils.KEY_DOWN) yDiff -= s;
    else if (keyCode == EsriUtils.KEY_UP) yDiff += s;
    else if (keyCode == KEY_UPPER_RIGHT) { xDiff -= s; yDiff += s; }
    else if (keyCode == KEY_UPPER_LEFT) { xDiff += s; yDiff += s; }
    else if (keyCode == KEY_LOWER_RIGHT) { xDiff -= s; yDiff -= s; }
    else if (keyCode == KEY_LOWER_LEFT) { xDiff += s; yDiff -= s; }
    map.panTool.action.doDrag(xDiff, yDiff);
    return false;
  }

  this.postAction = function(keyCode) {
    if (keyCodes.indexOf(keyCode) == -1) return true;
    if (! map) self.update();
    if (keyCode == EsriUtils.KEY_ESCAPE && map.currentTool) map.currentTool.action.reactivate();
    else if (keyCode == KEY_PLUS || keyCode == KEY_PLUS_NUM) map.mouseWheelTool.postAction(1);
    else if (keyCode == KEY_MINUS || keyCode == KEY_MINUS_NUM) map.mouseWheelTool.postAction(-1);
    else if (keyCode == EsriUtils.KEY_RIGHT || keyCode == EsriUtils.KEY_LEFT || keyCode == EsriUtils.KEY_DOWN || keyCode == EsriUtils.KEY_UP || keyCode == KEY_UPPER_RIGHT || keyCode == KEY_UPPER_LEFT || keyCode == KEY_LOWER_RIGHT || keyCode == KEY_LOWER_LEFT) map.panTool.action.endDrag(xDiff, yDiff);
    xDiff = yDiff = 0;
    sTime = null;
    return false;
  }
}

function EsriMapMouseWheel(id, toolName) {
  this.inheritsFrom(new EsriMapToolItem(id, toolName, new EsriMouseWheelAction()));
  var self = this;
  var map;

  this.update = function() {
    self = this;
    map = this.control;
  }

  this.postAction = function(value) {
    if (! map) self.update();

    for (var i=0;i<map.mapSourceNames.length;i++) {
      var mapSource = map.mapSources[map.mapSourceNames[i]];
      if (mapSource.type == "tile") {
        if (mapSource.level + value <= 0) {
          if (mapSource.level == 0) return;
          mapSource.level = 0;
        }
        else if (mapSource.level + value >= (mapSource.numLevels - 1)) {
          if (mapSource.level == (mapSource.numLevels -1)) return;
          mapSource.level = (mapSource.numLevels - 1);
        }
        else mapSource.level += value;
        mapSource.changeLevel(mapSource.level);
      }
      else mapSource.changeLevel(value);
    }
  }
}

function EsriMapServerAction(id, toolName, func) {
  this.inheritsFrom(new EsriMapToolItem(id, toolName, null));
  this.isCommand = true;
  var func = func;
  var self = this;

  this.update = function() { self = this; }
  this.activate = function() {
    self.update();

    if (func) if (! func()) return;

    var map = self.control;
    if (self.showLoading) map.showLoading();

    EsriUtils.addFormElement(map.formId, this.id, this.id);
    EsriUtils.addFormElement(map.formId, this.id + "_value", this.id);
    if (self.clientPostBack) EsriUtils.addFormElement(map.formId, "doPostBack", "doPostBack");
    EsriUtils.submitForm(map.formId, self.clientPostBack, EsriControls.processPostBack);
    this.isActive = true;
  }
}

function EsriMapNavigator(id, container, mapId, left, top) {
  this.inheritsFrom(new EsriNavigator(id, container, true, panCallback, zoomCallback, left, top));
  this.speedStepDistance = 10;
  var self = this;
  var shiftX = shiftY = 0;
  var map = EsriControls.maps[mapId];
  var panToolAction = map.panTool.action;

  function panCallback(panPoint, dist) {
    if (dist == -1) {
      panToolAction.endDrag(shiftX, shiftY);
      shiftX = shiftY = 0;
    }
    else {
      shiftX -= panPoint.x * Math.ceil(dist / self.speedStepDistance);
      shiftY -= panPoint.y * Math.ceil(dist / self.speedStepDistance);
      panToolAction.doDrag(shiftX, shiftY);
    }
  }

  function zoomCallback(inORout) {
    for (var i=0;i<map.mapSourceNames.length;i++) {
      var mapSource = map.mapSources[map.mapSourceNames[i]];
      if (mapSource.type == "tile") {
        if ((mapSource.level + inORout) < 0 || (mapSource.level + inORout) >= mapSource.numLevels) return;
        mapSource.level += inORout;
        mapSource.changeLevel(mapSource.level);
      }
      else mapSource.changeLevel(inORout);
    }
  }
}

function EsriMapSlider(id, container, mapId, numLevels, initLevel, left, top) {
  this.inheritsFrom(new EsriSlider(id, null, changeZoomLevel, left, top));
  this.numSegments = numLevels;
  this.initValue = initLevel;
  this.isHorizontal = false;
  this.showTicks = true;
  this.roundValues = true;
  this.callContinuously = false;
  var self = this;

  function changeZoomLevel(value) {
    var map = EsriControls.maps[mapId];
    for (var i=0;i<map.mapSourceNames.length;i++) map.mapSources[map.mapSourceNames[i]].changeLevel(value);
  }

  this.update = function(map) { self.setValue(map.mapSources[map.mapSourceNames[0]].level); }
  EsriControls.maps[mapId].addUpdateListener(id, this.update);
  if (container) this.init(container);
}

⌨️ 快捷键说明

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