📄 smismapcontrolns.js
字号:
function SMISCreateLine(mapId, points)
{
var pointsValue = SMISExtractPoints(points);
var map = SMISGetMap(mapId);
var mapDiv = document.getElementById(mapId);
var editLineId = "SMISEditLine";
var line = document.getElementById(editLineId);
if (!line){
line = document.createElement("div");
document.forms[0].appendChild(line);
line.style.width =map.style.width;
line.style.height =map.style.height;
line.style.left =map.origin.x+"px";
line.style.top = map.origin.y+"px";
line.style.position = "absolute";
line.style.visibility = "visible";
line.id = editLineId;
//line.style.zIndex = map.parentNode.style.zIndex + 200;
line.style.zIndex = 1002;
line.onmousedown = SMISPanOnMouseDown;
line.onmousemove = SMISPanOnMouseMove;
line.onmouseup = SMISOnMouseUp;
line.PointsParam = new SMISPointsParam();
line.origin = map.origin;
line.offset = map.offset;
line.origin.x = map.origin.x;
line.origin.y = map.origin.y;
line.offset.x = map.offset.x;
line.offset.y = map.offset.y;
line.DoPostBack = map.DoPostBack;
line.map = map;
//line.lineOffset = new SMISPoint(line.offsetLeft, line.offsetTop);
var Xpoints = SplitX(pointsValue);
var Ypoints = SplitY(pointsValue);
var jg = new jsGraphics(editLineId);
jg.origin = map.origin;
jg.origin.x = map.origin.x;
jg.origin.y = map.origin.y;
jg.setColor("#ff0000"); // red
jg.setStroke(3);
jg.drawPolyline(Xpoints, Ypoints);
jg.paint();
}
SMISClipPolygon(line);
}
function SMISCreatePoint(mapId, points)
{
// SMISCreatePoint_Img(mapId, points);
// return;
var pointsValue = SMISExtractPoints(points);
var map = SMISGetMap(mapId);
var mapDiv = document.getElementById(mapId);
var editPointId = "SMISEditPoint";
var point = document.getElementById(editPointId);
if(!point)
{
point = document.createElement("div");
document.forms[0].appendChild(point);
point.style.width = map.style.width;
point.style.height = map.style.height;
point.style.left = map.origin.x+"px";
point.style.top = map.origin.y+"px";
point.style.position = "absolute";
point.style.visibility = 'visible';
point.id = editPointId;
point.style.zIndex = 1002;
point.onmousedown = SMISPanOnMouseDown;
point.onmousemove = SMISPanOnMouseMove;
point.onmouseup = SMISOnMouseUp;
point.PointsParam = new SMISPointsParam();
point.origin = map.origin;
point.offset = map.offset;
point.origin.x = map.origin.x;
point.origin.y = map.origin.y;
point.offset.x = map.offset.x;
point.offset.y = map.offset.y;
point.DoPostBack = map.DoPostBack;
point.map = map;
var radius = 30;
var pointx = eval(pointsValue.split(",")[0]) - radius/2;
var pointy = eval(pointsValue.split(",")[1]) - radius/2;
var jg = new jsGraphics(editPointId);
jg.origin = new SMISPoint();
jg.origin.x = map.origin.x;
jg.origin.y = map.origin.y;
jg.setColor("#ff0000"); // red
jg.setStroke(2);
jg.fillEllipse(pointx, pointy,radius,radius);
jg.paint();
}
}
function SMISCreatePoint_Img(mapId, points)
{
var pointWidth = 30;
var pointHeight = 30;
var pointsValue = SMISExtractPoints(points);
var map = SMISGetMap(mapId);
var mapDiv = document.getElementById(mapId);
var editPointId = "SMISEditPoint";
var point = document.getElementById(editPointId);
if(!point){
point = document.createElement("IMG");
point.src = "images/Edit_Point.gif";
point.width = pointWidth;
point.height = pointHeight;
point.style.position = "absolute";
point.style.visibility = "visible";
point.id = editPointId;
point.style.zIndex = map.parentNode.style.zIndex + 200;
mapDiv.appendChild(point);
point.onmousedown = SMISPanOnMouseDown;
point.onmousemove = SMISPanOnMouseMove;
point.onmouseup = SMISOnMouseUp;
point.PointsParam = new SMISPointsParam();
point.origin = new SMISPoint();
// point.offset = map.offset; // 传的是引用。ft。//
point.offset = new SMISPoint();
point.origin.x = map.origin.x;
point.origin.y = map.origin.y;
point.offset.x = map.offset.x;
point.offset.y = map.offset.y;
point.DoPostBack = map.DoPostBack;
point.map = map;
point.lineOffset = new SMISPoint(point.offsetLeft, point.offsetTop);
}
var x = eval(pointsValue.split(",")[0]) + eval(map.offset.x) - pointWidth/2; /* 为Edit_Point.gif图片的1/2宽度 */
var y = eval(pointsValue.split(",")[1]) + eval(map.offset.y) - pointHeight/2; /* 为Edit_Point.gif图片的1/2宽度 */
point.style.left = x + "px";
point.style.top = y + "px";
}
function SMISExtractPoints(points)
{
var pointsValue = "";
if(points){
if( typeof(points) == "object") {
for(var i=0; i<points.length - 1; i++) {
pointsValue += points[i].x + "," + points[i].y + ",";
}
pointsValue += points[i].x + "," + points[i].y;
}
else {
pointsValue = points;
}
}
return pointsValue;
}
function SMISCheckMousePosition(evt,map)
{
var __DEBUG = false;
var absolutePos = SMISGetMouseAbsolutePosition(evt);
var width, height;
if(map.map){
width = map.map.width;
height = map.map.height;
}
else {
width = map.width;
height = map.height;
}
if ( absolutePos.x <= map.origin.x ||
absolutePos.y <= map.origin.y ||
absolutePos.x >= map.origin.x + width ||
absolutePos.y >= map.origin.y + height ){
return false;
}
else{
return true;
}
}
function IsInAbsOrRelStyle(obj)
{
var objTemp = obj;
while(objTemp){
if(objTemp.style){
var temp = objTemp.style.position.toLowerCase();
if( temp == "absolute" || temp == "relative"){
return true;
}
}
objTemp = objTemp.parentNode;
}
return false;
}
function SMISGetOffsetPosition(element, tagName, pos)
{
var _i = 0, _j = 0;
if(typeof(pos) == "undefined" || pos == null){
pos = new SMISPoint(0, 0);
}
while ( ! (element == null || element.tagName == "BODY" || element.tagName.toLowerCase() == tagName) ){
if(element.style){
var temp = element.style.position.toLowerCase();
if(temp == "absolute" || temp == "relative"){
if(_i > 0) { break; }
else { element = element.offsetParent; continue;}
}
}
_i += 1;
pos.x += eval(element.offsetLeft);
pos.y += eval(element.offsetTop);
var bFlag = typeof(element.style.borderLeftWidth) != "unknown";
if(bFlag && element.style.borderLeftWidth != null && element.style.borderLeftWidth != ""){
pos.x += SMISGetNumFromPixel(element.style.borderLeftWidth);
pos.y += SMISGetNumFromPixel(element.style.borderTopWidth);
}
element = element.offsetParent;
}
return pos;
}
function SMISClipPolygon(polygon, inMoving, offsetX, offsetY)
{
if(!offsetX){offsetX=0;}
if(!offsetY){offsetY=0;}
clipTop = -offsetY;
clipRight = polygon.map.width - offsetX;
clipBottom = polygon.map.height - offsetY;
clipLeft = -offsetX;
polygon.style.clip = "rect(" + clipTop + "px " + clipRight + "px " + clipBottom + "px " + clipLeft + "px)";
}
/* 在 SmartNavigation 开启的情况下,建议直接在 HTML 页面中使用 <Body ... Onload="functionName"> 的方式进行注册。 */
function SMISAddFuncToWindowEvent(functionName, eventName)
{
var p_szLoad = functionName;
var eventRef = document.body.onload;
if(eventName == "OnResize")
{
eventRef = document.body.onresize;
}
// Geneaology :: derived from technique at: http://devshed.com
if ( eventRef )
{
var szLoad = eventRef.toString() ;
var szFunc = p_szLoad.replace("()","");
if(szLoad.indexOf(szFunc) >= 0) // 已经注册到 onload 中了。
{
return;
}
var szMergeLoad = ''
+ szLoad.substring( szLoad.indexOf( '{' ) + 1
, szLoad.lastIndexOf( '}' ) )
+ ';\n'
+ p_szLoad + ';\n' ;
eventRef = new Function( szMergeLoad ) ;
}
else
{
eventRef = p_szLoad.replace("()","") ;
}
if(eventName == "OnResize")
{
document.body.onresize = eval(eventRef);
}
else
{
document.body.onload = eventRef;
}
}
/**
* 当页面采用相对定位时,浏览器窗口的缩放会导致 MapControl 的绝对位置发生变化从而导致索引框位置错误。
* 为解决这个问题,建议 body.onresize 事件被触发时调用该函数。 例如:
* 修改页面的 <body> 元素,往其中加入 <body onresize="SMISMapSetPosition('MapControl1')">
* 对 OverviewControl 也要做类似的处理:
* <body onresize="SMISMapSetPosition('MapControl1'); SMISOverviewSetPosition('OverviewControl1')">
**/
function SMISMapSetPosition(mapID)
{
if(mapID == null) { return; }
var mapImageID = mapID + '_MVIMAGE';
var mapLoadingID = mapID + '_divLoading';
var mapQuickPanLeftID = mapID + '_QuickPanDiv_L';
var mapQuickPanRightID = mapID + '_QuickPanDiv_R';
var mapQuickPanUpID = mapID + '_QuickPanDiv_U';
var mapQuickPanDownID = mapID + '_QuickPanDiv_D';
SetMapAbsPosition(mapImageID);
var mapDiv = document.getElementById(mapID);
var map = document.getElementById(mapImageID);
if(mapDiv.style.position != "absolute")
{
mapDiv.style.position = "relative";
// mapDiv.style.left = map.offset.x+"px";
// mapDiv.style.top = map.offset.y+"px";
map.offset = new SMISPoint(0,0);
}
mapDiv = null;
map.style.position = "absolute";
map.style.left = map.offset.x;
map.style.top = map.offset.y;
var workLayer = SMISGetWorkLayer(mapID);
if(workLayer){
workLayer.style.left = map.offset.x+"px";
workLayer.style.top = map.offset.y+"px";
}
workLayer = null;
var mapLoading = document.getElementById(mapLoadingID);
if(mapLoading){
mapLoading.style.left = map.offset.x + (SMISGetNumFromPixel(map.style.width) - SMISGetNumFromPixel(mapLoading.scrollWidth))/2 +"px";
mapLoading.style.top = map.offset.y + (SMISGetNumFromPixel(map.style.height) - SMISGetNumFromPixel(mapLoading.scrollHeight))/2 +"px";
}
mapLoading = null;
var divQuickPan_L = document.getElementById(mapQuickPanLeftID);
var divQuickPan_R = document.getElementById(mapQuickPanRightID);
var divQuickPan_U = document.getElementById(mapQuickPanUpID);
var divQuickPan_D = document.getElementById(mapQuickPanDownID);
// Firefox和NetScape下对clientHeight与clientWidth属性支持得不是很好,在第一次加载时clientHeight与clientWidth为0,
// 所以当其为0时,需要将其修改一下.
var hl = divQuickPan_L.clientHeight;
var hr = divQuickPan_R.clientHeight;
var hu = divQuickPan_U.clientHeight;
var hd = divQuickPan_D.clientHeight;
var wl = divQuickPan_L.clientWidth;
var wr = divQuickPan_R.clientWidth;
var wu = divQuickPan_U.clientWidth;
var wd = divQuickPan_D.clientWidth;
if(divQuickPan_L.clientHeight == 0){hl = 12;}
if(divQuickPan_R.clientHeight == 0){hr = 12;}
if(divQuickPan_U.clientHeight == 0){hu = 12;}
if(divQuickPan_D.clientHeight == 0){hd = 12;}
if(divQuickPan_L.clientWidth == 0){wl = 12;}
if(divQuickPan_R.clientWidth == 0){wr = 12;}
if(divQuickPan_U.clientWidth == 0){wu = 12;}
if(divQuickPan_D.clientWidth == 0){wd = 12;}
if(divQuickPan_L){
divQuickPan_L.style.visibility = 'visible';
divQuickPan_L.style.zIndex = map.style.zIndex + 10;
divQuickPan_L.style.left = map.offset.x +"px";
divQuickPan_L.style.top = map.offset.y + (SMISGetNumFromPixel(map.style.height))/2 - hl/2 +"px";
}
if(divQuickPan_R){
divQuickPan_R.style.visibility = 'visible';
divQuickPan_R.style.zIndex = map.style.zIndex + 10;
divQuickPan_R.style.left = map.offset.x + (SMISGetNumFromPixel(map.style.width)) - wr+"px";
divQuickPan_R.style.top = map.offset.y + (SMISGetNumFromPixel(map.style.height))/2 - hr/2+"px";
}
if(divQuickPan_U){
divQuickPan_U.style.visibility = 'visible';
divQuickPan_U.style.zIndex = map.style.zIndex + 10;
divQuickPan_U.style.left = map.offset.x + (SMISGetNumFromPixel(map.style.width))/2 - wu/2+"px";
divQuickPan_U.style.top = map.offset.y+"px";
}
if(divQuickPan_D){
divQuickPan_D.style.visibility = 'visible';
divQuickPan_D.style.zIndex = map.style.zIndex + 10;
divQuickPan_D.style.left = map.offset.x + (SMISGetNumFromPixel(map.style.width))/2 - wd/2+"px";
divQuickPan_D.style.top = map.offset.y + (SMISGetNumFromPixel(map.style.height)) - hd+"px";
}
try
{
eval( mapID + "_SetDivCustomLayer()" );
}
catch(e)
{
// alert(show_props(e));
}
map = null;
divQuickPan_L = null;
divQuickPan_R = null;
divQuickPan_U = null;
divQuickPan_D = null;
}
function AddImageCellsToWorkLayer(mapId)
{
//by zhangwl
// Format: "{'cellLTX':cellLTX, 'cellLTY':cellLTY, 'countX':countX, 'countY':countY, 'cellWidth':cellWidth, 'cellHeight':cellHeight, 'offsetLTX':offsetLTX, 'offsetLTY':offsetLTY,
// 'offsetRBX':offsetRBX, 'offsetRBY':offsetRBY, 'urls':url1|url2|url3|...}"
// or: "url"
var __DEBUG__ = false;
var map = SMISGetMap(mapId);
if(map.ImageCellsAdded)
{
return;
}
map.ImageCellsAdded = true;
var mapUrl = document.getElementById(mapId + "_MapUrl");
if(!mapUrl || !mapUrl.value) { return; }
mapUrl = mapUrl.value;
map.bActionStarted = true;
// mapUrl = "3;2;200;200;0,52;20,52;http://huzhn/output/127550932750756928.png|http://huzhn/output/127550932751858512.png|http://huzhn/output/127550939948506784.png|http://huzhn/output/127550939949608368.png|http://huzhn/output/127550939950910240.png|http://huzhn/output/127550939952111968.png|";
// mapUrl = "4;3;200;200;69,188;149,11;http://AHNAN/output/127550989867586896.png|http://AHNAN/output/127550989868888768.png|http://AHNAN/output/127550989869890208.png|http://AHNAN/output/127550989870991792.png|http://AHNAN/output/127550989872093376.png|http://AHNAN/output/127550989873094816.png|http://AHNAN/output/127550989874296544.png|http://AHNAN/output/127550989876199280.png|http://AHNAN/output/127550989877401008.png|http://AHNAN/output/127550989878302304.png|http://AHNAN/output/127550989879403888.png|http://AHNAN/output/127550989880405328.png|";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -