📄 esri_core.js
字号:
this.sendAjaxRequest = function(url, params, doGET, callback, contentType) {
try {
var xh = this.createXmlHttpObject();
xh.onreadystatechange = callback;
if (doGET) {
xh.open("GET", url + "?" + params, true);
xh.send(null);
}
else {
xh.open("POST", url, true);
if (contentType) xh.setRequestHeader("content-type", contentType);
xh.send(params);
}
return xh;
}
catch (exception) { return null; }
}
function decToHex(d) { return "0123456789abcdef".substring(d, d+1); }
function hexToDec(h) { return "0123456789abcdef".indexOf(h); }
this.toHex = function(n) { return (decToHex((0xf00000 & n) >> 20) + decToHex((0x0f0000 & n) >> 16) + decToHex((0x00f000 & n) >> 12) + decToHex((0x000f00 & n) >> 8) + decToHex((0x0000f0 & n) >> 4) + decToHex((0x00000f & n) >> 0)); }
this.fromHex = function(h) {
while (h.length < 6) h = "0" + h;
return ((hexToDec(h.substring(0,1)) << 20) + (hexToDec(h.substring(1,2)) << 16) + (hexToDec(h.substring(2,3)) << 12) + (hexToDec(h.substring(3,4)) << 8) + (hexToDec(h.substring(4,5)) << 4) + (hexToDec(h.substring(5,6))));
}
}
function EsriPageElement(id, l, t, w, h) {
this.id = id;
this.bounds = new EsriRectangle((l) ? l : 0, (t) ? t : 0, (w) ? w : 0, (h) ? h : 0);
this.divId = "";
this.divObject = null;
this.resize = function(wd, ht) {
this.bounds.reshape(this.bounds.left, this.bounds.top, wd, ht);
EsriUtils.setElementStyle(this.divObject, "width:" + wd + "px; height:" + ht + "px;");
}
}
EsriPageElement.prototype.show = function() { EsriUtils.showElement(this.divObject); }
EsriPageElement.prototype.hide = function() { EsriUtils.hideElement(this.divObject); }
function EsriControl(id, ct, l, t, w, h) {
this.inheritsFrom(new EsriPageElement(id, l, t, w, h));
this.type = ct;
this.updateListeners = new Array();
this.updateListenerNames = new Array();
}
EsriControl.prototype.addUpdateListener = function(name, listener) {
if (this.updateListenerNames.indexOf(name) == -1) this.updateListenerNames.push(name);
this.updateListeners[name] = listener;
}
EsriControl.prototype.removeUpdateListener = function(name) {
var index = this.updateListenerNames.indexOf(name);
if (index != -1) {
this.updateListenerNames.splice(index, 1);
this.updateListeners[name] = null;
}
}
var EsriControls = new function() {
this.maps = new Array();
this.mapIds = new Array();
this.toolbars = new Array();
this.toolbarIds = new Array();
this.tocs = new Array();
this.tocIds = new Array();
this.overviews = new Array();
this.overviewIds = new Array();
this.tasks = new Array();
this.taskIds = new Array();
var postBackTagHandlers = new Array();
var postBackTagNames = new Array();
var self = this;
this.addPostBackTagHandler = function(tagName, handler) {
if (postBackTagNames.indexOf(tagName) == -1) {
postBackTagNames.push(tagName);
postBackTagHandlers[tagName] = new Array();
}
if (postBackTagHandlers[tagName].indexOf(handler) != -1) return;
postBackTagHandlers[tagName].push(handler);
}
this.removePostBackTagHandler = function(tagName, handler) {
var i = postBackTagHandlers[tagName].indexOf(handler);
if (i != -1) return postBackTagHandlers[tagName].splice(i, 1);
return null;
}
this.processPostBack = function(xh) {
if (xh != null && xh.readyState == 4 && xh.status == 200) {
var xml = xh.responseXML;
var formTags = xml.getElementsByTagName("form");
if (formTags.length > 0) {
var formTag = formTags.item(0);
var formId = formTag.getElementsByTagName("id").item(0).firstChild.nodeValue;
EsriUtils.removeFormElement(formId, "doPostBack");
var eventSourceTags = formTag.getElementsByTagName("eventsource");
var eventSources = new Array();
for (var i=0;i<eventSourceTags.length;i++) {
var eventSource = eventSourceTags.item(i).firstChild.nodeValue;
eventSources.push(eventSource);
EsriUtils.removeFormElement(formId, eventSource);
EsriUtils.removeFormElement(formId, eventSource + "_value");
EsriUtils.removeFormElement(formId, eventSource + "_mode");
}
}
for (var h=0;h<postBackTagNames.length;h++) {
var tagName = postBackTagNames[h];
var tags = xml.getElementsByTagName(tagName);
for (var i=0;i<tags.length;i++)
for (var l=0;l<postBackTagHandlers[tagName].length;l++)
postBackTagHandlers[tagName][l](tags.item(i), eventSources);
}
for (var m=0;m<self.mapIds.length;m++) {
var map = self.maps[self.mapIds[m]];
map.hideLoading();
if (! map.isFuseGraphics) for (var s=0;s<map.mapSourceNames.length;s++) map.mapSources[map.mapSourceNames[s]].updateWebGraphics(map.id);
}
}
}
}
function EsriAction() {
this.name = "EsriAction";
this.graphicsZIndex = 49;
this.lineColor = "#f00";
this.lineWidth = 2;
this.lineOpacity = 1;
this.fillColor = "#fff";
this.fillOpacity = 0;
this.cursor = "crosshair";
this.isActive = false;
this.activate = null;
this.deactivate = null;
this.reactivate = function() {}
}
function EsriToolItem(id, tn, act, isM) {
this.id = id;
this.name = tn;
this.action = act;
this.isMarker = isM;
this.showLoading = true;
this.isCommand = this.isDisabled = this.clientPostBack = this.isActive = false;
this.toolTip = this.element = this.control = null;
this.defaultStyle = this.hoverStyle = this.selectedStyle = this.disabledStyle = null;
this.defaultImage = this.hoverImage = this.selectedImage = this.disabledImage = null;
this.activate = function() { if (this.action) this.action.activate(this.element, this.postAction); this.isActive = true; }
this.deactivate = function() { if (this.action) this.action.deactivate(); this.isActive = false; }
this.postAction = null;
}
function EsriDrawLineAction() {
this.inheritsFrom(new EsriAction());
this.name = "EsriDrawLineAction";
var element, callback, contCallback, bounds, startPt, gr;
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;
}
this.deactivate = function() {
this.isActive = false;
if (element != null) {
element.onmousedown = null;
element.style.cursor = "default";
}
if (gr != null) {
gr.destroy();
gr.gc.onmousedown = null;
}
element = startPt = gr = null;
}
this.reactivate = function() {
element.onmousedown = gr.gc.onmousedown = null;
element.onmousemove = gr.gc.onmousemove = null;
element.onmouseup = gr.gc.onmouseup = null;
var e = element;
var c = callback;
var cc = contCallback
this.deactivate();
this.activate(e, c, cc);
}
function processMouseDown(e) {
self.isActive = true;
bounds = EsriUtils.getElementPageBounds(element);
element.onmousedown = gr.gc.onmousedown = null;
element.onmousemove = gr.gc.onmousemove = processMouseMove;
element.onmouseup = gr.gc.onmouseup = processMouseUp;
startPt = EsriUtils.getXY(e).offset(-bounds.left, -bounds.top);
gr.clear();
EsriUtils.stopEvent(e);
return false;
}
function processMouseMove(e) {
gr.clear();
var endPt = EsriUtils.getXY(e).offset(-bounds.left, -bounds.top);
gr.drawLine(startPt, endPt);
EsriUtils.stopEvent(e);
if (contCallback) contCallback(startPt, endPt);
return false;
}
function processMouseUp(e) {
self.isActive = false;
gr.clear();
element.onmousemove = gr.gc.onmousemove = element.onmouseup = gr.gc.onmouseup = null;
element.onmousedown = gr.gc.onmousedown = processMouseDown;
EsriUtils.stopEvent(e);
callback(startPt, EsriUtils.getXY(e).offset(-bounds.left, -bounds.top));
return false;
}
}
function EsriDragElementAction(docIn) {
this.inheritsFrom(new EsriAction());
this.name = "EsriDragElementAction";
var docInput = docIn;
this.cursor = "move";
var element, startPt, callback, contCallback, bounds;
var self = this;
this.activate = function(elem, cbFunc, ccbFunc) {
element = elem;
callback = cbFunc;
contCallback = ccbFunc;
bounds = EsriUtils.getElementBounds(element);
element.style.cursor = this.cursor;
element.onmousedown = processMouseDown;
}
this.deactivate = function() {
this.isActive = false;
if (element != null) {
element.onmousedown = element.onmousemove = element.onmouseup = null;
element.style.cursor = "default";
}
if (docInput) document.onmousedown = document.onmousemove = document.onmouseup = null;
element = startPt = bounds = callback = null;
}
function processMouseDown(e) {
if (! EsriUtils.isLeftButton(e)) return;
startPt = EsriUtils.getXY(e);
element.onmousemove = processMouseMove;
element.onmouseup = processMouseUp;
if (docInput) {
document.onmousemove = processMouseMove;
document.onmouseup = processMouseUp;
}
EsriUtils.stopEvent(e);
return false;
}
function processMouseMove(e) {
var pt = EsriUtils.getXY(e);
self.doDrag(pt.x - startPt.x, pt.y - startPt.y);
EsriUtils.stopEvent(e);
return false;
}
function processMouseUp(e) {
var pt = EsriUtils.getXY(e);
element.onmousemove = element.onmouseup = null;
if (docInput) document.onmousemove = document.onmouseup = null;
self.endDrag(pt.x - startPt.x, pt.y - startPt.y);
EsriUtils.stopEvent(e);
return false;
}
this.doDrag = function(x, y) {
if (! self.isActive) {
bounds = EsriUtils.getElementBounds(element);
self.isActive = true;
}
EsriUtils.moveElement(element, bounds.left + x, bounds.top + y);
if (contCallback) contCallback(x, y);
}
this.endDrag = function(x, y) {
self.isActive = false;
if (x != 0 || y != 0) EsriUtils.moveElement(element, bounds.left + x, bounds.top + y);
callback(x, y);
}
}
function EsriDrawRectShapeAction(shapeType) {
this.inheritsFrom(new EsriAction());
this.name = (shapeType == "Rectangle") ? "EsriDrawRectangleAction" : (shapeType == "Oval") ? "EsriDrawOvalAction" : "EsriDrawRectShapeAction";
var element, bounds, startPt, callback, contCallback, gr;
var shape = (shapeType) ? shapeType : "Rectangle";
var self = this;
this.activate = function(elem, cF, ccF) {
element = elem;
callback = cF;
contCallback = ccF;
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;
element.style.cursor = gr.gc.style.cursor = this.cursor;
element.onmousedown = gr.gc.onmousedown = processMouseDown;
}
this.deactivate = function() {
this.isActive = false;
if (element != null) {
element.onmousedown = null;
element.style.cursor = "default";
}
if (gr != null) {
gr.gc.onmousedown = null;
gr.destroy();
}
element = startPt = gr = null;
}
this.reactivate = function() {
element.onmousedown = gr.gc.onmousedown = null;
element.onmousemove = gr.gc.onmousemove = null;
element.onmouseup = gr.gc.onmouseup = null;
var e = element;
var c = callback;
var cc = contCallback;
this.deactivate();
this.activate(e, c, cc);
}
function normalizeRectangle(point1, point2) {
var left = (point1.x < point2.x) ? point1.x : point2.x;
var top = (point1.y < point2.y) ? point1.y : point2.y;
var width = Math.abs(point1.x - point2.x);
var height = Math.abs(point1.y - point2.y);
return new EsriRectangle(left, top, width, height);
}
function processMouseDown(e) {
self.isActive = true;
bounds = EsriUtils.getElementPageBounds(element);
element.onmousedown = gr.gc.onmousedown = null;
element.onmousemove = gr.gc.onmousemove = processMouseMove;
element.onmouseup = gr.gc.onmouseup = processMouseUp;
startPt = EsriUtils.getXY(e).offset(-bounds.left, -bounds.top);
gr.clear();
eval("gr.draw" + shape + "(new EsriRectangle(startPt.x, startPt.y, 1, 1));");
EsriUtils.stopEvent(e);
return false;
}
function processMouseMove(e) {
var pt = EsriUtils.getXY(e).offset(-bounds.left, -bounds.top);
var rect = normalizeRectangle(startPt, pt);
gr.clear();
eval("gr.draw" + shape + "(rect);");
EsriUtils.stopEvent(e);
if (contCallback) contCallback(rect);
return false;
}
function processMouseUp(e) {
self.isActive = false;
var pt = EsriUtils.getXY(e).offset(-bounds.left, -bounds.top);
var rect = normalizeRectangle(startPt, pt);
gr.clear();
element.onmousemove = gr.gc.onmousemove = element.onmouseup = gr.gc.onmouseup = null;
element.onmousedown = gr.gc.onmousedown = processMouseDown;
EsriUtils.stopEvent(e);
callback(rect);
}
}
function EsriDrawRectangleAction() { return new EsriDrawRectShapeAction("Rectangle"); }
function EsriDrawOvalAction() { return new EsriDrawRectShapeAction("Oval"); }
function EsriDrawPointAction() {
this.inheritsFrom(new EsriAction());
this.name = "EsriDrawPointAction";
var element, callback, bounds;
this.cursor = "pointer";
var self = this;
this.activate = function(elem, callbackFunc) {
element = elem;
callback = callbackFunc;
element.style.cursor = this.cursor;
bounds = EsriUtils.getElementPageBounds(element);
element.onmousedown = processMouseDown;
}
this.deactivate = function() {
this.isActive = false;
if (element != null) {
element.style.cursor = "default";
element.onmousedown = null;
}
element = bounds = callback = null;
}
this.reactivate = function() {
element.onmousedown = null;
var e = element;
var c = callback;
this.deactivate();
this.activate(e, c);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -