基于 OpenLayers地图加载功能Javascript类定义
基于 OpenLayers地图加载功能Javascript类定义
MapCwgisLoadMapCmd.js
//定义加载地图的命令功能
//vp:hsg,myk
//create date:2013-07-29
MapCwgisLoadMapCmd = OpenLayers.Class(mapCwgisPluginCommand,
{
//定义类 注销函数
dispose: function () {
},
//定义单击事件
onClick: function () {
if (cmToolBar != null) {
cmToolBar.deactivateItems();
}
var wms_url = this.mapWrap.wms_url;
var defaultProjection = this.mapWrap.defaultProjection;
var defaultFormat = this.mapWrap.defaultFormat;
var bounds = this.mapWrap.defaultBounds;
//图层名称
var layer_DOM = this.mapWrap.layer_DOM; //DOM层名;
var layer_XZQ = this.mapWrap.layer_XZQ; //行政区层名
var layer_DX = this.mapWrap.layer_DX; //其他地类层名
var layer_ZD = this.mapWrap.layer_ZD; //宗地层名
var layer_ZD_LS = this.mapWrap.layer_ZD_LS; //宗地历史图层名称
//定义一个影像地图服务层
//layers: layer_DOM + ',' + layer_XZQ + ',' + layer_DX + ',' + layer_ZD + ',' + layer_ZD_LS,
mapWrap.map_Raster = new OpenLayers.Layer.WMS(
"影像", wms_url,
{
layers: layer_DOM + ',' + layer_XZQ + ',' + layer_DX + ',' + layer_ZD_LS + ',' + layer_ZD,
styles: '',
tiled: true,
srs: defaultProjection,
format: defaultFormat
},
{
singleTile: true, ratio: 1
}
);
//定义一个宗地矢量服务层
this.mapWrap.map_Cadastra = new OpenLayers.Layer.WMS(
"宗地", wms_url,
{
layers: layer_XZQ + ',' + layer_DX + ',' + layer_ZD_LS + ',' + layer_ZD,
styles: '',
tiled: true,
srs: defaultProjection,
format: defaultFormat
},
{
singleTile: true, ratio: 1
}
);
this.mapWrap.layer_Editor = new OpenLayers.Layer.Vector("编辑层");
this.mapWrap.layer_Highlight = new OpenLayers.Layer.Vector("高亮显示层");
//添加图层到地图
this.mapWrap.map.addLayers([this.mapWrap.map_Raster, this.mapWrap.layer_Editor, this.mapWrap.layer_Highlight]);
this.mapWrap.map.setCenter(new OpenLayers.LonLat(0, 0), 3);
//添加查询图层到地图
this.mapWrap.layer_Query = mapWrap.createLayerQuery("查询图层");
this.mapWrap.map.addLayers([this.mapWrap.layer_Query]);
//获取地图最大范围
var t_maxExtent = this.mapWrap.map.getMaxExtent();
if (t_maxExtent != null) {
this.mapWrap.defaultBounds = t_maxExtent;
bounds = t_maxExtent;
}
//放大到指定范围地图
this.mapWrap.map.zoomToExtent(bounds);
},
//交换显示地图
//isCadastraMap=true:打开宗地图,不含影像
//isCadastraMap=false:打开宗地图,含影像
isCadastraMap: false,
//交换显示地图方法
switchMap: function () {
this.switchMapByParam(this.isCadastraMap);
},
switchMapByParam: function (isChecked) {
if (isChecked) {
if (this.mapWrap.map_Raster != null) {
this.mapWrap.map.removeLayer(this.mapWrap.map_Raster);
this.mapWrap.map.addLayer(this.mapWrap.map_Cadastra);
}
}
else {
if (this.mapWrap.map_Cadastra != null) {
this.mapWrap.map.removeLayer(this.mapWrap.map_Cadastra);
this.mapWrap.map.addLayer(this.mapWrap.map_Raster);
}
}
},
CLASS_NAME: "MapCwgisLoadMapCmd"
//
});
//加载地图并显示
var lmcmd = new MapCwgisLoadMapCmd(mapWrap);
lmcmd.init(mapWrap);
lmcmd.onClick();
//
//切换地图主题函数(矢量/影像切换模式)
function switchMap(isChecked) {
if (lmcmd != null) {
lmcmd.switchMapByParam(isChecked);
}
}
//
转载自:https://blog.csdn.net/hsg77/article/details/22333067