📄 esri_map.js
字号:
/*
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
*/
function EsriMap(id, container, formId, wd, ht) {
this.width = (wd) ? wd : (container && container.style.width) ? EsriUtils.getStyleValue(container.style.width) : 400;
this.height = (ht) ? ht : (container && container.style.height) ? EsriUtils.getStyleValue(container.style.height) : 400;
this.inheritsFrom(new EsriControl(id, "Map", 0, 0, this.width, this.height));
this.formId = formId;
var self = this;
this.divId = "MapDiv_" + id;
this.controlDivId = "MapControlDiv_" + id;
this.controlDiv = null;
this.graphics = null;
this.graphicsId = "MapGraphics_" + id;
this.graphicsZIndex = 20;
this.webGraphics = null;
this.webGraphicsId = "MapWebGraphics_" + id;
this.webGraphicsZIndex = 19;
this.isFuseGraphics = false;
this.loadingId = "MapLoading_" + id;
this.loadingImage = null;
this.loadingUrl = EsriControls.contextPath + "images/loading.gif";
this.loadingZIndex = 99;
this.imageGridId = "MapGridDiv_" + id;
this.imageGrid = this.viewBounds = null;
this.currentToolbar = this.currentTool = null;
this.panTool = new EsriMapContinuousPan("emcp_" + id, "emcp_" + id);
this.keyNavigation = new EsriMapKeyNavigation("emkn_" + id, "emkn_" + id);
this.mouseWheelTool = new EsriMapMouseWheel("emmw_" + id, "emmw_" + id);
this.mapSources = [];
this.mapSourceNames = [];
this.scaleBarId = "ScaleBar_" + id
this.scaleBarDiv = null;
this.scaleBar = null;
this.scaleBarTypeNames = ["Alternating", "SteppedScaleLine", "SingleDivision", "DoubleAlternating"];
this.scaleBarTypes = [];
this.scaleBarTypes["Alternating"] = "EsriAlternatingScaleBarRenderer";
this.scaleBarTypes["SteppedScaleLine"] = "EsriSteppedScaleLineRenderer";
this.scaleBarTypes["SingleDivision"] = "EsriSingleDivisionScaleBar";
this.scaleBarTypes["DoubleAlternating"] = "EsriDoubleAlternatingScaleBarRenderer";
this.numLevels = 0;
this.level = 0;
this.zoomBeyondCache = false;
this.enableMapTips = true;
this.mapTip = null;
this.callOut = null;
this.init = function(container) {
if (! this.width || ! this.height) {
var size = EsriUtils.getElementPageBounds(container);
if (size.width && size.height) {
this.width = size.width;
this.height = size.height;
}
}
this.bounds = new EsriRectangle(0, 0, this.width, this.height);
this.viewBounds = new EsriRectangle(0, 0, this.width, this.height);
this.divObject = container.appendChild(document.createElement("div"));
this.divObject.id = this.divId;
EsriUtils.setElementStyle(this.divObject, "width:" + this.width + "px; height:" + this.height + "px; overflow:hidden;");
this.controlDiv = this.divObject.appendChild(document.createElement("div"));
this.controlDiv.id = this.controlDivId;
this.controlDiv.align = "left";
EsriUtils.setElementStyle(this.controlDiv, "position:relative; width:" + this.width + "px; height:" + this.height + "px; overflow:hidden;");
this.imageGrid = this.controlDiv.appendChild(document.createElement("div"));
this.imageGrid.id = this.imageGridId;
EsriUtils.setElementStyle(this.imageGrid, "position:absolute; left:0px; top:0px; width:" + this.width + "px; height:" + this.height + "px;");
this.graphics = EsriUtils.createGraphicsElement(this.graphicsId, this.imageGrid);
EsriUtils.setElementStyle(this.graphics.gc, "z-index:" + this.graphicsZIndex + ";");
this.divObject.onmouseover = function() { self.panTool.activate(); };
this.divObject.onmouseout = function() { self.panTool.deactivate(); };
this.loadingImage = this.controlDiv.appendChild(document.createElement("img"));
this.loadingImage.id = this.loadingId;
this.loadingImage.src = this.loadingUrl;
this.loadingImage.className = "esriLoadingImage";
EsriUtils.setElementStyle(this.loadingImage, "display:none; z-index:" + this.loadingZIndex + ";");
for (var i=0;i<this.mapSourceNames.length;i++) {
this.mapSources[this.mapSourceNames[i]].update(this);
this.mapSources[this.mapSourceNames[i]].updateImages(this.viewBounds);
}
this.updateWebGraphics();
this.panTool.control = this.keyNavigation.control = this.mouseWheelTool.control = this;
this.panTool.element = this.imageGrid;
this.keyNavigation.element = this.mouseWheelTool.element = this.divObject;
this.panTool.activate();
this.keyNavigation.activate();
this.mouseWheelTool.activate();
EsriControls.addPostBackTagHandler("map", EsriControls.maps[self.id].updateAsync);
var args ={};
args.container = this.controlDiv;
this.callOut = new EsriCallOut(this.controlDivId,args);
this.mapTip = new EsriMapTip(this.id);
}
this.updateAsync = function(xml, eventSources) {
var idTag = xml.getElementsByTagName("id").item(0);
if (idTag.firstChild.nodeValue == self.id) {
self.width = parseInt(xml.getElementsByTagName("width").item(0).firstChild.nodeValue);
self.height = parseInt(xml.getElementsByTagName("height").item(0).firstChild.nodeValue);
self.bounds.reshape(0, 0, self.width, self.height);
self.viewBounds.reshape(0, 0, self.width, self.height);
self.enableMapTips = xml.getElementsByTagName("enable-info-window").item(0).firstChild.nodeValue == "true";
self.isFuseGraphics = xml.getElementsByTagName("control-fuse-graphics").item(0).firstChild.nodeValue == "true";
self.zoomBeyondCache = xml.getElementsByTagName("zoom-beyond-cache").item(0).firstChild.nodeValue == "true";
if (self.webGraphics) EsriUtils.hideElement(self.webGraphics);
EsriUtils.setElementStyle(self.divObject, "width:" + self.width + "px; height:" + self.height + "px; overflow:hidden;");
EsriUtils.setElementStyle(self.controlDiv, "position:relative; width:" + self.width + "px; height:" + self.height + "px; overflow:hidden;");
EsriUtils.setElementStyle(self.imageGrid, "position:absolute; left:0px; top:0px; width:" + self.width + "px; height:" + self.height + "px;");
EsriUtils.setElementStyle(self.loadingImage, "display:none; z-index:" + self.loadingZIndex + ";");
self.removeAllMapSources();
self.clearImages();
var tlcTags = xml.getElementsByTagName("tile-levels-count");
if (tlcTags.length > 0) {
self.numLevels = parseInt(tlcTags.item(0).firstChild.nodeValue);
self.level = parseInt(xml.getElementsByTagName("tile-level").item(0).firstChild.nodeValue);
}
var dataSourcesTags = xml.getElementsByTagName("data-sources");
if (dataSourcesTags.length > 0) {
var dataSourcesTag = dataSourcesTags.item(0);
var dataSourceTags = dataSourcesTag.getElementsByTagName("data-source");
if (dataSourceTags.length > 0) {
for (var i=(dataSourceTags.length-1);i>=0;i--) {
var dataSourceTag = dataSourceTags.item(i);
var transparency = dataSourceTag.getAttribute("transparency");
transparency = (transparency) ? parseFloat(transparency) : 1;
var tileTags = dataSourceTag.getElementsByTagName("tile");
var dynamicTags = dataSourceTag.getElementsByTagName("dynamic");
if (tileTags.length > 0) {
tileTag = tileTags.item(0);
var mapSource = new EsriMapSourceTile(tileTag.getElementsByTagName("base-url").item(0).firstChild.nodeValue);
mapSource.filesys = tileTag.getElementsByTagName("file-sys").item(0).firstChild.nodeValue == "true";
mapSource.showNoData = false;
mapSource.imageOpacity = transparency;
var formatTags = tileTag.getElementsByTagName("image-format");
if (formatTags.length > 0)
mapSource.fileFormat = formatTags.item(0).firstChild.nodeValue;
mapSource.imageWidth = parseInt(tileTag.getElementsByTagName("tile-width").item(0).firstChild.nodeValue);
mapSource.imageHeight = parseInt(tileTag.getElementsByTagName("tile-height").item(0).firstChild.nodeValue);
mapSource.numLevels = parseInt(tileTag.getElementsByTagName("levels-count").item(0).firstChild.nodeValue);
mapSource.level = parseInt(tileTag.getElementsByTagName("level").item(0).firstChild.nodeValue);
mapSource.startColumn = parseInt(tileTag.getElementsByTagName("start-column").item(0).firstChild.nodeValue);
mapSource.endColumn = parseInt(tileTag.getElementsByTagName("end-column").item(0).firstChild.nodeValue);
mapSource.column = parseInt(tileTag.getElementsByTagName("column").item(0).firstChild.nodeValue);
mapSource.startRow = parseInt(tileTag.getElementsByTagName("start-row").item(0).firstChild.nodeValue);
mapSource.endRow = parseInt(tileTag.getElementsByTagName("end-row").item(0).firstChild.nodeValue);
mapSource.row = parseInt(tileTag.getElementsByTagName("row").item(0).firstChild.nodeValue);
mapSource.offsetX = parseInt(tileTag.getElementsByTagName("offsetx").item(0).firstChild.nodeValue);
mapSource.offsetY = parseInt(tileTag.getElementsByTagName("offsety").item(0).firstChild.nodeValue);
self.addMapSource("mapSource" + (i + 1), mapSource, false);
}
else if (dynamicTags.length > 0) {
dynamicTag = dynamicTags.item(0);
var imageUrl = dynamicTag.getElementsByTagName("image-url").item(0).firstChild.nodeValue;
var mapSource = new EsriMapSourceDynamic(self.width, self.height);
mapSource.imageOpacity = transparency;
mapSource = self.addMapSource("mapSource" + (i + 1), mapSource, false);
mapSource.addImage(0, 0, mapSource.generateTileId(0, 0), imageUrl);
}
}
}
}
self.graphics.destroy();
self.graphics = EsriUtils.createGraphicsElement(self.graphicsId, self.imageGrid);
EsriUtils.setElementStyle(self.graphics.gc, "z-index:" + self.graphicsZIndex + ";");
for (var i=0;i<self.mapSourceNames.length;i++) {
self.mapSources[self.mapSourceNames[i]].update(self);
self.mapSources[self.mapSourceNames[i]].updateImages(self.viewBounds);
}
var scalebarTags = xml.getElementsByTagName("scalebar");
if (scalebarTags.length > 0 && self.scaleBar) {
var scalebarTag = scalebarTags.item(0);
var imageUrlTags = scalebarTag.getElementsByTagName("image-url");
if (imageUrlTags.length > 0) self.scaleBar.src = imageUrlTags.item(0).firstChild.nodeValue;
else {
var sd = parseInt(scalebarTag.getElementsByTagName("screen-distance").item(0).firstChild.nodeValue);
var md = parseFloat(scalebarTag.getElementsByTagName("map-distance").item(0).firstChild.nodeValue);
var u = scalebarTag.getElementsByTagName("units").item(0).firstChild.nodeValue;
self.scaleBar.renderer.render(sd, md, u);
}
}
self.reactivateCurrentToolItem();
EsriUtils.removeFormElement(self.formId, self.id);
EsriUtils.removeFormElement(self.formId, self.id + "_mode");
EsriUtils.removeFormElement(self.formId, self.id + "_minx");
EsriUtils.removeFormElement(self.formId, self.id + "_miny");
EsriUtils.removeFormElement(self.formId, self.id + "_maxx");
EsriUtils.removeFormElement(self.formId, self.id + "_maxy");
EsriUtils.removeFormElement(self.formId, self.id + "_coords");
EsriUtils.removeFormElement(self.formId, self.id + "_value");
for (var i=0;i<self.updateListenerNames.length;i++) self.updateListeners[self.updateListenerNames[i]](self);
}
}
this.updateWebGraphics = function() {
if (! this.isFuseGraphics) {
var redisplay = this.webGraphics == null;
if (this.webGraphics) EsriUtils.setElementStyle(this.webGraphics, "width:0px; height:0px;");
var params = "getWebGraphics=getWebGraphics&formId=" + this.formId + "&mapId=" + this.id + "&redisplay=" + redisplay + "&" + EsriUtils.buildRequestParams(this.formId);
EsriUtils.sendAjaxRequest(EsriUtils.getServerUrl(this.formId), params, false, process_updateWebGraphicsResponse);
}
}
function process_updateWebGraphicsResponse(xh) {
if (xh != null && xh.readyState == 4 && xh.status == 200) {
var vb = self.viewBounds;
var xml = EsriUtils.getXmlDocument(xh);
var changed = xml.getElementsByTagName("changed").item(0).firstChild.nodeValue == "true";
self.webGraphics = document.getElementById(self.webGraphicsId);
if (changed) {
if (self.webGraphics) {
EsriUtils.removeElement(self.webGraphics);
self.webGraphics = null;
}
var imageTags = xml.getElementsByTagName("image-url");
if (imageTags.length > 0) {
var img = self.webGraphics = self.imageGrid.appendChild(EsriUtils.createImage(imageTags.item(0).firstChild.nodeValue, vb.width + "px", vb.height + "px"));
img.id = self.webGraphicsId;
EsriUtils.setElementStyle(img, "position:absolute; left:" + vb.left + "px; top:" + vb.top + "px; z-index:" + self.webGraphicsZIndex + ";");
}
}
else if (self.webGraphics) EsriUtils.setElementStyle(self.webGraphics, "position:absolute; left:" + vb.left + "px; top:" + vb.top + "px; width:" + vb.width + "px; height:" + vb.height + "px; z-index:" + self.webGraphicsZIndex + "; display:block;");
}
}
this.centerAt = function(x, y) {
var params = "doContinuousPan=doContinuousPan¢erAt=centerAt&source=" + ((this.numLevels == 0) ? "dynamic" : "tile") + "&formId=" + this.formId + "&mapId=" + this.id + "¢erx=" + x + "¢ery=" + y + "&" + EsriUtils.buildRequestParams(this.formId);
EsriUtils.sendAjaxRequest(EsriUtils.getServerUrl(this.formId), params, false, process_centerAtResponse);
}
function process_centerAtResponse(xh) {
if (xh != null && xh.readyState == 4 && xh.status == 200) {
var xml = EsriUtils.getXmlDocument(xh);
var responseTag = xml.getElementsByTagName("response").item(0);
var mapTags = responseTag.getElementsByTagName("map");
for (var i=0;i<mapTags.length;i++) {
var mapTag = mapTags.item(i);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -