📄 util.js
字号:
if(left)
e.style.left = parseInt(left) + "px";
if(top)
e.style.top = parseInt(top) + "px";
if(width ){
e.style.width = parseInt(width) + "px";
}
if( height){
e.style.height = parseInt(height) + "px";
}
if(img)
e.appendChild(Util.createImg(id+'_Img',5,5,null,null,img,'relative'));
if(position)
e.style.position = position ;
if (border)
e.style.border = border;
if (opacity) {
e.style.opacity = opacity;
e.style.filter = 'alpha(opacity=' + (opacity * 100) + ')';
}
return e;
};
//
Util.createImg = function(id, left, top, width, height, imgurl, position, border, opacity, delayDisplay) {
image = document.createElement("img");
if(delayDisplay) {
image.style.display = "none";
Event.observe(image, "load", Util.onImageLoad.bindAsEventListener(image));
Event.observe(image, "error",Util.onImageLoadError.bindAsEventListener(image));
}
image.style.alt = id;
image.galleryImg = "no";
if (imgurl)
image.src = imgurl;
if (!position)
position = "relative";
if(id)
image.id = id;
if(left)
image.style.left = parseInt(left) + "px";
if(top)
image.style.top = parseInt(top) + "px";
if(width && height){
image.style.width = parseInt(width) + "px";
image.style.height = parseInt(height) + "px";
}
if(position)
image.style.position = position ;
if (border)
image.style.border = border;
if (opacity) {
image.style.opacity = opacity;
image.style.filter = 'alpha(opacity=' + (opacity * 100) + ')';
}
return image;
}
Util.setElementStyle = function(element, id, left, top, width, height, position, border, overflow, opacity) {
if (id) {
element.id = id;
}
if(left)
element.style.left = parseInt(left) + "px";
if(top)
element.style.top = parseInt(top) + "px";
if(width && height){
element.style.width = parseInt(width) + "px";
element.style.height = parseInt(height) + "px";
}
if (position) {
element.style.position = position;
}
if (border) {
element.style.border = border;
}
if (overflow) {
element.style.overflow = overflow;
}
if (opacity) {
element.style.opacity = opacity;
element.style.filter = 'alpha(opacity=' + (opacity * 100) + ')';
}
};
Util.onImageLoad = function() {
this.style.backgroundColor = null;
this.style.display = "";
};
Util.onImageLoadError = function() {
this.style.backgroundColor = "pink";
this.style.display = "";
};
Util.getMousePixel = function(e){
if(!e)
e = window.event;
//Changed by Deng Guoqi 2008-05-25
if(!e.pageX)
e.pageX = document.body.scrollLeft + e.clientX;
// e.pageX = e.clientX;
if(!e.pageY)
e.pageY = document.body.scrollTop + e.clientY;
// e.pageY = e.clientY;
return {x:e.pageX, y:e.pageY};
};
Util.getMouseRelativePixel = function(e, mapDiv){
var pixel = Util.getMousePixel(e);
var relDeltaX = pixel.x - Util.getLeft(mapDiv.parentNode) - Util.getValueOfNoPX(mapDiv.style.left);
var relDeltaY = pixel.y - Util.getTop(mapDiv.parentNode) - Util.getValueOfNoPX(mapDiv.style.top);
return {x:relDeltaX, y:relDeltaY};
};
Util.getTop = function(obj){
var t = obj.offsetTop;
while(obj = obj.offsetParent){
t += obj.offsetTop;
}
return t;
};
Util.getLeft = function(obj){
var t = obj.offsetLeft;
while(obj = obj.offsetParent){
t += obj.offsetLeft;
}
return t;
};
//根据实际坐标跟放大级别获取屏幕坐标
Util.getScreenPixel = function(coord, zoom){
var sx = (coord.x-zoom.realMapBound.getMinX()) * ((zoom.getTileCols() * TileSize)/zoom.realMapBound.getWidth());
var sy = (zoom.realMapBound.getMaxY()-coord.y) * ((zoom.getTileRows() * TileSize)/zoom.realMapBound.getHeight());
return {x:Math.ceil(sx), y:Math.ceil(sy)};
}
//根据屏幕坐标跟放大级别获取实际坐标
Util.getCoordinateByPixel = function(pixel, zoom){
var x = zoom.realMapBound.getMinX() + pixel.x * (zoom.realMapBound.getWidth()/(zoom.getTileCols() * TileSize));
var y = zoom.realMapBound.getMaxY() - pixel.y * (zoom.realMapBound.getHeight()/(zoom.getTileRows() * TileSize));
return new Coordinate(x, y);
};
Util.getDeltaPixel = function(pixel, zoom){
var coord = Util.getCoordinateByPixel(pixel,zoom);
var pixel = Util.getScreenPixel(coord,zoom);
return pixel;
}
var state = 1 ;
var orgLeft = 0;
var orgTop = 0;
var deltaX = 0;
var deltaY = 0;
var timer = null;
function setCurPos(left, top){
orgLeft = left;
orgTop = top;
}
function slide(layerId, w, h, img){
var containerW = Util.getValueOfNoPX($(layerId).parentNode.style.width);
var containerH = Util.getValueOfNoPX($(layerId).parentNode.style.height);
if(state == 1){
state = 0 ;
var rate = 200/190;
fly(layerId, containerW, containerH, 20, rate);
img.src = ImageBaseDir + '2.gif';
}
else {
state = 1 ;
var rate = 190/200;
fly(layerId, containerW-w+1, containerH-h+1, 20, rate);
img.src = ImageBaseDir + '1.gif';
}
}
function fly(layerId, left, top, speed, speedRate){
wSpeed = (Math.max(orgLeft, left) - Math.min(orgLeft, left))/(speed) ;
hSpeed = (Math.max(orgTop, top) - Math.min(orgTop, top))/(speed*speedRate);
move(layerId, wSpeed, hSpeed, left, top) ;
}
function move(layerId, wSpeed, hSpeed, left, top){
clearTimeout(timer) ;
if(orgLeft != left){
if((Math.max(orgLeft, left) - Math.min(orgLeft, left)) < wSpeed)
orgLeft = left ;
else if(orgLeft < left)
orgLeft = orgLeft + wSpeed;
else if(orgLeft > left)
orgLeft = orgLeft - wSpeed;
$(layerId).style.left = orgLeft;
}
if(orgTop != top){
if((Math.max(orgTop, top) - Math.min(orgTop, top)) < hSpeed)
{
orgTop = top;
}
else if(orgTop < top)
{
orgTop = orgTop + hSpeed;
}
else if(orgTop > top)
{
orgTop = orgTop - hSpeed ;
}
$(layerId).style.top = orgTop;
}
timer = setTimeout('move("'+layerId+'",'+wSpeed+','+hSpeed+','+left+','+top+')',30);
};
function MM_swapImgRestore() {
var i,x,a=document.MM_sr;
for(i=0; a&&i<a.length&&(x=a[i])&&x.oSrc; i++) x.src=x.oSrc;
}
function MM_swapImage() {
var i,j=0,x,a=MM_swapImage.arguments;
document.MM_sr=new Array;
for(i=0;i<(a.length-2);i+=3)
if ((x=$(a[i]))!=null){
document.MM_sr[j++]=x;
if(!x.oSrc)
x.oSrc=x.src;
x.src=a[i+2];
}
}
Util.sendAjaxRequest = function (url, params, doGET, callback, contentType) {
try {
var xh = Ajax.getTransport();
xh.onreadystatechange = callback;
if (doGET) {
xh.open("GET", url + "?" + params, true);
xh.send(null);
}
else {
xh.open("POST", url, true);
if (contentType){
xh.setRequestHeader("content-type", contentType);
}
xh.send(params);
}
return xh;
}
catch (exception) {
return null;
}
};
//初始化页面
//得到当前辖区名
function initPage(center){
var url = "../login.jsf";
var params = 'mapViewerAjax=mapViewerAjax&getCurStaticArea=getCurStaticArea¢erCoords='+center+'&formId=mapForm&mapId=map1';
var xmlHttp = Util.sendAjaxRequest(url, params, false, function () {
getCurStaticAreaAjaxResponse(xmlHttp);}, "application/x-www-form-urlencoded");
}
function getCurStaticAreaAjaxResponse(xmlHttp) {
if (xmlHttp != null && xmlHttp.readyState == 4 && xmlHttp.status == 200) {
var xml = xmlHttp.responseXML;
if(xml.getElementsByTagName("CurStaticArea").item(0)){
var curAreaName = xml.getElementsByTagName("CurStaticArea").item(0).firstChild.nodeValue;
$("Field_Info").innerHTML = curAreaName;
}
}
}
//get map_main origin point
Util.getOrigPoint=function()
{
if(!$("map_main"))
return new PointEntry(0,0);
var x = Util.getValueOfNoPX($("map_main").style.left);
var y = Util.getValueOfNoPX($("map_main").style.top);
// if(x>0)
// x=0;
// else
x=x*(-1);
// if(y>0)
// y=0;
// else
y=y*(-1);
// return new PointEntry(x,y);
return new PointEntry(0,0);
}
// check the url is or not exist
Util.existed = function(url){
var has = false;
new Ajax.Request(url, {method:"post", onComplete:function(res){
if(res.readyState==4){
if(res.status==200)
has = true;
else
has = false;
}
}});
return has;
}
function getArgs(){
var args = new Object( );
var query = self.location.search.substring(1); // Get query string
var pairs = query.split("&"); // Break at ampersand
for(var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf('='); // Look for "name=value"
if (pos == -1) continue; // If not found, skip
var argname = pairs[i].substring(0,pos); // Extract the name
var value = pairs[i].substring(pos+1); // Extract the value
value = decodeURIComponent(value); // Decode it, if needed
args[argname] = value; // Store as a property
}
return args;
}
saveHandler = function(id){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -