日期:2014-05-16 浏览次数:20662 次
基于OpenLayers的地图封装Javascript类定义
MapCwgisClass.js
//web地图封装类
//MapCwgisClass类的定义
//vp:hsg,myk
//create date:2013-07-26
//类 原型定义
var Person = function () {
this.m_Name = "good";
}
Person.prototype = {
m_Name: '',
getName: function () {
return this.m_Name;
}
}
//类 原型定义
var MapCwgisClass=function()
{
//OpenLayers环境参数
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 5;
OpenLayers.DOTS_PER_INCH = 25.4 / 0.28;
OpenLayers.INCHES_PER_UNIT["千米"] = OpenLayers.INCHES_PER_UNIT["km"];
OpenLayers.INCHES_PER_UNIT["米"] = OpenLayers.INCHES_PER_UNIT["m"];
OpenLayers.INCHES_PER_UNIT["英里"] = OpenLayers.INCHES_PER_UNIT["mi"];
OpenLayers.INCHES_PER_UNIT["英寸"] = OpenLayers.INCHES_PER_UNIT["ft"];
this.defaultFormat = 'image/png';
//
this.map=null;
}
MapCwgisClass.prototype={
//属性
wms_url:null,
wms_url_getFeature:null,
map_divid:null,
map: null,
currentClientPoint: null,
currentClientMapPoint:null,
m_CurrentTool:null,
ProxyHost:null,
defaultFormat:null,
defaultProjection:null,
defaultBounds:null,
vlayer_drawFeature:null,
layer_Highlight:null,
LayerList:null,
//自定义的wms图层属性
map_Raster:null,
map_Cadastra:null,
//
//图层名称
layer_DOM: "RFS_DOM", //DOM层名;
layer_XZQ: "RFS_XZQ", //行政区层名
layer_DX : "RFS_MZDW", //其他地类层名
layer_ZD : "RFS_CBD_ZD", //宗地层名
//新添加图层
layer_ZD_LS:"RFS_CBD_LS", //地块历鸣图层名称
//方法
//初始化地图方法
init:function()
{
//OpenLayers.ProxyHost = 'GeoServerProxy.aspx?URL=';
OpenLayers.ProxyHost =this.ProxyHost;
//
//默认参数
this.defaultProjection = "EPSG:2358";
this.defaultBounds = new OpenLayers.Bounds(
34602000.15, 3318000.3500000006,
34609999.65, 3326999.8500000006);
var bounds = this.defaultBounds;
//选项
var options = {
controls: [], //若添加编辑框就在[]中加上 new OpenLayers.Control.EditingToolbar(vlayer)
maxExtent: bounds,
maxResolution: 35.154296875,
projection: this.defaultProjection,
units: 'm',
allOverlays: false //true代表允许叠加显示图层
};
//初始化地图对象
this.map = new OpenLayers.Map(this.map_divid, options);
map=this.map; //给全局变量map赋值
mapWrap = this; //给全局变量赋值
var t_LLPoint=new OpenLayers.LonLat(0, 0);
//this.setCenterPoint(t_LLPoint, 3);
//放大到指定范围地图
//this.map.zoomToExtent(bounds);
//
},
setCenterPoint:function(openLayerLonLatPoint,Level)
{
if(this.map!=null)
{
this.map.setCenter(openLayerLonLatPoint,Level);
}
},
//创建wms图层
createLayerWms:function(p_mapName,p_wms_url,p_layers)
{
var t_mapLayer = new OpenLayers.Layer.WMS(
p_mapName, p_wms_url,
{
layers: p_layers,
styles: '',
tiled: true,
srs: defaultProjection,
format: defaultFormat
},
{
singleTile: true, ratio: 1
}
);
return t_mapLayer;
},
//创建Vector图层
createLayerVector:function(p_LayerName)
{
var t_layer_vector = new OpenLayers.Layer.Vector(p_LayerName);
return t_layer_vector;
},
//创建查询图层
createLayerQuery:function(p_QueryLayerName)
{
var t_querylayerName='查询图层';
if(p_QueryLayerName!=null && p_QueryLayerName!="")
{
t_querylayerName=p_QueryLayerName;
}
var t_styleMap=new OpenLayers.StyleMap({
"d