//==========================================================================
// SuperMap IS 客户端程序,版权所有,北京超图地理信息技术有限公司,2000-2006。
// 本程序只能在有效的授权许可下使用。未经许可,不得以任何手段擅自使用或传播。
// 作者: SuperMap IS Team
// 修改:
// 文件名: SuperMap.IS.Utility.js
// 功能: AjaxMap 辅助方法
// 最后修改时间: 2006-05-23
//==========================================================================
function RegisterNamespaces(){for(var i=0;i RegisterNamespaces("SuperMap.IS");
//from prototype.js
function $() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = document.getElementById(element);
if (arguments.length == 1)
return element;
elements.push(element);
}
return elements;
}
//from Yahoo! dragdrop_1.0.2.js
function _GetScroll(){var t,l;if(document.documentElement&&document.documentElement.scrollTop){t=document.documentElement.scrollTop;l=document.documentElement.scrollLeft;}else{if(document.body){t=document.body.scrollTop;l=document.body.scrollLeft;}}return {top:t,left:l};};
function _GetStyle(el,_95){if(el.style.styleProp){return el.style.styleProp;}else{if(el.currentStyle){return el.currentStyle[_95];}else{if(document.defaultView){return document.defaultView.getComputedStyle(el,null).getPropertyValue(_95);}}}};
function _GetScrollTop(){return _GetScroll().top;};
function _GetScrollLeft(){return _GetScroll().left;};
//_AddEvent(element,"mousedown",handleMouseDown)
function _AddEvent(el,eventType,fn,useCapture){if(eventType.indexOf("on")==0){eventType=eventType.substring(2);}useCapture=(useCapture)?true:false;if(el.addEventListener){el.addEventListener(eventType,fn,useCapture);}else{if(el.attachEvent){el.attachEvent("on"+eventType,fn);}else{el["on"+eventType]=fn;}}};
function _RemoveEvent(el,eventType,fn,useCapture){if(eventType.indexOf("on")==0){eventType=eventType.substring(2);}useCapture=(useCapture)?true:false;if(el.removeEventListener){el.removeEventListener(eventType,fn,useCapture);}else{if(el.detachEvent){el.detachEvent("on"+eventType,fn);}else{el["on"+eventType]=null;}}};
function _FixIEEvent(ev){
if(typeof ev.charCode=="undefined"){ev.charCode=(ev.type=="keypress")?ev.keyCode:0;ev.isChar=(ev.charCode>0);}if(ev.srcElement&&!ev.target){ev.eventPhase=2;ev.pageX=ev.clientX+_GetScrollLeft();ev.pageY=ev.clientY+_GetScrollTop();
if(!ev.preventDefault){ev.preventDefault=function(){this.returnValue=false;};}if(ev.type=="mouseout"){ev.relatedTarget=ev.toElement;}else{if(ev.type=="mouseover"){ev.relatedTarget=ev.fromElement;}}
if(!ev.stopPropagation){ev.stopPropagation=function(){this.cancelBubble=true;};}ev.target=ev.srcElement;ev.time=(new Date).getTime();}return ev;
};
function _FixDOMEvent(ev){if(!ev.srcElement){ev.srcElement=ev.originalTarget;}if(!ev.pageX&&ev.clientX&&ev.clientY){ev.pageX=ev.clientX;ev.pageY=ev.clientY;}return ev;};
// 下面这个方法有内存泄漏,暂时弃用。
//function _GetEvent(e){if(ygPos.browser=="ie"){ev=_FixIEEvent(window.event);}else{ev=_GetEvent.caller.arguments[0];ev=_FixDOMEvent(_GetEvent.caller.arguments[0]);}return ev;};
//function _GetEvent(e){if(window.event){ev=_FixIEEvent(window.event);}else{ev=_GetEvent.caller.arguments[0];ev=_FixDOMEvent(_GetEvent.caller.arguments[0]);}return ev;};
function _GetEvent(e){return e?e:window.event;}
function _CancelBubble(e){e.cancelBubble=true;}
function G(e){e=_GetEvent(e);_CancelBubble(e);return false;}
function _GetMouseX(e){var posX=0;if(e.pageX){posX=e.pageX;}else if(e.clientX){if(document.documentElement&&document.documentElement.scrollLeft){posX=e.clientX+document.documentElement.scrollLeft;}else if(document.body){posX=e.clientX+document.body.scrollLeft;}}return posX;}
function _GetMouseY(e){var posY=0;if(e.pageY){posY=e.pageY;}else if(e.clientY){if(document.documentElement&&document.documentElement.scrollTop){posY=e.clientY+document.documentElement.scrollTop;}else if(document.body){posY=e.clientY+document.body.scrollTop;}}return posY;}
function _GetMouseScrollDelta(e){if(e.wheelDelta){return e.wheelDelta;}else if(e.detail){return-e.detail;}return 0;}
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&&t.nodeType){if(t.nodeType==3){t=targ.parentNode;}}return t;}
function _GetElementX(el){var element=el;var x=0;while(element){x+=element.offsetLeft;element=element.offsetParent;}if(navigator.userAgent.indexOf("Mac")!=-1&&typeof(document.body.leftMargin)!="undefined"){x+=document.body.leftMargin;}return x;}
function _GetElementY(el){var element=el;var y=0;while(element){y+=element.offsetTop;element=element.offsetParent;}if(navigator.userAgent.indexOf("Mac")!=-1&&typeof(document.body.topMargin)!="undefined"){y+=document.body.topMargin;}return y;}
//function _GetElementX(el){return ygPos.getX(el);}
//function _GetElementY(el){return ygPos.getY(el);}
function _Floor(d){return Math.floor(d);}function _Ceil(d){return Math.ceil(d);}function _Max(d,f){return Math.max(d,f);}function _Min(d,f){return Math.min(d,f);}function _Abs(d){return Math.abs(d);}function _Round(d){return Math.round(d);}function _AngleToRadian(angle){return angle*Math.PI/180.0;}function _RadianToAngle(radian){return radian*180.0/Math.PI;}
// from Yahoo! position_1.0.2.js
var ygPos=new function(){
this.getPos=function(oEl){
var pos=[oEl.offsetLeft,oEl.offsetTop];var parent=oEl.offsetParent;var tmp={x:null,y:null};
if(parent!=oEl){
while(parent){
switch(browser){
case'ie':
if(_getStyle(parent,'position')=='relative'&&_getStyle(oEl,'width')=='auto'&&!(_getStyle(oEl,'position')!='static')){return[oEl.offsetLeft,oEl.offsetTop];}
else if(_getStyle(parent,'width')!='auto'||_getStyle(oEl.parentNode,'position')!='static'){tmp.x=parseInt(_getStyle(parent,'borderLeftWidth'));tmp.y=parseInt(_getStyle(parent,'borderTopWidth'));if(!isNaN(tmp.x))pos[0]+=tmp.x;if(!isNaN(tmp.y))pos[1]+=tmp.y;}
break;
case'gecko':
if(_getStyle(parent,'position')=='relative'){tmp.x=parseInt(_getStyle(parent,'border-left-width'));tmp.y=parseInt(_getStyle(parent,'border-top-width'));if(!isNaN(tmp.x))pos[0]+=tmp.x;if(!isNaN(tmp.y))pos[1]+=tmp.y;}
break;
}
pos[0]+=parent.offsetLeft;pos[1]+=parent.offsetTop;parent=parent.offsetParent;
}
}
if(browser=='ie'&&_getStyle(oEl,'width')!='auto'&&_getStyle(oEl.offsetParent,'width')=='auto'&&_getStyle(oEl.offsetParent,'position')=='relative'){
parent=oEl.parentNode;
while(parent.tagName!='HTML'){
tmp.x=parseInt(_getStyle(parent,'marginLeft'));tmp.y=parseInt(_getStyle(parent,'paddingLeft'));
if(!isNaN(tmp.x))pos[0]-=tmp.x;if(!isNaN(tmp.y))pos[0]-=tmp.y;
parent=parent.parentNode;
}
}
return pos;
},
this.getX=function(oEl){return this.getPos(oEl)[0];}
this.getY=function(oEl){return this.getPos(oEl)[1];}
this.setPos=function(oEl,endPos){
var offset=[0,0];var delta={x:0,y:0};var curStylePos=_getStyle(oEl,'position');
if(curStylePos=='static'){oEl.style.position='relative';curStylePos='relative';}
if(oEl.offsetWidth){
if(curStylePos=='relative'){offset=this.getPos(oEl);var tmp={x:_getStyle(oEl,'left'),y:_getStyle(oEl,'top')};delta.x=(tmp.x&&tmp.x.indexOf('px')!=-1)?parseInt(tmp.x):0;delta.y=(tmp.y&&tmp.y.indexOf('px')!=-1)?parseInt(tmp.y):0;}
else{offset=this.getPos(oEl.offsetParent);var tmp={x:_getStyle(oEl,'margin-left'),y:_getStyle(oEl,'margin-top')};delta.x=(tmp.x&&tmp.x.indexOf('px')!=-1)?0-parseInt(tmp.x):0;delta.y=(tmp.y&&tmp.y.indexOf('px')!=-1)?0-parseInt(tmp.y):0;}
}
if(browser=='safari'){
if(oEl.offsetParent&&oEl.offsetParent.tagName=='BODY'){
if(_getStyle(oEl,'position')=='relative'){delta.x-=document.body.offsetLeft;delta.y-=document.body.offsetTop;}
else if(_getStyle(oEl,'position')=='absolute'||_getStyle(oEl,'position')=='fixed'){delta.x+=document.body.offsetLeft;delta.y+=document.body.offsetTop;}
}
}
if(endPos[0]!==null)oEl.style.left=endPos[0]-offset[0]+delta.x+'px';
if(endPos[1]!==null)oEl.style.top=endPos[1]-offset[1]+delta.y+'px';
}
this.setX=function(oEl,x){this.setPos(oEl,[x,null]);}
this.setY=function(oEl,y){this.setPos(oEl,[null,y]);}
var _getStyle=function(oEl,property){
var dv=document.defaultView;
if(oEl.style[property])return oEl.style[property];
else if(oEl.currentStyle){
if(property.indexOf('-')!=-1){
property=property.split('-');
property[1]=property[1].toUpperCase().charAt(0)+property[1].substr(1);
property=property.join('');
}
if(oEl.currentStyle[property])return oEl.currentStyle[property];
}
else if(dv&&dv.getComputedStyle(oEl, '')&&dv.getComputedStyle(oEl,'').getPropertyValue(property)) return dv.getComputedStyle(oEl,'').getPropertyValue(property);
return null;
}
var _getBrowser=function(){
var ua=navigator.userAgent.toLowerCase();
if(ua.indexOf('opera')!=-1)return'opera';
else if(ua.indexOf('msie')!=-1)return'ie';
else if(ua.indexOf('safari')!=-1)return'safari';
else if(ua.indexOf('gecko')!=-1)return'gecko';
else return false;
}
var browser=_getBrowser();
this.browser = browser;
}
//Enable VML support
function _EnableVML()
{
if(ygPos.browser != "ie"){return;}
// todo: support ie5.0, ie5.5
if(document.namespaces){
document.namespaces.add("v", "urn:schemas-microsoft-com:vml")
}
if(document.styleSheets.length < 1){
var _oStyle = document.createElement("style");
document.body.appendChild(_oStyle);
}
if(document.styleSheets.item(0).addRule){
document.styleSheets.item(0).addRule("v\\:*", "behavior:url(#default#VML)");
}
}
function show_props(obj, objName) {
var result = "";
for (var i in obj) {
result += objName + "." + i + " = " + obj[i] + "\n";
}
return result;
}
function _GetXmlHttpRequest(){
var xh=null;
try{xh=new ActiveXObject("Msxml2.XMLHTTP");}catch(ex){
try{xh=new ActiveXObject("Microsoft.XMLHTTP");}catch(ex){xh=null;}}
if(!xh&&typeof XMLHttpRequest!="undefined"){xh=new XMLHttpRequest();}
return xh;
}
function _ToJSON(o){
if(o == null)
return "null";
switch(o.constructor) {
case String:
var s = o; // .encodeURI();
s = '"' + s.replace(/(["\\])/g, '\\$1') + '"';
s = s.replace(/\n/g,"\\n");
s = s.replace(/\r/g,"\\r");
return s;
case Array:
var v = [];
for(var i=0; i v.push(_ToJSON(o[i])) ;
return "[" + v.join(", ") + "]";
case Number:
return isFinite(o) ? o.toString() : _ToJSON(null);
case Boolean:
return o.toString();
case Date:
var d = new Object();
d.__type = "System.DateTime";
d.Year = o.getUTCFullYear();
d.Month = o.getUTCMonth() +1;
d.Day = o.getUTCDate();
d.Hour = o.getUTCHours();
d.Minute = o.getUTCMinutes();
d.Second = o.getUTCSeconds();
d.Millisecond = o.getUTCMilliseconds();
d.TimezoneOffset = o.getTimezoneOffset();
return _ToJSON(d);
default:
if(o["toJSON"] != null && typeof o["toJSON"] == "function")
return o.toJSON();
if(typeof o == "object") {
var v=[];
for(attr in o) {
if(typeof o[attr] != "function")
v.push('"' + attr + '": ' + _ToJSON(o[attr]));
}
if(v.length>0)
return "{" + v.join(", ") + "}";
else
return "{}";
}
return o.toString();
}
};
function _FromJSON(o, j){
if(!j){return;}
for(var m in j){
if(typeof(o[m]) == "object"){
_FromJSON(o[m], j[m]);
}
else if(typeof(o[m]) != "function" && typeof(o[m]) != "undefined"){
o[m] = j[m];
}
}
};
function _SplitX(points, offsetX)
{
if(typeof(offsetX)=="undefined"){offsetX=0;}
var pxs=new Array();
for(var i=0; i return pxs;
}
function _SplitY(points,offsetY)
{
if(typeof(offsetY)=="undefined"){offsetY=0;}
var pys=new Array();
for(var i=0; i return pys;
}