📄 supermap.is.type.js
字号:
//==========================================================================
// SuperMap IS 客户端程序,版权所有,北京超图地理信息技术有限公司,2000-2006。
// 本程序只能在有效的授权许可下使用。未经许可,不得以任何手段擅自使用或传播。
// 作者: SuperMap IS Team
// 修改:
// 文件名: SuperMap.IS.Type.js
// 功能: AjaxMap 基础类型
// 最后修改时间: 2006-05-23
//==========================================================================
SuperMap.IS.MapCoord=function(x,y){this.x=x;this.y=y;this.ToString=function(){return"("+this.x+", "+this.y+")";};this.Copy=function(o){if(!o){return;}this.x=o.x;this.y=o.y;};};
SuperMap.IS.MapRect=function(left,bottom,right,top){
this.leftBottom=new SuperMap.IS.MapCoord(left,bottom);this.rightTop=new SuperMap.IS.MapCoord(right,top);
this.ToString=function(){return"("+(this.leftBottom?this.leftBottom.ToString():"null")+", "+(this.rightTop?this.rightTop.ToString():"null")+")";};
this.Copy=function(mapRect){if(!mapRect){return;}if(!this.leftBottom){this.leftBottom=new SuperMap.IS.MapCoord();}if(!this.rightTop){this.rightTop=new SuperMap.IS.MapCoord();}this.leftBottom.Copy(mapRect.leftBottom);this.rightTop.Copy(mapRect.rightTop);};
this.Center=function(){var center=new SuperMap.IS.MapCoord();center.x=0.5*(this.leftBottom.x+this.rightTop.x);center.y=0.5*(this.leftBottom.y+this.rightTop.y);return center;};
this.Contains=function(point){return point.x>=this.leftBottom.x&&point.y>=this.leftBottom.y&&point.x<=this.rightTop.x&&point.y<=this.rightTop.y;};
this.Width=function(){return this.rightTop.x-this.leftBottom.x;};
this.Height=function(){return this.rightTop.y-this.leftBottom.y;};
this.FromJSON=function(o){
if(!o){return;}
if(o.leftBottom && !this.leftBottom){this.leftBottom=new SuperMap.IS.MapCoord();}
if(o.leftBottom){this.leftBottom.x=o.leftBottom.x;this.leftBottom.y=o.leftBottom.y;}
if(o.rightTop && !this.rightTop){this.rightTop=new SuperMap.IS.MapCoord();}
if(o.rightTop){this.rightTop.x=o.rightTop.x;this.rightTop.y=o.rightTop.y;}
};
};
SuperMap.IS.PixelCoord=function(x,y){this.x=parseInt(x);this.y=parseInt(y);this.ToString=function(){return"("+this.x+", "+this.y+")";};this.Copy=function(pixelCoord){if(!pixelCoord){return;}this.x=pixelCoord.x;this.y=pixelCoord.y;};};
SuperMap.IS.PixelRect=function(left,top,right,bottom){
this.leftTop=new SuperMap.IS.PixelCoord(left,top);this.rightBottom=new SuperMap.IS.PixelCoord(right,bottom);
this.ToString=function(){return"("+(this.leftTop?this.leftTop.ToString():"null")+", "+(this.rightBottom?this.rightBottom.ToString():"null")+")";};
this.Copy=function(pixelRect){if(!pixelRect){return;}if(!this.leftTop){this.leftTop=new SuperMap.IS.PixelCoord();}if(!this.rightBottom){this.rightBottom=new SuperMap.IS.PixelCoord();}this.leftTop.Copy(pixelRect.leftTop);this.rightBottom.Copy(pixelRect.rightBottom);};
this.Width=function(){return _Abs(this.rightBottom.x-this.leftTop.x);};
this.Height=function(){return _Abs(this.rightBottom.y-this.leftTop.y);};
this.FromJSON=function(o){
if(!o){return;}
if(o.leftTop && !this.leftTop){this.leftTop=new SuperMap.IS.PixelCoord();}
if(o.leftTop){this.leftTop.x=o.leftTop.x;this.leftTop.y=o.leftTop.y;}
if(o.rightBottom && !this.rightBottom){this.rightBottom=new SuperMap.IS.PixelCoord();}
if(o.rightBottom){this.rightBottom.x=o.rightBottom.x;this.rightBottom.y=o.rightBottom.y;}
};
};
SuperMap.IS.MapParam=function(name,scales){
this.mapName=name;
this.mapScales=scales;
this.zoomLevel=1;
this.pixelCenter=new SuperMap.IS.PixelCoord();
this.mapCenter=new SuperMap.IS.MapCoord();
this.pixelRect=new SuperMap.IS.PixelRect();
this.mapRect=new SuperMap.IS.MapRect();
var self=this;
var viewType="pc"; //"pixelCenter","mc","pr","mapRect".
this.Destroy=function(){this.pixelCenter=this.mapCenter=self=null;};
this.GetViewType=function(){return viewType;};
function _MakeCopy(){var mapParam=new SuperMap.IS.MapParam();mapParam.Copy(self);return mapParam;}
function _Copy(param){self.mapScales=param.mapScales;self.mapName=param.mapName;self.zoomLevel=param.zoomLevel;self.pixelCenter.Copy(param.pixelCenter);self.mapCenter.Copy(param.mapCenter);self.pixelRect.Copy(param.pixelRect);self.mapRect.Copy(param.mapRect);viewType=param.GetViewType();}
function _Equals(param){return param!=null&&self.mapName==param.mapName&&self.zoomLevel==param.zoomLevel&&_Abs(self.pixelCenter.x-param.pixelCenter.x)<0.000001&&_Abs(self.pixelCenter.y-param.pixelCenter.y)<0.000001;}
function _ToString(){return"("+self.mapName+", "+self.mapCenter.ToString()+", "+self.zoomLevel+")";}
function _SetPixelCenter(pc){if(!pc){return;}self.pixelCenter=pc;viewType="pc";}
function _SetMapCenter(mc){if(!mc){return;}self.mapCenter=mc;viewType="mc";}
function _SetPixelRect(pr){self.pixelRect=pr;viewType="pr";}
function _SetMapRect(mr){self.mapRect=mr;viewType="mr";}
function _SetMapScales(scales){self.mapScales = scales;}
function _SetZoomLevel(level){
if(!level){return;}
if(level<=0){return;}
if(level>self.mapScales.length){return;}
self.zoomLevel = _Min(self.zoomLevel, self.mapScales.length);
self.zoomLevel = _Max(0, self.zoomLevel);
var ratio=self.mapScales[level-1]/self.mapScales[self.zoomLevel-1];
switch(viewType){
case"pc":{
self.pixelCenter.x*=ratio;
self.pixelCenter.y*=ratio;
break;
}
case"pr":{
self.pixelRect.leftTop.x*=ratio;
self.pixelRect.leftTop.y*=ratio;
self.pixelRect.rightBottom.x*=ratio;
self.pixelRect.rightBottom.y*=ratio;
break;
}
}
self.zoomLevel=level;
}
function _SetMapName(mapName){self.mapName=mapName;if(viewType=="pc"){viewType="mc";}}
function _GetPixelX(level){
if(level){return self.pixelCenter.x*(self.mapScales[level-1]/self.mapScales[self.zoomLevel-1]);}
return self.pixelCenter.x;
}
function _GetPixelY(level){
if(level){return self.pixelCenter.y*(self.mapScales[level-1]/self.mapScales[self.zoomLevel-1]);}
return self.pixelCenter.y;
}
function _GetPixelCenter(level){if(level==undefined){return self.pixelCenter;}return new SuperMap.IS.PixelCoord(self.GetPixelX(level),self.GetPixelY(level));}
function _Resolve(map,width,height){
switch(viewType){
case"pc":self.mapCenter=map.PixelToMapCoord(self.pixelCenter,self.zoomLevel);break;
case"mc":self.pixelCenter=map.MapCoordToPixel(self.mapCenter,self.zoomLevel);break;
case"pr":_ValidateByPixelRect(map,width,height);break;
case"mr":{
self.pixelRect.leftTop=map.MapCoordToPixel(self.mapRect.leftBottom,self.zoomLevel);
self.pixelRect.rightBottom=map.MapCoordToPixel(self.mapRect.rightTop,self.zoomLevel);
// 尽量让 mapRect 都在可见范围内。 --ahnan 2006-05-18
_ValidateByPixelRect(map,width,height,true);
break;
}
}
viewType="pc";
}
function _ValidateByPixelRect(map,width,height,ensureVisible){
// 调整中心点。
self.pixelCenter.x=0.5*(self.pixelRect.leftTop.x+self.pixelRect.rightBottom.x);
self.pixelCenter.y=0.5*(self.pixelRect.leftTop.y+self.pixelRect.rightBottom.y);
self.mapCenter=map.PixelToMapCoord(self.pixelCenter,self.zoomLevel);
// 校验传入的 mapRect 的高度与宽度比。以得到正确的比例尺。
// 正确的比例尺定义为:尽量接近原图的比例尺。
// 比如,宽度为原来的 1.1 倍,高度为原来的 1.2 倍,结果应当为 1.1 倍。
// 又如,宽度为原来的 0.9 倍,高度为原来的 0.8 倍,结果应当为 0.9 倍。
// 但是,宽度为原来的 0.9 倍,高度为原来的 1.1 倍,结果应当为 ??? 倍?
// 结果是: 1/0.9 = 1.111 > 1.1,所以,结果为 1.1 倍。
var dScaleRatio;
var dScaleRatioWidth = width / self.pixelRect.Width();
var dScaleRatioHeight = height / self.pixelRect.Height();
// 排列两者。使得 dScaleRatioWidth > dScaleRatioHeight。
dScaleRatio = _Min(dScaleRatioWidth, dScaleRatioHeight);
dScaleRatioWidth = _Max(dScaleRatioWidth, dScaleRatioHeight);
dScaleRatioHeight = dScaleRatio;
if(ensureVisible)
{
dScaleRatio = dScaleRatioWidth;
}
else if (dScaleRatioHeight > 1){ // 两者都大于1。
dScaleRatio = dScaleRatioHeight;
}
else if (dScaleRatioWidth <= 1){ // 两者都小于等于于1。
dScaleRatio = dScaleRatioWidth;
}
else{ // 一大一小。
if (dScaleRatioWidth * dScaleRatioHeight < 1){ // a < 1/b,取a。
dScaleRatio = dScaleRatioWidth;
}
else{
dScaleRatio = dScaleRatioHeight;
}
}
// 调整比例尺。
var ratio = 0;
var validZoomLevel = self.zoomLevel;
var diff = 0;
var minDiff = Number.MAX_VALUE;
for(var i=0; i<self.mapScales.length; i++){
ratio = self.mapScales[i]/self.mapScales[self.zoomLevel-1];
if((dScaleRatio>1 && ratio<1) || (dScaleRatio<1 && ratio>1)){
continue;
}
if(ensureVisible){
diff = dScaleRatio/ratio;
if(diff > 1 && diff < minDiff){
minDiff = diff;
validZoomLevel = i+1;
}
}
else{
diff = ratio/dScaleRatio > 1 ? ratio/dScaleRatio : dScaleRatio/ratio;
if(diff < minDiff){
minDiff = diff;
validZoomLevel = i+1;
}
}
}
self.zoomLevel = validZoomLevel;
self.pixelCenter = map.MapCoordToPixel(self.mapCenter,self.zoomLevel);
}
this.MakeCopy=_MakeCopy;this.Copy=_Copy;this.Equals=_Equals;this.ToString=_ToString;
this.SetPixelCenter=_SetPixelCenter;this.SetMapCenter=_SetMapCenter;this.SetPixelRect=_SetPixelRect;this.SetMapRect=_SetMapRect;this.SetZoomLevel=_SetZoomLevel;this.SetMapName=_SetMapName;
this.GetPixelX=_GetPixelX;this.GetPixelY=_GetPixelY;this.GetPixelCenter=_GetPixelCenter;this.Resolve=_Resolve;
};
SuperMap.IS.QueryLayer=function()
{
this.groupClause=""; // Group By 语句。 比如“group by SmID”。
this.layerId=0; // 查询图层的ID。
this.layerName=""; // 查询图层的名称。
this.returnFields=null; // 需要返回的字段。
this.sortClause=""; // Order By 语句。 比如“order by SmID”。
this.whereClause=""; // 对该图层设置的查询条件语句。
};
SuperMap.IS.QueryParam=function()
{
this.customParams=""; // 自定义参数。
this.expectCount=10; // 期望返回的记录数。
this.hasGeometry=true; // 是否查询空间数据。默认为 true。
// this.highlight 高亮选项,包括是否高亮显示分析结果等。
this.queryAllLayer=false; // 是否需要查询所有图层。
this.queryLayers=null; // 待查询的图层。 QueryLayer 数组。
// this.networkType="point"; // 当查询的数据集类型为NetWork(网络数据集)时,指定查询网络数据集中哪种子数据集。
this.returnFields=null; // 需要返回的字段。
this.startRecord=0; // 起始记录号。默认从0开始计数。
this.whereClause=""; // 所有图层的通用查询条件,不允许在这里设置“ORDER BY”字句。
this.Destroy=function(){this.queryLayers=null;};
};
SuperMap.IS.ResultSet=function()
{
this.currentCount=0;
this.customResponse=""; // 自定义处理结果。
// this.mapResult // 查询结果的地图描述,如果查询结果没有地图描述,此对象变量为空。
this.recordsets=null; // 查询记录集。
this.totalCount=0; // 查询返回记录的总数。
this.Destroy=function(){if(this.recordsets){while(this.recordsets.length>0){this.recordsets.pop().Destroy();}}this.recordsets=null;};
this.FromJSON=function(o){
if(!o){return;}
this.currentCount=o.currentCount;
this.customResponse=o.customResponse;
if(o.recordsets && !this.recordsets){this.recordsets=new Array();}
for(var i=0;o.recordsets && i<o.recordsets.length;i++){
if(o.recordsets[i] && !this.recordsets[i]){this.recordsets[i]=new SuperMap.IS.Recordset();}
if(o.recordsets[i]){this.recordsets[i].FromJSON(o.recordsets[i]);}
}
this.totalCount=o.totalCount;
};
};
SuperMap.IS.Recordset=function()
{
this.layerId=0; // 图层唯一标识。
this.layerName=""; // 结果集中的几何对象所在的图层名称
this.records=null; // 结果集。SuperMap.IS.Record 数组。
this.returnFields=null; // 返回的字段名称数组。
this.Destroy=function(){if(this.records){while(this.records.length>0){this.records.pop().Destroy();}}this.records=null;};
this.FromJSON=function(o){
if(!o){return;}
this.layerId=o.layerId;
this.layerName=o.layerName;
if(o.records && !this.records){this.records=new Array();}
for(var i=0;o.records && i<o.records.length;i++){
if(o.records[i] && !this.records[i]){this.records[i]=new SuperMap.IS.Record();}
if(o.records[i]){this.records[i].FromJSON(o.records[i]);}
}
this.returnFields=o.returnFields;
};
};
SuperMap.IS.Record=function()
{
this.center=null; // 实体的中心点坐标。 MapCoord.
this.fieldValues=null; // 实体的属性信息集合。 string[].
this.Destroy=function(){this.center=null;};
this.FromJSON=function(o){
if(!o){return;}
if(o.center && !this.center){this.center=new SuperMap.IS.MapCoord();}
if(o.center){this.center.x=o.center.x;this.center.y=o.center.y;}
this.fieldValues=o.fieldValues;
};
};
// 事件参数。
function EventArguments(param,error,e){
this.param=param; // 地图参数。
this.error=error; // 错误信息。如果没有错误信息,则该参数的值为""。
this.e=e; // 浏览器事件参数。如果当前事件不是浏览器事件,则该参数为null。
}
// 地图状态信息。
SuperMap.IS.MapStatus=function()
{
this.mapName="";
this.mapScales=null; // int型数组
this.mapBounds=null; // MapRect
this.referViewBounds=null; // MapRect
this.referScale=0; // double
this.referViewer=null // PixelRect
this.Destroy=function(){this.mapBounds=null;this.referViewBounds=null;this.referViewer=null;};
this.FromJSON=function(o){
if(!o){return;}
this.mapName=o.mapName;
this.mapScales=o.mapScales;
if(o.mapBounds && !this.mapBounds){this.mapBounds=new SuperMap.IS.MapRect();}
this.mapBounds.FromJSON(o.mapBounds);
if(o.referViewBounds && !this.referViewBounds){this.referViewBounds=new SuperMap.IS.MapRect();}
this.referViewBounds.FromJSON(o.referViewBounds);
this.referScale=o.referScale;
if(o.referViewer && !this.referViewer){this.referViewer=new SuperMap.IS.PixelRect();}
this.referViewer.FromJSON(o.referViewer);
};
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -