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

📄 esri_core.js

📁 ARCGIS程序,可以实现查、缩放等功能
💻 JS
📖 第 1 页 / 共 3 页
字号:
/*
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
*/

if (! Object.prototype.inheritsFrom) { Object.prototype.inheritsFrom = function(oSuper) { for (sProperty in oSuper) this[sProperty] = oSuper[sProperty]; } }

if (! Array.prototype.indexOf) {
  Array.prototype.indexOf = function(item) {
    for (var i=0;i<this.length;i++) if (this[i] == item) return i;
    return -1;
  }
}

if (! String.prototype.trim) { String.prototype.trim = function() { return this.replace(/^\s+/g, '').replace(/\s+$/g, ''); } }

if (! String.prototype.endsWith) {
  String.prototype.endsWith = function(str) {
    if (str.length > this.length) return false;
    if (this.lastIndexOf(str) + str.length == this.length) return true;
    return false;
  }
}

function EsriPoint(x, y) {
  this.x = this.y = null;
  this.reshape(x, y);
}

EsriPoint.prototype.reshape = function(x, y) {
  this.x = x;
  this.y = y;
}

EsriPoint.prototype.offset = function(oX, oY) { return new EsriPoint(this.x + oX, this.y + oY); }
EsriPoint.prototype.equals = function(pt) { return this.x == pt.x && this.y == pt.y; }
EsriPoint.prototype.toString = function() { return "EsriPoint [x = " + this.x + ", y = " + this.y + "]"; }

function EsriRectangle(left, top, width, height) {
  this.left = this.top = this.width = this.height = 0;
  this.center = null;
  this.reshape(left, top, width, height);
}

EsriRectangle.prototype.offset = function(oX, oY) {
  var oLeft = this.left + oX;
  var oTop = this.top + oY;
  return new EsriRectangle(oLeft, oTop, this.width, this.height);
}

EsriRectangle.prototype.reshape = function(left, top, width, height) {
  this.left = left;
  this.top = top;
  this.width = width;
  this.height = height;
  this.center = new EsriPoint(this.left + (this.width / 2), this.top + (this.height / 2));
}

EsriRectangle.prototype.scale = function(factor, scaleCenter) {
  var newWd = this.width * factor;
  var newHt = this.height * factor;
  var rect = new EsriRectangle(this.center.x - (newWd / 2), this.center.y - (newHt / 2), newWd, newHt);

  if (scaleCenter) {
    var x = this.center.x - scaleCenter.x;
    var y = this.center.y - scaleCenter.y;
    var shiftX = x * factor;
    var shiftY = y * factor;
    var moveX = shiftX - x;
    var moveY = shiftY - y;
    rect = rect.offset(moveX, moveY);
  }
  return rect;
}

EsriRectangle.prototype.parseStyle = function(style) {
  var a = style.split(";");
  var l = t = w = h = 0;
  for (var i=0;i<a.length;i++) {
    if (a[i] == "") continue;
    var p = a[i].trim().split(":");
    if (p[0] == "" || p[1] == "") continue;
    switch (p[0]) {
      case "left": l = EsriUtils.getStyleValue(p[1]); break;
      case "top" : t = EsriUtils.getStyleValue(p[1]); break;
      case "width" : w = EsriUtils.getStyleValue(p[1]); break;
      case "height" : h = EsriUtils.getStyleValue(p[1]); break;
    }
  }
  this.reshape(l, t, w, h);
  return this;
}

EsriRectangle.prototype.equals = function(rect) { return this.left == rect.left && this.top == rect.top && this.width == rect.width && this.height == rect.height; }
EsriRectangle.prototype.toStyle = function() { return "left:" + this.left + "px; top:" + this.top + "px; width:" + this.width + "px; height:" + this.height + "px;"; }
EsriRectangle.prototype.toString = function() { return "EsriRectangle [left = " + this.left + ", top = " + this.top + ", width = " + this.width + ", height = " + this.height + "]"; }

function EsriColor(r, g, b) {
  this.red = r;
  this.green = g;
  this.blue = b;
}

EsriColor.prototype.fromHex = function(hex) {
  this.red = EsriUtils.fromHex(((hex.charAt(0)=="#") ? hex.substring(1, 7) : hex).substring(0, 2));
  this.green = EsriUtils.fromHex(((hex.charAt(0)=="#") ? hex.substring(1, 7) : hex).substring(2, 4));
  this.blue = EsriUtils.fromHex(((hex.charAt(0)=="#") ? hex.substring(1, 7) : hex).substring(4, 6));
  return this;
}

EsriColor.prototype.fromString = function(s) {
  var cs = s.split(",");
  this.red = parseInt(cs[0]);
  this.green = parseInt(cs[1]);
  this.blue = parseInt(cs[2]);
  return this;
}

EsriColor.prototype.toHex = function() { return "#" + EsriUtils.toHex(this.red).substring(4) + EsriUtils.toHex(this.green).substring(4) + EsriUtils.toHex(this.blue).substring(4); }
EsriColor.prototype.toString = function() { return "EsriColor [red = " + this.red + ", green = " + this.green + ", blue = " + this.blue + "]"; }

function EsriGraphicsElement(id) {
  this.id = id;
  this.gc = null;

  this.lineColor = "#000";
  this.lineOpacity = 1;
  this.lineWidth = 1;
  this.fillColor = "#000";
  this.fillOpacity = 0;

  this.show = function() { EsriUtils.showElement(this.gc); }
  this.hide = function() { EsriUtils.hideElement(this.gc); }
  this.destroy = function() {}
  this.clip = function(rect) {}
  this.clearClip = function() {}
  this.clear = function() {}
  this.drawPoint = function(point) {}
  this.drawLine = function(point1, point2) {}
  this.drawRectangle = function(rect) {}
  this.drawOval = function(bounds) {}
  this.drawCircle = function(center, radius) {}
  this.drawPolyline = function(points) {}
  this.drawPolygon = function(points) {}
  this.drawImage = function(src, left, top, width, height) {}
  this.drawText = function(txt, bounds, style) {}
}

var EsriUtils = new function() {
  var appName = window.navigator.appName.toLowerCase();
  this.isNav = appName.indexOf("netscape") != -1;
  this.isIE = appName.indexOf("microsoft") != -1;

  this.userAgent = navigator.userAgent;
  this.isIE7 = this.userAgent.indexOf("MSIE 7") != -1;
  this.isFF15 = this.userAgent.indexOf("Firefox/1.5") != -1;
  this.navType = "IE";
  this.doPostBack = true;

  if (! this.isIE) {
    if (this.userAgent.indexOf("Firefox") != -1) this.navType = "Firefox";
    else if (this.userAgent.indexOf("Opera") != -1) this.navType = "Opera";
    else if (this.userAgent.indexOf("Safari") != -1) this.navType = "Safari";
    else if (this.userAgent.indexOf("Netscape") != -1) this.navType = "Netscape";
    else this.navType = "Mozilla";
  }

  if (this.isIE) {
    this.graphicsType = "VML";
    document.writeln("<xml:namespace ns=\"urn:schemas-microsoft-com:vml\" prefix=\"v\"/>\n");
    document.writeln("<style type=\"text/css\"> v\\:* { behavior: url(#default#VML);} </style>\n");
  }
  else this.graphicsType = "NS";

  this.leftButton = 1;
  this.rightButton = 2;
  if (this.isNav) this.rightButton = 3;
  this.mouseWheelUnit = 3;
  if (this.isIE) this.mouseWheelUnit = 120;

  this.KEY_LEFT = 37;
  this.KEY_UP = 38;
  this.KEY_RIGHT = 39;
  this.KEY_DOWN = 40;
  this.KEY_ENTER = 13;
  this.KEY_ESCAPE = 27;

  this.hideElement = function(element) { element.style.display = "none"; }
  this.showElement = function(element) { element.style.display = "block"; }
  this.toggleElement = function(element) { (element.style.display.toLowerCase() == "block") ? element.style.display = "none" : element.style.display = "block"; }
  this.moveElement = function(element, left, top) { EsriUtils.setElementStyle(element, "left:" + left + "px; top:" + top + "px;"); }

  this.getXY = function(e) {
    if (this.isIE) return new EsriPoint(window.event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft - 2, window.event.clientY + document.body.scrollTop + document.documentElement.scrollTop - 2);
    else return new EsriPoint(e.pageX, e.pageY);
  }

  this.getEventSource = function(e) {
    if (this.isIE) return window.event.srcElement;
    else return e.target;
  }

  this.stopEvent = function(e) {
    if (this.isIE) {
      window.event.returnValue = false;
      window.event.cancelBubble = true;
    }
    else {
      e.preventDefault();
      e.stopPropagation();
    }
  }

  this.getKeyCode = function(e) {
    if (this.isIE) return window.event.keyCode;
    else return e.keyCode;
  }

  this.getElementBounds = function(e) { return new EsriRectangle(this.getStyleValue(e.style.left), this.getStyleValue(e.style.top), this.getStyleValue(e.style.width), this.getStyleValue(e.style.height)); }

  this.getElementPageBounds = function(e) {
    var eL = eT = 0;
    var elB, etB;
    var eW = e.offsetWidth;
    var eH = e.offsetHeight;
    while(e) {
      elB = 0;
      etB = 0;
      eL += e.offsetLeft;
      eT += e.offsetTop;

      if (e.style && e.style.borderWidth != "") {
        elB = parseInt(e.style.borderWidth);
        etB = parseInt(e.style.borderWidth);
      }
      else if (e.style && e.style.borderLeftWidth != "") {
        elB = parseInt(e.style.borderLeftWidth);
        etB = parseInt(e.style.borderTopWidth);
      }
      if (isNaN(elB)) elB = 0;
      if (isNaN(etB)) etB = 0;

      eL += elB;
      eT += etB;
      e = e.offsetParent;
    }
    return new EsriRectangle(eL, eT, eW, eH);
  }

  this.getPageBounds = function() {
    if (window.innerHeight) return new EsriRectangle(0, 0, window.innerWidth, window.innerHeight);
    else if (document.documentElement.clientHeight) return new EsriRectangle(0, 0, document.documentElement.clientWidth, document.documentElement.clientHeight);
    else if (document.body.clientHeight) return new EsriRectangle(0, 0, document.body.clientWidth, document.body.clientHeight);
    else return new EsriRectangle(0, 0, 0, 0);
  }

  this.isLeftButton = function(e) { return this.getMouseButton(e) == this.leftButton; }

  this.getMouseButton = function(e) {
    if (this.isIE) return window.event.button;
    else return e.which;
  }

  function camelizeStyle(name) {
    var a = name.split("-");
    var s = a[0];
    for (var c=1;c<a.length;c++) s += a[c].substring(0, 1).toUpperCase() + a[c].substring(1);
    return s;
  }

  this.setElementStyle = function(e, css) {
    var es = e.style;
    var ss = css.split(";");
    for (var i=0;i<ss.length;i++) {
      var s = ss[i].split(":");
      s[0] = s[0].trim();
      if (s[0] == "" || ! s[1]) continue;
      eval("es." + camelizeStyle(s[0]) + " = \"" + s[1].trim() + "\"");
    }
  }

  this.getStyleByClassName = function(name) {
    var styleSheets = document.styleSheets;
    name = name.toLowerCase();
    for (var s=0;s<styleSheets.length;s++) {
      var rules;
      if (this.isIE) rules = styleSheets.item(s).rules;
      else rules = styleSheets.item(s).cssRules;
      for (var i=0;i<rules.length;i++) { if (rules.item(i).selectorText.toLowerCase() == name) return rules.item(i).style; }
    }
    return null;
  }

  this.removeElementStyle = function(e, css) {
    var es = e.style;
    var ss = css.split(";");
    for (var i=0;i<ss.length;i++) {
      var s = ss[i].split(":");
      s[0] = s[0].trim();
      if (s[0] == "") continue;
      if (this.isIE) es.removeAttribute(camelizeStyle(s[0]));
      else es.removeProperty(s[0]);
    }
  }

  this.setElementOpacity = function(e, t) {
    if (this.isIE) this.setElementStyle(e, "filter:alpha(opacity=" + (t * 100) + ");");
    else this.setElementStyle(e, "-moz-opacity:" + t + "; opacity:" + t + ";");
  }

  this.cloneElementStyle = function(src, target) {
    var ss = src.style;
    var ts = target.style;
    for (var s in ss) try { eval("ts." + s + " = ss." + s + ";"); } catch (e) {};
  }

  this.getElementsByClassName = function(element, className) {
    var cs = element.getElementsByTagName("*");
    var es = [];
    for (var i=0;i<cs.length;i++) {
      var c = cs.item(i);
      if (c.className.match(new RegExp("(^|\\s)" + className + "(\\s|$)"))) es.push(c);
    }
    return es;
  }

  this.createImage = function(src, width, height) {
    var img;
    if (this.isIE && ! this.isIE7 && ! (src.toLowerCase().endsWith(".gif") || src.toLowerCase().endsWith(".jpg"))) {
      img = document.createElement("div");
      EsriUtils.setElementStyle(img, "width:" + width + "; height:" + height + ";");
      img.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "')";
    }
    else {
      img = document.createElement("img")
      img.src = src;
      EsriUtils.setElementStyle(img, "width:" + width + "; height:" + height + ";");
    }
    return img;
  }

  this.setImageSrc = function(element, src) {
    element.onload = null;
    if (this.isIE && !this.isIE7 && src.endsWith(".png")) {
      element.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "')";
      element.src = "images/pixel.gif";
    }
    else element.src = src;
  }

  this.createGraphicsElement = function(id, cont) { return eval("new Esri" + this.graphicsType + "GraphicsElement(id, cont);"); }

  this.getStyleValue = function(s) {
    if (typeof s == "number") return s;
    var index = s.indexOf("px");
    if (index == -1) {
      index = s.indexOf("%");
      if (index == -1) return s;
      else return parseInt(s.substring(0, index));
    }
    return parseInt(s.substring(0, index));
  }

  this.addFormElement = function(fId, name, value) {
    var eId = fId + "_input_" + name;
    var inp = document.getElementById(eId);
    if (! inp) inp = document.createElement("input");
    inp.type = "HIDDEN";
    inp.id = eId;
    inp.name = name;
    inp.value = value;
    document.forms[fId].appendChild(inp);
  }

  this.removeFormElement = function(fId, name) {
    var inp = document.getElementById(fId + "_input_" + name);
    if (! inp) inp = document.getElementById(name);
    if (inp) inp.parentNode.removeChild(inp);
  }

  this.getJSessionId = function() {
    var start;
    if ((start = document.cookie.indexOf("JSESSIONID=")) != -1) {
      start = document.cookie.indexOf("=", start) + 1;
      var end = document.cookie.indexOf(";", start);
      return document.cookie.substring(start, (end == -1) ? document.cookie.length : end);
    }
    return "";
  }

  this.getServerUrl = function(fId) {
    if (document.forms[fId].action.indexOf(";jsessionid=") != -1) return encodeURI(document.forms[fId].action);
    else if (this.getJSessionId()) return encodeURI(document.forms[fId].action + ";jsessionid=" + this.getJSessionId());
    else return encodeURI(document.forms[fId].action);
  }

  this.createXmlHttpObject = function() {
    if (this.isIE) {
      try { return new ActiveXObject("Msxml2.XMLHTTP"); }
      catch (exception) { return new ActiveXObject("Microsoft.XMLHTTP"); }
    }
    return new XMLHttpRequest();
  }

  this.submitForm = function(fId, async, callbackFunc) {
    if (! async || ! this.doPostBack) {
      this.removeFormElement(fId, "doPostBack");
      document.forms[fId].submit();
    }
    else {
      var form = document.forms[fId];
      var params = "formId=" + fId;
      for (i=0;i<form.elements.length;i++) {
        var e = form.elements[i];
        var eType = e.type;
        var eLow = eType.toLowerCase();
        if (eType && e.name.trim().length > 0) {
          if (eLow == "checkbox") { if (e.checked) params += "&" + e.name + "=" + encodeURIComponent(e.value); }
          else if (eLow == "select-multiple") {
            for (var c=0;c<e.childNodes.length;c++) {
              var child = e.childNodes.item(c);
              if (child.selected) params += "&" + e.name + "=" + encodeURIComponent(child.value);
            }
          }
          else if (eLow != "button") params += "&" + e.name + "=" + encodeURIComponent(e.value);
        }
      }
      var xh = this.sendAjaxRequest(this.getServerUrl(fId), params, false, function() { callbackFunc(xh) }, "application/x-www-form-urlencoded");
    }
  }

⌨️ 快捷键说明

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