📄 smismapcontrolie.js
字号:
//debug
//重新调整一下位置?
return;
}
map.ImageCellsAdded = true;
var mapUrl = document.getElementById(mapId + "_MapUrl");
if(!mapUrl || !mapUrl.value) { return; }
mapUrl = mapUrl.value;
// when ImageHandlerEnabled, mapUrl = "ImageHandler.ashx?IU=" + mapUrl.
//TODO: 下面这一段需要修改。 --ahnan 2006-02-06
var handler = "";
if(mapUrl.indexOf("ImageHandler.ashx?URL=") == 0) { handler = "ImageHandler.ashx?IU="; }
mapUrl = mapUrl.replace(handler, "");
mapUrl = mapUrl.replace(/localhost/g, document.getElementById(mapId + "_MapServer_Address").value);
var workLayer = SMISGetWorkLayer(mapId);
with(workLayer.style) {
position = "absolute";
overflow = "hidden";
pixelLeft = map.offset.x;
pixelTop = map.offset.y;
zIndex = -100;
width = map.style.width;
height = map.style.height;
// border = "1px dotted red";
}
var div = document.getElementById(mapId + "_ImageCellContainer");
if(!div){
div = document.createElement("DIV");
div.id = mapId + "_ImageCellContainer";
div.style.position = "absolute";
workLayer.appendChild(div);
}
div.style.left = 0;
div.style.top = 0;
var img = document.getElementById(mapId + "_Cells_" + "-1");
if(mapUrl.indexOf("{") == -1) { // 只有图片地址。 //
if(!img) {
img = document.createElement("IMG");
img.id = mapId + "_Cells_" + "-1";
div.appendChild(img);
}
// 如果图片已经被IE缓存过,img.onload 事件将可能在指定img.src之后立刻触发,所以应当把事件注册写在前面。 //
img.onload = function anonymous() { hideBusyFlag(mapId); }
img.src = mapUrl;
img.style.position = "absolute";
// img.style.border = "1px dotted gray";
img.style.left = 0;
img.style.top = 0;
img = null;
div = null;
HideObsoleteCells(0, mapId + "_Cells_"); //隐藏自-1以后的Cells.
return;
}
if(img) {
img.style.visibility = "hidden";
img = null;
}
eval("var objMapUrl = " + mapUrl);
var countX, countY, cellWidth, cellHeight, leftBottomOffset, rightTopOffset, arrUrls;
countX = objMapUrl.countX;
countY = objMapUrl.countY;
if(countX > 20 || countY > 20) { if(!confirm("Too many pictures, are you sure?")) return; }
map.MapUrlCount = countX*countY;
cellWidth = objMapUrl.cellWidth;
cellHeight = objMapUrl.cellHeight;
offsetLT = new SMISPoint(objMapUrl.offsetLTX, objMapUrl.offsetLTY);
offsetRB = new SMISPoint(objMapUrl.offsetRBX, objMapUrl.offsetRBY);
div.style.left = (-offsetLT.x)+"px";
div.style.top = (-offsetLT.y)+"px";
if(div.origin){
// alert(div.origin.x);
div.origin.x = div.style.pixelLeft;
div.origin.y = div.style.pixelTop;
// alert(div.origin.x);
}
offsetLT.x = 0;
offsetLT.y = 0;
arrUrls = objMapUrl.urls.split("|");
var arrImg = new Array();
var img;
for(var i=0; i<countX; i++) {
for(var j=0; j<countY; j++) {
img = document.getElementById(mapId + "_Cells_" + (i*countY+j)); // reuse old image element.
if(!img) {
img = document.createElement("IMG");
img.id = mapId + "_Cells_" + (i*countY+j);
div.appendChild(img);
}
// img.onload = function anonymous() { this.style.visibility = "visible"; };
img.style.visibility = "hidden";
img.src = handler + arrUrls[i*countY+j];
with(img.style) {
if(__DEBUG__){ border = "1px dotted blue"; }
position = "absolute";
pixelLeft = cellWidth * i - offsetLT.x;
pixelTop = cellHeight * j - offsetLT.y;
pixelWidth = cellWidth;
pixelHeight = cellHeight;
if(pixelLeft + pixelWidth < 0 || pixelTop + pixelHeight < 0 ||
pixelLeft - map.style.pixelWidth > 0 || pixelTop - map.style.pixelHeight > 0){
//visibility = "hidden";
}
// window.status += "(" + i + "" + j + ":" + pixelLeft + "," + pixelTop + ")";
}
arrImg[arrImg.length] = img;
//workLayer.appendChild(img);
}
}
img = null;
// 先显示中间的...
var middle = Math.round(countX * countY / 2);
var createdImg;
var createdImgID;
for(var i=0; i<=middle; i++) {
createdImgID = mapId + "_Cells_" + (middle - i);
if(__DEBUG__){ window.status += ";" + (middle - i);}
createdImg = arrImg[middle - i];
if(createdImg) {
createdImg.style.visibility = "";
// div.appendChild(arrImg[middle - i]);
}
createdImgID = mapId + "_Cells_" + (middle + i);
if(__DEBUG__){window.status += "," + (middle + i);}
createdImg = arrImg[middle + i];
if(createdImg) {
createdImg.style.visibility = "";
// div.appendChild(arrImg[middle + i]);
}
}
HideObsoleteCells(countX*countY, mapId + "_Cells_");
if(__DEBUG__){ window.status = "ALL:" + (countX * countY); }
while(arrImg && arrImg.length > 0) { arrImg.pop(); }
arrImg = null;
div = null;
workLayer = null;
hideBusyFlag(mapId);
}
//-------------------- end of the third part ----------------------------//
function SMISGetWorkLayer(mapId)
{
var workLayer = document.getElementById(mapId + "_WorkLayer");
if(!workLayer) {
workLayer = document.createElement("DIV");
workLayer.id = mapId + "_WorkLayer";
var mapDiv = document.getElementById(mapId);
mapDiv.appendChild(workLayer);
}
return workLayer;
}
function PanMapCells(map, startPoint, curPoint)
{
if(!map) { return; }
if(!map.MapUrlCount) { map.MapUrlCount = 1; }
var workLayer = SMISGetWorkLayer(map.mapId);
var container = workLayer.childNodes[0];
with(container.style){
if(!container.origin) { container.origin = new SMISPoint(pixelLeft, pixelTop); }
pixelLeft = container.origin.x + curPoint.x - startPoint.x;
pixelTop = container.origin.y + curPoint.y - startPoint.y;
}
return;
var img;
for(var i=0; i<map.MapUrlCount; i++){
img = document.getElementById(map.id.split('_')[0] + "_Cells_" + i);
if(!img) { continue; }
with(img.style){
if(!img.origin) { img.origin = new SMISPoint(pixelLeft, pixelTop); }
pixelLeft = img.origin.x + curPoint.x - startPoint.x;
pixelTop = img.origin.y + curPoint.y - startPoint.y;
}
}
img = null;
}
function PanWorkLayer(map, startPoint, curPoint)
{
if(!map) { return; }
var workLayer = SMISGetWorkLayer(map.mapId);
if(!workLayer) { return; }
with(workLayer.style){
if(!workLayer.origin) { workLayer.origin = new SMISPoint(pixelLeft, pixelTop); }
pixelLeft = workLayer.origin.x + curPoint.x - startPoint.x;
pixelTop = workLayer.origin.y + curPoint.y - startPoint.y;
}
}
function StartDefaultAction(map, actionName)
{
try{ map.style.cursor = 'images/cur_' + actionName + '.cur';}catch(e){map.style.cursor = 'crosshair';}
switch(actionName){
// DrawRect
case 'ZOOMIN':
case 'ZOOMOUT':
case 'RECTQUERY':
map.onmousedown = SMISOnMouseDown;
map.onmousemove = SMISRectOnMouseMove;
map.onmouseup = SMISOnMouseUp;
map.onclick = null;
map.ondblclick = null;
break;
// Pan
case 'PAN':
map.onmousedown = SMISPanOnMouseDown;
map.onmousemove = SMISPanOnMouseMove;
map.onmouseup = SMISOnMouseUp;
map.onclick = null;
map.ondblclick = null;
break;
// DrawLines
case 'MEASUREDIS':
case 'FINDPATH':
map.PolygonClosed = false;
map.onmousedown = null;
map.onmousemove = SMISPolygonOnMouseMove;
map.onmouseup = null;
map.onclick = SMISPolygonOnMouseClick;
map.ondblclick = SMISPolygonOnDblClick;
break;
// DrawPolygon
case 'MEASUREAREA':
case 'POLYGONQUERY':
map.PolygonClosed = true;
map.onmousedown = null;
map.onmousemove = SMISPolygonOnMouseMove;
map.onmouseup = null;
map.onclick = SMISPolygonOnMouseClick;
map.ondblclick = SMISPolygonOnDblClick;
break;
// Click
case 'POINTQUERY':
case 'CLOSESTFACILITY':
map.bActionStarted = true;
map.onmousedown = null;
map.onmousemove = null;
map.onmouseup = SMISOnMouseUp;
map.onclick = null;
map.ondblclick = null;
break;
// DrawCircle
case 'CIRCLEQUERY':
map.onmousedown = SMISOnMouseDown;
map.onmousemove = SMISCircleOnMouseMove;
map.onmouseup = SMISCircleOnMouseUp;
map.onclick = null;
map.ondblclick = null;
break;
}
}
//TODO.
function RenderQuickPan(mapId, description, quickPanWidth, quickPanHeight, prefix)
{
var mapDiv = document.getElementById(mapId);
var theform = document.forms[0];
var quickPanInputId = mapId + "_QuickPanInput";
SMISCreateHiddenField(theform, quickPanInputId, quickPanInputId, "");
var quickPanDescs = description.split(","); // left, up, right, down
if(!quickPanDescs) { quickPanDescs = new Array(4); }
for(var i=4; i<quickPanDescs.length; i--) { quickPanDescs.push(""); }
var StrDivFormat = "<div id={0} width=" + quickPanWidth + " height=" + quickPanHeight + " border=0 cellspacing=0 cellpadding=0 style='position:absolute; cursor:pointer; visibility:hidden;' title='{1}'>";
StrDivFormat += "<img src=\"{2}\" onclick=\"document.getElementById('" + quickPanInputId + "').value='{3}'; " + mapId + "_DoPostBack();\">";
StrDivFormat += "</div>";
var strDivLeft = StrDivFormat.replace("{0}", mapId + "_QuickPanDiv_L");
strDivLeft = strDivLeft.replace("{1}", quickPanDescs[0]);
strDivLeft = strDivLeft.replace("{2}", prefix.replace("{0}", "L"));
strDivLeft = strDivLeft.replace("{3}", "L");
var divLeft = document.createElement("DIV");
divLeft.innerHTML = strDivLeft;
mapDiv.appendChild(divLeft);
var strDivUp = StrDivFormat.replace("{0}", mapId + "_QuickPanDiv_U");
strDivUp = strDivUp.replace("{1}", quickPanDescs[1]);
strDivUp = strDivUp.replace("{2}", prefix.replace("{0}", "U"));
strDivUp = strDivUp.replace("{3}", "U");
var divUp = document.createElement("DIV");
divUp.innerHTML = strDivUp;
mapDiv.appendChild(divUp);
var strDivRight = StrDivFormat.replace("{0}", mapId + "_QuickPanDiv_R");
strDivRight = strDivRight.replace("{1}", quickPanDescs[2]);
strDivRight = strDivRight.replace("{2}", prefix.replace("{0}", "R"));
strDivRight = strDivRight.replace("{3}", "R");
var divRight = document.createElement("DIV");
divRight.innerHTML = strDivRight;
mapDiv.appendChild(divRight);
var strDivDown = StrDivFormat.replace("{0}", mapId + "_QuickPanDiv_D");
strDivDown = strDivDown.replace("{1}", quickPanDescs[3]);
strDivDown = strDivDown.replace("{2}", prefix.replace("{0}", "D"));
strDivDown = strDivDown.replace("{3}", "D");
var divDown = document.createElement("DIV");
divDown.innerHTML = strDivDown;
mapDiv.appendChild(divDown);
}
function MapControl_Callback(argument)
{
var mapId = argument.split("||")[0];
argument=argument.split("||")[1];
var mapUrl = document.getElementById(mapId + "_MapUrl");
if(!mapUrl) return;
mapUrl.value = argument;
var map = SMISGetMap(mapId);
map.ImageCellsAdded = false;
var workLayer = SMISGetWorkLayer(mapId);
if(workLayer){
// workLayer.innerHTML = "";
}
AddImageCellsToWorkLayer(mapId);
hideBusyFlag(mapId);
if(map.bActionStarted){
map.bActionStarted = false;
}
map = null;
workLayer = null;
}
function GetMouseScrollDelta(e)
{
if(e.wheelDelta){return e.wheelDelta;}
else if(e.detail){return -e.detail;}
return 0;
}
function SMISOnMouseWheel(e)
{
if(!e)e=window.event;
var map = this;
if(this.map){map=this.map;}
if(!map){alert(1);return false;}
if(map.bWheeling){return false;}
map.bWheeling = true;
var delta=GetMouseScrollDelta(e);
var argument = "ZoomByPixel";
var params = "";
var relativePos = SMISGetMouseMapRelativePosition(map);
if(delta>0){
params = relativePos.x + "&" + relativePos.y + "&0.5";
map.DoCallback(argument, params);
}
else if(delta<0){
params = relativePos.x + "&" + relativePos.y + "&2";
map.DoCallback(argument, params);
}
map.bWheeling = false;
e.cancelBubble=true;
return false;
}
function GetTarget(e)
{
if(!e)e=window.event;var t=null;
if(e.srcElement)t=e.srcElement;
else if(e.target)t=e.target;
if(t.nodeType==3)t=targ.parentNode; //Text node.
return t;
}
function AddOnMouseWheelFunction(mapId)
{
//debug.
return;
var map = SMISGetMap(mapId);
if(!map.DoCallback) { map.DoCallback = Map_DoCallback; }
map.onmousewheel = SMISOnMouseWheel;
}
function HideObsoleteCells(endIndex, prefix)
{
var start = parseInt(endIndex);
var img;
while(true){
img = document.getElementById(prefix + start);
// alert(prefix + start);
if(!img){break;}
img.style.visibility = "hidden";
img.src = "images/spacer.gif";
start++;
}
img = null;
}
//-------------------- end of the forth part ----------------------------//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -