esri_core.js
来自「esri的ArcGIS Server超级学习模板程序(for java)」· JavaScript 代码 · 共 1,599 行 · 第 1/4 页
JS
1,599 行
createGraphic = false;
}
else {
gr = EsriUtils.createGraphicsElement(element.id + "_gr", element);
EsriUtils.setElementStyle(gr.gc, "z-index:" + this.graphicsZIndex + ";");
}
element.style.cursor = self.cursor;
element.onmousedown = gr.gc.onmousedown = processMouseDown;
}
this.deactivate = function() {
this.isActive = false;
if (element != null) {
element.onmousedown = element.onmousemove = element.onmouseup = null;
element.style.cursor = "default";
}
if (gr != null) {
gr.gc.onmousedown = gr.gc.onmousemove = gr.gc.onmouseup = null;
if (graphic) gr.remove(graphic);
if (createGraphic) gr.destroy();
}
element = startPt = gr = graphic = 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;
var ge = createGraphics ? null : gr;
this.deactivate();
this.activate(e, c, cc, ge);
}
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);
if (graphic) gr.remove(graphic);
EsriUtils.stopEvent(e);
return false;
}
function processMouseMove(e) {
if (graphic) gr.remove(graphic);
var endPt = EsriUtils.getXY(e).offset(-bounds.left, -bounds.top);
graphic = gr.drawLine(startPt, endPt, self.symbol);
EsriUtils.stopEvent(e);
if (contCallback) contCallback(startPt, endPt);
return false;
}
function processMouseUp(e) {
if (graphic) gr.remove(graphic);
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));
self.isActive = false;
return false;
}
}
function EsriDragElementAction(docIn, enableMouseOut) {
this.inheritsFrom(new EsriAction());
this.name = "EsriDragElementAction";
var docInput = docIn;
var enMouseOut = enableMouseOut;
this.cursor = "move";
var element, startPt, callback, contCallback, bounds, movePt;
var self = this;
this.activate = function(elem, cbFunc, ccbFunc) {
element = elem;
callback = cbFunc;
contCallback = ccbFunc;
element.style.cursor = self.cursor;
element.onmousedown = processMouseDown;
}
this.deactivate = function() {
this.isActive = false;
if (element != null) {
element.onmousedown = element.onmousemove = element.onmouseup = element.onmouseout = 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;
self.isActive = true;
bounds = EsriUtils.getElementBounds(element);
startPt = EsriUtils.getXY(e);
element.onmousemove = processMouseMove;
element.onmouseup = processMouseUp;
if (enMouseOut) element.onmouseout = processMouseOut;
if (docInput) {
document.onmousemove = processMouseMove;
document.onmouseup = processMouseUp;
}
EsriUtils.stopEvent(e);
return false;
}
function processMouseMove(e) {
var pt = movePt = 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 = element.onmouseout = null;
if (docInput) document.onmousemove = document.onmouseup = null;
self.endDrag(pt.x - startPt.x, pt.y - startPt.y);
EsriUtils.stopEvent(e);
self.isActive = false;
return false;
}
function processMouseOut(e) {
element.onmousemove = element.onmouseup = element.onmouseout = null;
if (docInput) document.onmousemove = document.onmouseup = null;
self.endDrag(movePt.x - startPt.x, movePt.y - startPt.y);
EsriUtils.stopEvent(e);
self.isActive = false;
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, graphic;
var shape = (shapeType) ? shapeType : "Rectangle";
var createGraphic = true;
var self = this;
this.activate = function(elem, cF, ccF, ge) {
element = elem;
callback = cF;
contCallback = ccF;
if (ge) {
gr = ge;
createGraphic = false;
}
else {
gr = EsriUtils.createGraphicsElement(element.id + "gr", element);
EsriUtils.setElementStyle(gr.gc, "z-index:" + this.graphicsZIndex + ";");
}
element.style.cursor = self.cursor;
element.onmousedown = gr.gc.onmousedown = processMouseDown;
}
this.deactivate = function() {
this.isActive = false;
if (element != null) {
element.onmousedown = element.onmousemove = element.onmouseup = null;
element.style.cursor = "default";
}
if (gr != null) {
gr.gc.onmousedown = gr.gc.onmousemove = gr.gc.onmouseup = null;
if (graphic) gr.remove(graphic);
if (createGraphic) gr.destroy();
}
element = startPt = gr = graphic = 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;
var ge = createGraphic ? null : gr;
this.deactivate();
this.activate(e, c, cc);
}
function normalizeRectangle(point1, point2) {
if (point1 && point2 && point1.x && point1.y && point2.x && point2.y) {
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);
}
else return null;
}
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);
if (graphic) gr.remove(graphic);
eval("graphic = gr.draw" + shape + "(new EsriRectangle(startPt.x, startPt.y, 1, 1), self.symbol);");
EsriUtils.stopEvent(e);
return false;
}
function processMouseMove(e) {
var pt = EsriUtils.getXY(e).offset(-bounds.left, -bounds.top);
var rect = normalizeRectangle(startPt, pt);
if (rect) {
gr.remove(graphic);
eval("graphic = gr.draw" + shape + "(rect, self.symbol);");
if (contCallback) contCallback(rect);
}
EsriUtils.stopEvent(e);
return false;
}
function processMouseUp(e) {
self.isActive = false;
var pt = EsriUtils.getXY(e).offset(-bounds.left, -bounds.top);
var rect = normalizeRectangle(startPt, pt);
if (rect) {
if (graphic) gr.remove(graphic);
element.onmousemove = gr.gc.onmousemove = element.onmouseup = gr.gc.onmouseup = null;
element.onmousedown = gr.gc.onmousedown = processMouseDown;
callback(rect);
}
EsriUtils.stopEvent(e);
return false;
}
}
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 = self.cursor;
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);
}
function processMouseDown(e) {
self.isActive = true;
bounds = EsriUtils.getElementPageBounds(element);
var pt = EsriUtils.getXY(e).offset(-bounds.left, -bounds.top);
EsriUtils.stopEvent(e);
callback(pt);
self.isActive = false;
return false;
}
}
function EsriDrawPolyShapeAction(isPolygon) {
this.inheritsFrom(new EsriAction());
this.name = (isPolygon) ? "EsriDrawPolygonAction" : "EsriDrawPolylineAction";
var isPgon = isPolygon;
var element, callback, contCallback, bounds, pts, index, gr, tGr, lineGraphic, closePolyGraphic, polyGraphics;
var createGraphics = true;
var self = this;
this.activate = function(elem, cF, ccF, ge) {
element = elem;
callback = cF;
contCallback = ccF;
polyGraphics = [];
if (ge) {
gr = (tGr = ge);
createGraphics = false;
}
else {
gr = EsriUtils.createGraphicsElement(element.id + "gr", element);
EsriUtils.setElementStyle(gr.gc, "z-index:" + this.graphicsZIndex + ";");
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;
}
element.style.cursor = self.cursor;
element.onmousedown = tGr.gc.onmousedown = processMouseDown;
}
this.deactivate = function() {
this.isActive = false;
if (element != null) {
element.style.cursor = "default";
element.onclick = element.ondblclick = element.onmousemove = element.onmouseup = element.onmousedown = null;
}
clearGraphics();
if (createGraphics) {
if (gr != null) {
gr.gc.onclick = gr.gc.ondblclick = gr.gc.onmousemove = gr.gc.onmouseup = gr.gc.onmousedown = null;
gr.destroy();
}
if (tGr != null) {
tGr.gc.onclick = tGr.gc.ondblclick = tGr.gc.onmousemove = tGr.gc.onmouseup = tGr.gc.onmousedown = null;
if (lineGraphic) tGr.remove(lineGraphic);
if (isPgon && closePolyGraphic) tGr.remove(closePolyGraphic);
tGr.destroy();
}
}
else {
if (gr != null) {
gr.gc.onclick = gr.gc.ondblclick = gr.gc.onmousemove = gr.gc.onmouseup = gr.gc.onmousedown = null;
}
}
element = bounds = pts = index = gr = tGr = lineGraphic = closePolyGraphic = polyGraphics = null;
}
this.reactivate = function() {
element.onmousedown = tGr.gc.onmousedown = null;
element.onclick = tGr.gc.onclick = null;
element.ondblclick = tGr.gc.ondblclick = null;
element.onmousemove = tGr.gc.onmousemove = null;
element.onmouseup = tGr.gc.onmouseup = null;
var e = element;
var c = callback;
var cc = contCallback;
var ge = createGraphics ? null : gr;
this.deactivate();
this.activate(e, c, cc, ge);
}
function clearGraphics() {
if (lineGraphic) tGr.remove(lineGraphic);
if (isPgon && closePolyGraphic) tGr.remove(closePolyGraphic);
for (var i=polyGraphics.length - 1; i>=0; i--) gr.remove(polyGraphics[i]);
}
function processMouseDown(e) {
self.isActive = true;
bounds = EsriUtils.getElementPageBounds(element);
pts = new Array();
index = 0;
pts.push(EsriUtils.getXY(e).offset(-bounds.left, -bounds.top));
EsriUtils.stopEvent(e);
element.onmousedown = tGr.gc.onmousedown = null;
element.onclick = tGr.gc.onclick = processClick;
element.onmousemove = tGr.gc.onmousemove = processMouseMove;
element.ondblclick = tGr.gc.ondblclick = processDblClick;
return false;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?