欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Goldmap 应用程序接口的开发和编码

最编程 2024-03-28 18:08:13
...
/** 高德autonavi 地图API Define:begin */
var AutoNaviMap = function(mapOption){

this.map = null; //高德autonavi地图对象

this.mapWrap = mapOption.mapWrap; //地图容器

this.mapRange = mapOption.mapRange; //地图范围

this.centerPoint = mapOption.centerPoint; //中心点

this.GeoServerLayers = mapOption.GeoServerLayers; //GeoServer 图层参数

this.GeoServerlayerEntities = null; //GeoServer 图层实例对象

this.zoom = mapOption.zoom==undefined ? 15 : mapOption.zoom;

this.contextMenuPositon; //右键菜单位置

this.mapLayer;//管线图层

this.heatmap;

this.toolBar = null; // 地图oolBar插件

this.markers = [];

this.infoWindow = {}; //global infoWindow

this.polygon;

this.init = function(){
debugger;
var self = this;
if(!self.map){
var option = {resizeEnable : true, //监控地图容器尺寸变化,默认为false
zoom : self.zoom, //显示级别
mapStyle: "amap://styles/darkblue", //地图样式主题
features:['bg', 'point', 'building'], //地图展示元素
logo : false};
if(self.centerPoint && !$.isEmptyObject(self.centerPoint)){ //设置中心点
var transCoordinate = {
'lng':self.centerPoint.x,
'lat':self.centerPoint.y
};

if(!mapOption.noTransAmap) {
self.centerPoint.lng = self.centerPoint.x;
self.centerPoint.lat = self.centerPoint.y;
transCoordinate = self.get_GCJLngLat(self.centerPoint);
}
option['center'] = new AMap.LngLat(transCoordinate.lng, transCoordinate.lat);
}

self.map = new AMap.Map(self.mapWrap, option);

//地图单击事件
if(mapOption.click && $.isFunction(mapOption.click)) {
debugger;
self.map.on('click',function(e){
var mapPoint = getMapPoint(e); //经纬度
var screenPoint = getScreenPoint(e);
mapOption.click(mapPoint, screenPoint);
}); //点事件的获取
}


//地图缩放结束事件
if(mapOption.zoomend && $.isFunction(mapOption.zoomend)) {
self.map.on('zoomend',function(e){
mapOption.zoomend();
}); //点事件的获取
}

self.map.plugin(["AMap.ToolBar"], function() {
toolBarOption = {
offset:new AMap.Pixel(10,50)
}
toolBar = new AMap.ToolBar(toolBarOption);
self.map.addControl(toolBar);
});
//添加比例尺控件
self.map.plugin(["AMap.Scale"],function(){
self.map.addControl(new AMap.Scale());
});
//地图类型切换
self.map.plugin(["AMap.MapType"],function(){
var type= new AMap.MapType({
defaultType:0 //使用2D地图
});
self.map.addControl(type);
});

$(".amap-maptype-wrap").bind('click',function(){
if(self.mapLayer && self.map){
self.mapLayer.setMap(self.map);
}
}); // 绑定地图切换插件单击事件


}
//在高德地图上 叠加 标准wms图层
setTimeout(function(){
if(self.GeoServerLayers && self.GeoServerLayers.length>0){
self.GeoServerlayerEntities = {};
for(var i=0,len=self.GeoServerLayers.length; i<len; i++){
var geoItem = self.GeoServerLayers[i];
// 创建 WMS 标准图层
var version = geoItem.GeoServerVersion || '1.1.0';
var wms = new AMap.TileLayer.WMS({
url: geoItem.GeoServerLayerUrl,
blend: true,
tileSize: 256,
visible: false,
params: {'LAYERS': geoItem.GeoServerLayerName,VERSION:version}
});
self.GeoServerlayerEntities[geoItem.GeoServerLayerCode] = wms;
//wms.show();
wms.setMap(self.map);
}
}
}, 1000);

if(mapOption.openSatelliteLayer){
var satelliteLayer = new AMap.TileLayer.Satellite();
var roadNetLayer = new AMap.TileLayer.RoadNet();
var layers = [
satelliteLayer
]
// 添加到地图上
self.map.add(layers);
}
};


/**
* checkType : 选中还是取消选中
*/
this.geoAllLayerVisibleOrHide = function(checkType){
var self = this;
var _GeoServerlayerEntities = self.GeoServerlayerEntities;
for(var o in _GeoServerlayerEntities){
if(checkType){
_GeoServerlayerEntities[o].show();
}else{
_GeoServerlayerEntities[o].hide();
}
}
}

/**
* 控制geoServer图层 显示与隐藏
* pipeCode : 管线压力级制编码
* checkType : 选中还是取消选中
*/
this.geoServerLayerVisibleOrHide = function(pipeCode, checkType){
var self = this;
var _GeoServerlayerEntities = self.GeoServerlayerEntities;
var glayer = _GeoServerlayerEntities[pipeCode];
if(checkType){
glayer.show();
}else{
glayer.hide();
}
};

this.drawPolygon = function(mPolygon){
var _self = this;
var coordinatesList = [];
if (mPolygon.points.length > 0) {
$.each(mPolygon.points, function(coordinateIndex, coordinateEntry) {
if(coordinateEntry.lng && coordinateEntry.lat && Number(coordinateEntry.lng)>0 && Number(coordinateEntry.lat)>0){
var transCoordinate = {
'lng':coordinateEntry.lng,
'lat':coordinateEntry.lat
}
//若不是从天地图转换为高德地图,则不用转换坐标系
if(!mPolygon.noTransAmap) {
var transCoordinate = _self.get_GCJLngLat(coordinateEntry);
}
coordinatesList.push(new AMap.LngLat(transCoordinate.lng, transCoordinate.lat));
}
});
if(coordinatesList.length>0) {
polygon = new AMap.Polygon({
map:_self.map,
path: coordinatesList,//设置多边形边界路径
strokeColor: mPolygon.color?mPolygon.color:"#FF33FF", //线颜色
strokeOpacity: mPolygon.opacity?mPolygon.opacity:0.2, //线透明度
strokeWeight: mPolygon.width?mPolygon.width:3, //线宽
fillColor: mPolygon.fillColor?mPolygon.fillColor:"#1791fc", //填充色
fillOpacity: mPolygon.fillOpacity?mPolygon.fillOpacity:0.35,//填充透明度
zIndex:mPolygon.zIndex
});
}
}
return polygon;
};

this.drawLine = function(mLine){
var _self = this;
var polyLine;
var coordinatesList = [];
if (mLine.pionts.length > 0) {
$.each(mLine.pionts, function(coordinateIndex, coordinateEntry) {
if(coordinateEntry.lng && coordinateEntry.lat && Number(coordinateEntry.lng)>0 && Number(coordinateEntry.lat)>0){
var transCoordinate = {
'lng':coordinateEntry.lng,
'lat':coordinateEntry.lat
}
//若不是从天地图转换为高德地图,则不用转换坐标系
if(!mLine.noTransAmap) {
var transCoordinate = _self.get_GCJLngLat(coordinateEntry);
}
coordinatesList.push(new AMap.LngLat(transCoordinate.lng, transCoordinate.lat));
}
});
if(coordinatesList.length>0) {
polyLine = new AMap.Polyline({
id : mLine.id,
map:_self.map,
path: coordinatesList, //设置线覆盖物路径
strokeColor: mLine.color, //线颜色
strokeOpacity: mLine.opacity, //线透明度
strokeWeight: mLine.width, //线宽
strokeStyle: mLine.style, //线样式
strokeDasharray: mLine.dasharray //补充线样式
});
}

if(mLine.infowindow && !$.isEmptyObject(mLine.infowindow)) {
if(!$('body').find('#infowindow').length>0) {
var html = '<div id="infowindow" style="position:absolute;display:none" class="box_wraper"><div class="box_con"><p></p></div><div class="box_img"><img src="/HRSmartGas/platform/images/box_img.png"/></div></div>';
$('body').append(html);
}
polyLine.on('mouseover',function(e) {
$('body').find('#infowindow p').html(mLine.infowindow.content);
$('#infowindow').show();
$('#infowindow').css("left",e.pixel.x-$('#infowindow').width()/2);
$('#infowindow').css("top",e.pixel.y-$('#infowindow').height());
});
polyLine.on('mouseout',function(e) {
$('#infowindow').hide();
});
}

if(mLine.onClick){
polyLine.on('click',function(e) {
mLine.onClick(e);
});
}
}
return polyLine;
};

/**
* 删除点
* point 为map地图对象, drawPoint时返回
*/
this.removePoint = function(point){
this.map.remove(point);
};

this.removeLine = function(mLine){
var _self = this;
_self.map.remove(mLine);
};

this.removePolygon = function(polygon){
var _self = this;
_self.map.remove(polygon);
};
this.drawPoint = function(mPoint){
debugger;
var _self = this;
var transCoordinate = {
'lng':mPoint.lng,
'lat':mPoint.lat
};

var marker;
if(mPoint.lng && mPoint.lat && Number(mPoint.lng)>0 && Number(mPoint.lat)>0){
//若不是从天地图转换为高德地图,则不用转换坐标系
if(!mPoint.noTransAmap) {
transCoordinate = _self.get_GCJLngLat(mPoint);
}
var icon;
if(mPoint.type.imgUrl == "") {
icon = new AMap.Icon({
imageSize:new AMap.Size(mPoint.type.width,mPoint.type.height),
size: new AMap.Size(mPoint.type.width,mPoint.type.height), //图标大小
});
} else {
icon = new AMap.Icon({
imageSize:new AMap.Size(mPoint.type.width,mPoint.type.height),
size: new AMap.Size(mPoint.type.width,mPoint.type.height), //图标大小
image:mPoint.type.imgUrl
});
}

var pointOpitons = {
map:_self.map,
icon:icon,
position:[transCoordinate.lng,transCoordinate.lat],
offset:new AMap.Pixel(mPoint.type.xoffset, mPoint.type.yoffset), //偏移量
title:mPoint.type.title, //点的文字提示
extData:mPoint
};
marker = new AMap.Marker(pointOpitons);
mPoint.marker = marker;
if(mPoint.type.onClick && $.isFunction(mPoint.type.onClick)) {
marker.on('click',function(e){
debugger;
mPoint.type.onClick(e.target.getExtData(),null);
}); //点事件的获取
}
if(null != mPoint.labelContent && '' != mPoint.labelContent && 'undefined' != mPoint.labelContent){
marker.setLabel({
offset: new AMap.Pixel(20, -10), //显示位置
content: mPoint.labelContent //显示内容
});
}
_self.markers.push(mPoint);
}
if(mPoint.type.showInfo && mPoint.type.infowindow && !$.isEmptyObject(mPoint.type.infowindow)) {
debugger;
if(marker != undefined) {
var position = {
'lng':mPoint.lng,
'lat':mPoint.lat
};
if(!mapOption.noTransAmap) {
position = _self.get_GCJLngLat({'lng':mPoint.lng,'lat':mPoint.lat});
}
var infowindow = mPoint.type.infowindow;
var infoMouseOverWin = new AMap.InfoWindow({
isCustom:true,
content: infowindow.content,
offset: new AMap.Pixel(infowindow.xoffset,infowindow.yoffset)
});
infoMouseOverWin.open(_self.map, new AMap.LngLat(position.lng,position.lat));
_self.infoWindow.uniqueCode = mPoint.busiKey;
}
}
};

/**
* 展示自定义弹出框
*/
this.showInfoWindow = function(mPoint){
debugger;
var _self = this;
if(mPoint.type.infowindow && !$.isEmptyObject(mPoint.type.infowindow)) {
var position = {
'lng':mPoint.lng,
'lat':mPoint.lat
};
if(!mapOption.noTransAmap) {
position = _self.get_GCJLngLat({'lng':mPoint.lng,'lat':mPoint.lat});
}
var infowindow = mPoint.type.infowindow;
var infoMouseOverWin = new AMap.InfoWindow({
isCustom:true,
content: infowindow.content,
offset: new AMap.Pixel(infowindow.xoffset,infowindow.yoffset)
});
infoMouseOverWin.open(_self.map, new AMap.LngLat(position.lng,position.lat));
_self.infoWindow.uniqueCode = mPoint.busiKey;
}
}

this.getInfoWindowUnique = function(){
var _self = this;
return _self.infoWindow.uniqueCode;
}

this.clearGraphics = function(type) {
var _self = this;
for(var i =0; i<_self.markers.length; i++){
if(type){
if((_self.markers[i].node == type))
_self.map.remove(_self.markers[i].marker);
}else{
_self.map.remove(_self.markers[i].marker);
}

}
};

/**
* e 鼠标事件对象
*/
function getScreenPoint(e){
return new SreenPoint({x:e.pixel.x, y:e.pixel.y});
};

/**
* e 鼠标事件对象
*/
function getMapPoint(e){
return new MapPoint({'lng' : e.lnglat.lng, 'lat' : e.lnglat.lat});
};


//绘制管线图层
this.drawArcgisTile = function(url,token,callback) {
var _self = this;
if(_self.mapLayer){
mapLayer.setTileUrl(callback);
} else {
_self.mapLayer = new AMap.TileLayer({
zIndex:20,
getTileUrl: function(x,y,z){
return url+'/'+ z +'/'+ y +'/'+ x+'?token='+token;
}
});
_self.mapLayer.setMap(_self.map);
}
return _self.mapLayer;
};

//重新加载arcgis管线图层
this.reloadArcgisTile = function(){
if(_self.mapLayer && _self.map){
_self.mapLayer.setMap(_self.map);
}
}

//画热力图
this.drawHeatMap = function(heatMap) {
var _self = this;
var coordinatesList = [];
if (heatMap.data.length > 0) {
$.each(heatMap.data, function(coordinateIndex, coordinateEntry) {
if(coordinateEntry.lng && coordinateEntry.lat && Number(coordinateEntry.lng)>0 && Number(coordinateEntry.lat)>0){
var transCoordinate = {
'lng':coordinateEntry.lng,
'lat':coordinateEntry.lat
}
//若不是从天地图转换为高德地图,则不用转换坐标系
if(!heatMap.noTransAmap) {
transCoordinate = _self.get_GCJLngLat(coordinateEntry);
}
coordinatesList.push(new AMap.LngLat(transCoordinate.lng, transCoordinate.lat));
}
});
}
if(coordinatesList.length>0) {
_self.map.plugin(["AMap.Heatmap"], function() {
//初始化heatmap对象
_self.heatmap = new AMap.Heatmap(_self.map, {
radius: 80, //给定半径
opacity: [0, 0.8]
});
//设置数据集
_self.heatmap.setDataSet({
data: coordinatesList,
max: 2
});
});
}
}

/**
*画圆 获取中心点及半径
*20180122
*/
this.draw =function (){
var _self = this;
var mouseTool = new AMap.MouseTool(_self.map);
//自定义图形样式
mouseTool.polyline({
strokeColor:"#f50", // 线条颜色,十六进制
strokeOpacity:0.5, // 线条透明度
strokeWeight:10, // 线条宽度
strokeStyle:"dashed" // 线条样式 solid || dashed
});
//在地图中添加MouseTool插件
mouseTool.circle(); //用鼠标工具画圆
AMap.event.addListener( mouseTool,'draw',function(e){ //添加事件
console.log(e.obj.getRadius());//获取半径
console.log(e.obj.getCenter());//获取中心点
showChoseDevice(e.obj.getRadius(),e.obj.getCenter());
mouseTool.close(true);//关闭当前鼠标操作
});

} ;



//画圆
this.drawCircle = function(circle){
var _self = this;
var center = new AMap.LngLat(circle.center.lng,circle.center.lat);
var circleOptions = {
center:center,
zIndex:1000,
radius:circle.radius, //半径1公里
strokeColor: "#F33", //线颜色
strokeOpacity: 1, //线透明度
strokeWeight: 3, //线粗细度
fillColor: "#ee2200", //填充颜色
fillOpacity: 0.35//填充透明度
};
var _circle = new AMap.Circle(circleOptions);
_circle.setMap(_self.map);
circle.marker = _circle;
}

this.circleContains = function(circle,point) {
var _self = this;
var transCoordinate = {
'lng':point.lng,
'lat':point.lat
}
//若不是从天地图转换为高德地图,则不用转换坐标系
if(!point.noTransAmap) {
transCoordinate = _self.get_GCJLngLat(point);
}
var _point = new AMap.LngLat(transCoordinate.lng,transCoordinate.lat);
var isContains = circle.marker.contains(_point);
return isContains;
}

//绑定地图缩放事件
this.bindZoomChange = function(callBack) {
var _self = this;
_self.map.on('zoomchange', function(e) {
callBack(_self.map.getZoom());
});
}

//绑定地图单击事件
this.bindClick = function(callBack) {
var _self = this;
_self.map.on('click', function(e) {
callBack(e.lnglat.getLng(),e.lnglat.getLat(),_self.map.getZoom());
});
}

/**
* 获取缩放等级
*/
this.getZoom = function(){
var _self = this;
return _self.map.getZoom();
}

//显示或隐藏热力图
this.showHeatMap = function(isShow) {
var _self = this;
if(_self.heatmap) {
if(isShow) {
_self.heatmap.show();
} else {
_self.heatmap.hide();
}
}

}

//添加右键菜单获取坐标
this.addGetLnglatMenu = function() {
var _self = this;
var menu = new AMap.ContextMenu();
//添加菜单项
menu.addItem("发送任务",function() {
debugger;
mapDbClick(contextMenuPositon.getLat(),contextMenuPositon.getLng());
//alert(contextMenuPositon.getLng() + "," + contextMenuPositon.getLat());
},0);

//为地图注册rightclick事件获取鼠标点击出的经纬度坐标
var clickEventListener = _self.map.on('rightclick', function(e) {
menu.open(_self.map,e.lnglat);
contextMenuPositon = e.lnglat;
});
};

this.setCenter = function(lnt,lat) {
var transCoordinate = {
'lng':lnt,
'lat':lat
};
var _self = this;
if(!mapOption.noTransAmap) {
_self.centerPoint.lng = lnt;
_self.centerPoint.lat = lat;
transCoordinate = _self.get_GCJLngLat(_self.centerPoint);
}
_self.map.setCenter(new AMap.LngLat(transCoordinate.lng, transCoordinate.lat));
};

this.closeInfoWindow = function(infoWindow) {
var _self = this;
_self.map.clearInfoWindow();
};

this.fromLngLatToContainerPixel = function(mPoint) {
var _self = this;
var retObj = _self.map.lnglatToPixel(new AMap.LngLat(mPoint.lng,mPoint.lat));
return new SreenPoint(retObj);
};

this.fromContainerPixelToLngLat = function(mPoint) {
var _self = this;
var retObj = _self.map.pixelToLngLat(new AMap.Pixel(mPoint.x,mPoint.y));
return new MapPoint(retObj);
};
this.setFitView = function() {
var _self = this;
_self.map.setFitView();
};
this.zoomOut = function() {
var _self = this;
_self.map.zoomOut();
}
this.get_GCJLngLat = function(mPoint) {

var retObj = {};
var CT = new CoordinateTransform(mPoint.lat, mPoint.lng, CoordinateSys.WGS84);//CoordinateSys.WGS84 是转换前的坐标系
var retValue = new Object();
if (CT.WGS84ToGCJ02()== false)//WGS84ToBD09()方法 WGS84转BD坐标,如果是转成火星坐标改调用WGS84ToGCJ02()
console.info(CT.get_ErrMsg());
retObj.lat = CT.get_GCJLat() == 0 ? mPoint.lat : CT.get_GCJLat();//获取转换后的高德坐标纬度
retObj.lng = CT.get_GCJLng() == 0 ? mPoint.lng : CT.get_GCJLng();//获取转换后的高德坐标精度
return retObj;
};

};

function openWindowTask(tltle,url){
var options = {
modal : true,
title : tltle,
collapsible : false,
minimizable : false,
maximizable : false,
closable : true,
closed : false
};
var uid = "self_card_";
options["id"] = uid;
winFormDesigner = UIFactory.getUI(uid);
if(!winFormDesigner){
winFormDesigner = UIFactory.create(xpad.ui.Window, options);
}
var root = jQuery("body");
var offset = root.offset();
var winleft = 0;
var wintop = 0;
var newSize = {};
newSize["left"] = (jQuery("body").width()-450)/2;
newSize["top"] = 20;
newSize["width"] = 450;//jQuery("body").width();
newSize["height"] = 500;//jQuery("body").height();
winFormDesigner.window("resize", newSize);
setTimeout(function(){
winFormDesigner.loadURL(url);
}, 0);
}


AutoNaviMap.CLASS_NAME = "AutoNaviMap";
/**高德autonavi 地图API Define:end */

推荐阅读