esri_core.js
来自「esri的ArcGIS Server超级学习模板程序(for java)」· JavaScript 代码 · 共 1,599 行 · 第 1/4 页
JS
1,599 行
var s = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "')";
img.src = EsriControls.contextPath + "images/pixel.gif";
if (img.runtimeStyle.filter) img.runtimeStyle.filter = img.runtimeStyle.filter.replace(alphaImageLoaderRegExp, s);
else img.runtimeStyle.filter = s;
}
else img.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.buildRequestParams = function(fId) {
var form = document.forms[fId];
var params = "";
for (i=0;i<form.elements.length;i++) {
var e = form.elements[i];
var eType = e.type;
if (eType && e.name.trim().length > 0) {
var eLow = eType.toLowerCase();
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 == "radio") { if (e.checked) params += "&" + e.name + "=" + encodeURIComponent(e.value); }
else if (eLow != "button" && eLow != "submit") params += "&" + e.name + "=" + encodeURIComponent(e.value);
}
}
return (params.indexOf("&") == 0) ? params.substring(1) : params;
}
this.submitForm = function(fId, async, callbackFunc) {
if (! async || ! this.doPostBack) {
this.removeFormElement(fId, "doPostBack");
document.forms[fId].submit();
}
else {
var params = "formId=" + encodeURIComponent(fId) + "&" + this.buildRequestParams(fId);
this.sendAjaxRequest(this.getServerUrl(fId), params, false, callbackFunc);
}
}
this.sendAjaxRequest = function(url, params, doGET, callback, contentType) {
try {
params = "isXMLHttp=" + encodeURIComponent("true") + "&" + params;
var xh = this.createXmlHttpObject();
xh.onreadystatechange = function() {
if (xh != null && xh.readyState == 4) {
try {
if (xh.status == 200) {
var xml = EsriUtils.getXmlDocument(xh);
var error = EsriUtils.getErrorFromDocument(xml);
if (error !== null) {
if (error)
alert(error);
return false;
}
if (xml) {
var hiddenView = document.getElementById("com.sun.faces.VIEW");
if (hiddenView) {
var viewState = xml.getElementsByTagName("com.sun.faces.VIEW");
if (viewState && viewState.length > 0) {
hiddenView.value = viewState.item(0).firstChild.nodeValue;
}
}else{
hiddenView = document.getElementsByName("com.sun.faces.VIEW");
if (hiddenView && hiddenView.length > 0) {
var viewState = xml.getElementsByTagName("com.sun.faces.VIEW");
if (viewState && viewState.length > 0) {
hiddenView[0].value = viewState.item(0).firstChild.nodeValue;
}
}
else {
hiddenView = document.getElementById("javax.faces.ViewState");
if (hiddenView) {
var viewState = xml.getElementsByTagName("com.sun.faces.VIEW");
if (viewState && viewState.length > 0) {
hiddenView.value = viewState.item(0).firstChild.nodeValue;
}
}
}
}
}
}
else {
window.location.href = EsriControls.contextPath + "error.html";
}
}
catch (exception) {
alert("An error occurred while processing your request.");
window.location.href = EsriControls.contextPath + "error.html";
return false;
}
}
callback(xh);
if (xh != null && xh.readyState == 4) {
xh = null;
}
};
if (doGET) {
xh.open("GET", url + "?" + params, true);
xh.send(null);
}
else {
xh.open("POST", url, true);
xh.setRequestHeader("content-type", (contentType) ? contentType : "application/x-www-form-urlencoded");
xh.send(params);
}
return xh;
}
catch (exception) { return null; }
}
this.getXmlDocument = function(xh) {
var xml = xh.responseXML;
if (xml && xml.firstChild) return xml;
else return this.stringToXml(xh.responseText);
}
this.stringToXml = function(s) {
try {
var xml;
if (EsriUtils.isIE) {
xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = "false";
xml.loadXML(s);
}
else {
var parser = new DOMParser();
xml = parser.parseFromString(s, "text/xml");
}
return xml;
}
catch (e) { return null; }
}
this.getErrorFromDocument = function(xml) {
var errorTags = xml.getElementsByTagName("error");
if (errorTags.length > 0) {
var message = errorTags.item(0).getElementsByTagName("message").item(0).firstChild.nodeValue;
var redirect = "redirect=";
var i = message.indexOf(redirect);
if (i != -1) {
message = message.substring(i + redirect.length);
window.location.href = EsriControls.contextPath + (message.indexOf("/") == 0 ? message.substring(1) : message);
return "";
}
return message;
}
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))));
}
this.getCheckBoxStates = function(root) {
var chks = new Array();
var inputs = root.getElementsByTagName("input");
if (inputs) {
for (var i=0, il=inputs.length; i<il; i++) {
var input = inputs[i];
if (input.type == "checkbox") chks[input.id] = input.checked;
}
}
return chks;
}
this.setCheckBoxStates = function(root, chks) {
var inputs = root.getElementsByTagName("input");
if (inputs) {
for (var i=0, il=inputs.length; i<il; i++) {
var input = inputs[i];
if (input.type == "checkbox" && chks[input.id] != undefined) input.checked = chks[input.id];
}
}
}
this.getXmlText = function(node) {
if(! node) return null;
return node.innerText || node.textContent || (node.firstChild ? node.firstChild.nodeValue : null);
}
}
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;
}
}
if (! window.EsriControls) {
window.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();
this.contextPath = "";
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)
EsriControls.processPostBackXML(EsriUtils.getXmlDocument(xh));
}
this.processPostBackXML = function(xml) {
var formTags = xml.getElementsByTagName("form");
var eventSources = new Array();
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");
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();
map.updateWebGraphics();
}
}
}
}
function EsriAction() {
this.name = "EsriAction";
this.graphicsZIndex = 49;
this.symbol = new EsriGraphicsSymbol("#f00", 1, 2, "#fff", 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, graphic;
var createGraphic = true;
var self = this;
this.activate = function(elem, cbF, ccbF, ge) {
element = elem;
callback = cbF;
contCallback = ccbF;
if (ge) {
gr = ge;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?