| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722 |
- /**
- * Created by Wandergis on 2015/7/8.
- * 提供了百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换
- */
- var map, geoc;
- $.ajax({
- type: "post",
- url: "user_location",
- data: {
- // req: "cbd",
- },
- dataType: "json",
- success: function (data) {
- //百度地图获取坐标
- map = new BMap.Map("allmap", { });// 创建地图实例
- // map = new BMap.Map("allmap", { mapType: BMAP_HYBRID_MAP });// 创建地图实例
- // map.centerAndZoom(new BMap.Point(113.64964385, 34.75661006), 13);// 创建点坐标
- var parentUserName = $('#parentUserName', parent.document).html();
- if (parentUserName == '罗普特') {
- map.centerAndZoom(new BMap.Point(112.55, 37.87), 13);// 创建点坐标
- } else if (data.user_pro != '' || data.user_city != '' ||data.user_area != '') {
- if(data.user_area){
- map.centerAndZoom(data.user_area,11);
- }else if(data.user_city){
- map.centerAndZoom(data.user_city,11);
- }else{
- map.centerAndZoom(data.user_pro,11);
- }
- }else{
- map.centerAndZoom(new BMap.Point(113.64964385, 34.75661006), 13);// 创建点坐标
- }
- map.enableScrollWheelZoom(true);
- map.addControl(new BMap.NavigationControl()); // 添加平移缩放控件
- map.addControl(new BMap.ScaleControl()); // 添加比例尺控件
- map.addControl(new BMap.OverviewMapControl()); //添加缩略地图控件
- map.enableScrollWheelZoom(); //启用滚轮放大缩小
- map.addControl(new BMap.MapTypeControl()); //添加地图类型控件
- // map.setMapStyle({style:'midnight'});
- map.addEventListener("tilesloaded", function () {
- $(".BMap_cpyCtrl").hide();
- // $(".anchorBL").hide();
- });//地图加载完毕后 隐藏百度图标
- geoc = new BMap.Geocoder();
- if ($('.content').height() > 750) {
- $('#iframe-main', parent.document).css('height', $('.content').height() + 20)
- } else {
- $('#iframe-main', parent.document).css('height', '750px')
- }
- }
- });
- // //百度地图获取坐标
- // var map = new BMap.Map("allmap", { mapType: BMAP_HYBRID_MAP });// 创建地图实例
- // // map.centerAndZoom(new BMap.Point(113.64964385, 34.75661006), 13);// 创建点坐标
- // var parentUserName = $('#parentUserName', parent.document).html();
- // if (parentUserName == '罗普特') {
- // map.centerAndZoom(new BMap.Point(112.55, 37.87), 13);// 创建点坐标
- // } else {
- // map.centerAndZoom(new BMap.Point(113.64964385, 34.75661006), 13);// 创建点坐标
- // }
- // map.enableScrollWheelZoom(true);
- // map.addControl(new BMap.NavigationControl()); // 添加平移缩放控件
- // map.addControl(new BMap.ScaleControl()); // 添加比例尺控件
- // map.addControl(new BMap.OverviewMapControl()); //添加缩略地图控件
- // map.enableScrollWheelZoom(); //启用滚轮放大缩小
- // map.addControl(new BMap.MapTypeControl()); //添加地图类型控件
- // // map.setMapStyle({style:'midnight'});
- // var stCtrl = new BMap.PanoramaControl(); //全景图
- // stCtrl.setOffset(new BMap.Size(20, 20));
- // map.addControl(stCtrl);
- window.onload = function () {
- //请求数据:
- // $.ajax({
- // type: "post",
- // url: "home_map/map_locat",
- // data: {
- // req: "cbd",
- // },
- // dataType: "json",
- // success: function (data) {
- // eachItem(data)
- // }
- // });
- // $.ajax({
- // type: "post",
- // url: "home_map/map_locat",
- // data: {
- // req: "scd",
- // },
- // dataType: "json",
- // success: function (data) {
- // eachItem(data)
- // }
- // });
- // $.ajax({
- // type: "post",
- // url: "home_map/map_locat",
- // data: {
- // req: "qxz",
- // },
- // dataType: "json",
- // success: function (data) {
- // eachItem(data)
- // }
- // });
- }
- // function eachItem(data_info) {
- // var points = []; // 添加海量点数据
- // for (var i = 0; i < data_info.length; i++) {
- // if (data_info[i].lng > 999) {
- // var lng = Math.floor(data_info[i].lng / 100) + ((data_info[i].lng % 100) / 60);
- // var lat = Math.floor(data_info[i].lat / 100) + ((data_info[i].lat % 100) / 60);
- // } else {
- // var lat = data_info[i].lat;
- // var lng = data_info[i].lng;
-
- // }
- // if (data_info[i].lat && data_info[i].lng) {
- // //标注图标
- // var orgType = data_info[i].equip_type;//parseInt(0) data_info[i].equip_type
- // if (orgType == 5) {
- // var equip_type = '环境监测';
- // var options = {
- // size: BMAP_POINT_SIZE_BIG,
- // shape: BMAP_POINT_SHAPE_CIRCLE,
- // color: '#001dff'
- // }
- // // var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 1 * 23) });
- // } else if (orgType == 2) {
- // var equip_type = '杀虫灯';
- // var options = {
- // size: BMAP_POINT_SIZE_BIG,
- // shape: BMAP_POINT_SHAPE_CIRCLE,
- // color: '#ff6600'
- // }
- // // var myIcon = new BMap.Icon("/static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 2 * 23) });
- // } else if (orgType == 3) {
- // var equip_type = '虫情测报';
- // var options = {
- // size: BMAP_POINT_SIZE_BIG,
- // shape: BMAP_POINT_SHAPE_CIRCLE,
- // color: '#9c1ee4'
- // }
- // // var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -13), imageOffset: new BMap.Size(0, 0 - 3 * 23) });
- // } else if (orgType == 4) {
- // var equip_type = '性诱器设备';
- // var options = {
- // size: BMAP_POINT_SIZE_BIG,
- // shape: BMAP_POINT_SHAPE_CIRCLE,
- // color: '#ff2da9'
- // }
- // // var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 6 * 23) });
- // } else if (orgType == 6) {
- // var equip_type = '监控设备';
- // var options = {
- // size: BMAP_POINT_SIZE_BIG,
- // shape: BMAP_POINT_SHAPE_CIRCLE,
- // color: 'green'
- // }
- // // var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 5 * 23) });
- // } else if (orgType == 7) {
- // var equip_type = '孢子仪设备';
- // var options = {
- // size: BMAP_POINT_SIZE_BIG,
- // shape: BMAP_POINT_SHAPE_CIRCLE,
- // color: '#ff0000'
- // }
- // // var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 0 * 23) });
- // } else if (orgType == 8) {
- // var equip_type = '农药残留';
- // var options = {
- // size: BMAP_POINT_SIZE_BIG,
- // shape: BMAP_POINT_SHAPE_CIRCLE,
- // color: '#ff7600'
- // }
- // // var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 4 * 23) });
- // }
- // // console.log(lat,lng);
- // //判断当前是否为杀虫灯
- // if (data_info[i].equip_type == 2) {
- // if (data_info[i].gps == 1) {
- // // 先从WGS84转火星再转百度 GPS定位
- // var lng1 = wgs84togcj02(lng, lat);
- // var lngData = gcj02tobd09(lng1[0], lng1[1]);
- // // console.log(lngData + 'GPS定位')
- // } else if (data_info[i].gps == 2) {
- // //直接从火星转百度 基站定位
- // var lngData = gcj02tobd09(lng, lat)
- // // console.log(lngData + '基站定位')
- // } else if (data_info[i].gps == 0) {
- // //手动定位不需要进行操作
- // var lngData = []
- // lngData.push(lng)
- // lngData.push(lat)
- // // console.log(lngData + '手动定位')
- // }
- // var point = new BMap.Point(lngData[0], lngData[1]);
- // point.equip_id= data_info[i].equip_id;
- // point.equip_name= data_info[i].equip_name;
- // point.equip_type = equip_type;
- // point.orgType = orgType;
- // points.push(point);
- // } else if (data_info[i].equip_type == 3) {
- // // console.log('测报灯')
- // //测报灯
- // if (data_info[i].gps == 1) {
- // // 先从WGS84转火星再转百度 GPS定位
- // var lng1 = wgs84togcj02(lng, lat);
- // var lngData = gcj02tobd09(lng1[0], lng1[1]);
- // // console.log(lngData + 'GPS定位')
- // } else if (data_info[i].gps == 2) {
- // //直接从火星转百度 基站定位
- // var lngData = gcj02tobd09(lng, lat)
- // // console.log(lngData + '基站定位')
- // } else if (data_info[i].gps == 0) {
- // //手动定位不需要进行操作
- // var lngData = []
- // lngData.push(lng)
- // lngData.push(lat)
- // // console.log(lngData + '手动定位')
- // }
- // var point = new BMap.Point(lngData[0], lngData[1]);
- // point.equip_id= data_info[i].equip_id;
- // point.equip_name= data_info[i].equip_name;
- // point.equip_type = equip_type;
- // point.orgType = orgType;
- // points.push(point);
- // } else {
- // var lng1 = wgs84togcj02(lng, lat);
- // var lng2 = gcj02tobd09(lng1[0], lng1[1]);
- // // console.log(lng1[0] + ',' + lng1[1] + '火星坐标')
- // // console.log(lng2[0] + ',' + lng2[1] + '百度坐标')
- // // console.log(lng1,lng2);
- // // pointArray[i] = new BMap.Point(lng2[0], lng2[1]);
- // // pointArray.push(new BMap.Point(lng2[0], lng2[1]))
- // // var point = new BMap.Point(lng2[0], lng2[1]);
-
- // var point = new BMap.Point(lng1[0], lng1[1]);
- // point.equip_id= data_info[i].equip_id;
- // point.equip_name= data_info[i].equip_name;
- // point.equip_type = equip_type;
- // point.orgType = orgType;
- // points.push(point);
- // }
-
- // // var lng1 = wgs84togcj02(lng, lat);
- // // var lng2 = gcj02tobd09(lng1[0], lng1[1]);
- // // // console.log(lng1[0] + ',' + lng1[1] + '火星坐标')
- // // // console.log(lng2[0] + ',' + lng2[1] + '百度坐标')
- // // // console.log(lng1,lng2);
- // // // pointArray[i] = new BMap.Point(lng2[0], lng2[1]);
- // // // pointArray.push(new BMap.Point(lng2[0], lng2[1]))
- // // // var point = new BMap.Point(lng2[0], lng2[1]);
- // // var point = new BMap.Point(lng1[0], lng1[1]);
- // // point.equip_id= data_info[i].equip_id;
- // // point.equip_name= data_info[i].equip_name;
- // // point.equip_type = equip_type;
- // // point.orgType = orgType;
- // // points.push(point);
-
-
- // // var enterNum = equip_type;//data_info[i].equip_name
- // // var content = '<p>名称:' + data_info[i].equip_name + '</p><p class="gotoDetial" onclick="gotoManageDetial(\'' + data_info[i].equip_id + ' \',' + orgType + ')">IMEI:' + data_info[i].equip_id + '</p><p>经度:' + lng2[0] + '</p><p>纬度:' + lng2[1] + '</p><p class="area">位置:' + data_info[i].equip_location + '</p></br>';
- // // if (data_info[i].equip_location) {
- // // var flag = true;
- // // } else {
- // // var flag = false;
- // // }
-
-
- // // 将标注添加到地图中
- // // addClickHandler(content, marker, enterNum, flag);
- // }
- // }
-
- // var pointCollection = new BMap.PointCollection(points, options); // 初始化PointCollection
- // // var pointCollection = new BMap.Marker(new BMap.Point(118.60865944575743,36.938527592949285));
- // pointCollection.addEventListenr('click', function (e) {
- // var point = new BMap.Point(e.point.lng, e.point.lat);
- // geoc.getLocation(point, function (rs) {
- // var addComp = rs.addressComponents;
- // $('.area').html('位置:' + addComp.province + ", " + addComp.city + ", " + addComp.district)
- // });
- // var opts = {
- // width: 200, // 信息窗口宽度
- // height: 150, // 信息窗口高度
- // title: e.point.equip_type, // 信息窗口标题
- // enableMessage: true//设置允许信息窗发送短息
- // };
- // var content = '<p>名称:' + e.point.equip_name + '</p><p class="gotoDetial" onclick="gotoManageDetial(\'' + e.point.equip_id + ' \',' + e.point.orgType + ')">IMEI:' + e.point.equip_id + '</p><p>经度:' + e.point.lng + '</p><p>纬度:' + e.point.lat + '</p><p class="area">位置:' + e.point.equip_location + '</p></br>';
- // var infoWindow = new BMap.InfoWindow(content, opts)
- // map.openInfoWindow(infoWindow, point)
- // });
- // map.addOverlay(pointCollection); // 添加Overlay
- // //让所有点在视野范围内
- // map.setViewport(points);
- // }
- function eachItem(data_info) {
- var points = []; // 添加海量点数据
- for (var i = 0; i < data_info.length; i++) {
- if (data_info[i].lng > 999) {
- var lng = Math.floor(data_info[i].lng / 100) + ((data_info[i].lng % 100) / 60);
- var lat = Math.floor(data_info[i].lat / 100) + ((data_info[i].lat % 100) / 60);
- } else {
- var lat = data_info[i].lat;
- var lng = data_info[i].lng;
-
- }
- if (lat && lng) {
- //标注图标
- var orgType = data_info[i].equip_type;//parseInt(0) data_info[i].equip_type
- if (orgType == 5) {
- var equip_type = '环境监测';
- var options = {
- size: BMAP_POINT_SIZE_BIG,
- shape: BMAP_POINT_SHAPE_CIRCLE,
- color: '#001dff'
- }
- // var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 1 * 23) });
- } else if (orgType == 2) {
- var equip_type = '杀虫灯';
- var options = {
- size: BMAP_POINT_SIZE_BIG,
- shape: BMAP_POINT_SHAPE_CIRCLE,
- color: '#ff6600'
- }
- // var myIcon = new BMap.Icon("/static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 2 * 23) });
- } else if (orgType == 3) {
- var equip_type = '虫情测报';
- var options = {
- size: BMAP_POINT_SIZE_BIG,
- shape: BMAP_POINT_SHAPE_CIRCLE,
- color: '#9c1ee4'
- }
- // var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -13), imageOffset: new BMap.Size(0, 0 - 3 * 23) });
- } else if (orgType == 4) {
- var equip_type = '性诱器设备';
- var options = {
- size: BMAP_POINT_SIZE_BIG,
- shape: BMAP_POINT_SHAPE_CIRCLE,
- color: '#ff2da9'
- }
- // var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 6 * 23) });
- } else if (orgType == 6) {
- var equip_type = '监控设备';
- var options = {
- size: BMAP_POINT_SIZE_BIG,
- shape: BMAP_POINT_SHAPE_CIRCLE,
- color: 'green'
- }
- // var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 5 * 23) });
- } else if (orgType == 7) {
- var equip_type = '孢子仪设备';
- var options = {
- size: BMAP_POINT_SIZE_BIG,
- shape: BMAP_POINT_SHAPE_CIRCLE,
- color: '#ff0000'
- }
- // var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 0 * 23) });
- } else if (orgType == 8) {
- var equip_type = '农药残留';
- var options = {
- size: BMAP_POINT_SIZE_BIG,
- shape: BMAP_POINT_SHAPE_CIRCLE,
- color: '#ff7600'
- }
- // var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 4 * 23) });
- }
- if (data_info[i].equip_type == 2 ||data_info[i].equip_type ==3 || data_info[i].equip_type ==4 ) {
- if (data_info[i].gps == 1) {
- //convert wgs84 to cj02
- var cj02 = coordtransform.wgs84togcj02(lng, lat);//gps转火星定位
- //convert cj02 to bd09
- var lngData = coordtransform.gcj02tobd09(cj02[0], cj02[1]);//火星转百度定位
- } else if (data_info[i].gps == 2) {
- //convert cj02 to bd09
- var lngData = coordtransform.gcj02tobd09(lng, lat);//火星转百度定位
- } else if (data_info[i].gps == 0) {
- //手动定位不需要进行操作
- var lngData = []
- lngData.push(lng)
- lngData.push(lat)
- }else{
- //万一上报设备定位GPS标志不为012
- var lngData = []
- lngData.push(lng)
- lngData.push(lat)
- }
- }else if(data_info[i].equip_type == 5){
- //convert cj02 to bd09
- var lngData = coordtransform.gcj02tobd09(lng, lat);//火星转百度定位
- }else {
- var lngData = []
- lngData.push(lng)
- lngData.push(lat)
- }
- var point = new BMap.Point(lngData[0], lngData[1]);
- point.equip_id= data_info[i].equip_id;
- point.equip_name= data_info[i].equip_name;
- point.equip_type = equip_type;
- point.orgType = orgType;
- points.push(point);
- }
- }
-
- var pointCollection = new BMap.PointCollection(points, options); // 初始化PointCollection
- pointCollection.addEventListener('click', function (e) {
- var point = new BMap.Point(e.point.lng, e.point.lat);
- geoc.getLocation(point, function (rs) {
- var addComp = rs.addressComponents;
- $('.area').html('位置:' + addComp.province + ", " + addComp.city + ", " + addComp.district)
- });
- var opts = {
- width: 200, // 信息窗口宽度
- height: 150, // 信息窗口高度
- title: e.point.equip_type, // 信息窗口标题
- enableMessage: true//设置允许信息窗发送短息
- };
- var content = '<p>名称:' + e.point.equip_name + '</p><p class="gotoDetial" onclick="gotoManageDetial(\'' + e.point.equip_id + ' \',' + e.point.orgType + ')">IMEI:' + e.point.equip_id + '</p><p>经度:' + e.point.lng + '</p><p>纬度:' + e.point.lat + '</p><p class="area">位置:' + e.point.equip_location + '</p></br>';
- var infowindow = new BMap.InfoWindow(content, opts);
- map.openInfoWindow(infowindow, point);
- });
- map.addOverlay(pointCollection); // 添加Overlay
- // 让所有点在视野范围内
- map.setViewport(points);
- }
- function eachItem1(data_info) {
- var pointArray = [];
- for (var i = 0; i < data_info.length; i++) {
- if (data_info[i].lng > 999) {
- var lng = Math.floor(data_info[i].lng / 100) + ((data_info[i].lng % 100) / 60);
- var lat = Math.floor(data_info[i].lat / 100) + ((data_info[i].lat % 100) / 60);
- } else {
- var lat = data_info[i].lat;
- var lng = data_info[i].lng;
- }
- if (data_info[i].lat && data_info[i].lng) {
- //标注图标
- var orgType = data_info[i].equip_type;//parseInt(0) data_info[i].equip_type
- if (orgType == 5) {
- var equip_type = '环境监测';
- var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 1 * 23) });
- } else if (orgType == 2) {
- var equip_type = '杀虫灯';
- var myIcon = new BMap.Icon("/static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 2 * 23) });
- } else if (orgType == 3) {
- var equip_type = '虫情测报';
- var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -13), imageOffset: new BMap.Size(0, 0 - 3 * 23) });
- } else if (orgType == 4) {
- var equip_type = '性诱器设备';
- var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 6 * 23) });
- } else if (orgType == 6) {
- var equip_type = '监控设备';
- var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 5 * 23) });
- } else if (orgType == 7) {
- var equip_type = '孢子仪设备';
- var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 0 * 23) });
- } else if (orgType == 8) {
- var equip_type = '农药残留';
- var myIcon = new BMap.Icon("static/img/locationIcon2.png", new BMap.Size(17, 23), { offset: new BMap.Size(0, -18), imageOffset: new BMap.Size(0, 0 - 4 * 23) });
- }
- var lng1 = wgs84togcj02(lng, lat);
- var lng2 = gcj02tobd09(lng1[0], lng1[1]);
- // pointArray[i] = new BMap.Point(lng2[0], lng2[1]);
- pointArray.push(new BMap.Point(lng2[0], lng2[1]))
- var marker = new BMap.Marker(new BMap.Point(lng2[0], lng2[1]), { icon: myIcon }); // 创建标注
- map.addOverlay(marker);
- var enterNum = equip_type;//data_info[i].equip_name
- var content = '<p>名称:' + data_info[i].equip_name + '</p><p class="gotoDetial" onclick="gotoManageDetial(\'' + data_info[i].equip_id + ' \',' + orgType + ')">IMEI:' + data_info[i].equip_id + '</p><p>经度:' + lng2[0] + '</p><p>纬度:' + lng2[1] + '</p><p class="area">位置:' + data_info[i].equip_location + '</p></br>';
- if (data_info[i].equip_location) {
- var flag = true;
- } else {
- var flag = false;
- }
- // 将标注添加到地图中
- addClickHandler(content, marker, enterNum, flag);
- }
- }
- //让所有点在视野范围内
- map.setViewport(pointArray);
- }
- function addClickHandler(content, marker, enterNum, flag) {
- marker.addEventListener("click", function (e) {
- if (!flag) {
- var pt = marker.point;
- geoc.getLocation(pt, function (rs) {
- var addComp = rs.addressComponents;
- $('.area').html('位置:' + addComp.province + ", " + addComp.city + ", " + addComp.district)
- // alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
- });
- }
- openInfo(content, e, enterNum)
- }
- );
- }
- function openInfo(content, event, orgname) {
- var p = event.target;
- var opts = {
- title: orgname, // 信息窗口标题
- enableMessage: true//设置允许信息窗发送短息
- };
- var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
- var infoWindow = new BMap.InfoWindow(content, opts); // 创建信息窗口对象
- map.openInfoWindow(infoWindow, point); //开启信息窗口
- }
- // 查询相对类型的数据
- $('#selectType').on('click', 'span', function () {
- var dtype = $(this).data('type');
- if (dtype == 2 || dtype == 3 || dtype == 5 || dtype == 7 || dtype == 8) {
- if (dtype == 2) { dtype = "scd" }
- else if (dtype == 3) { dtype = "cbd" }
- else if (dtype == 5) { dtype = "qxz" }
- else if (dtype == 7) { dtype = "bzy" }
- else if (dtype == 8) { dtype = "xyq" }
- map.clearOverlays();//清除全部
- $.ajax({
- type: "post",
- url: "home_map/map_locat",
- data: { req: dtype },
- dataType: "json",
- success: function (data) {
- map.clearOverlays();//清除全部
- eachItem(data)
- }
- });
- } else if (dtype == 0) {
- map.clearOverlays();//清除全部
- $.ajax({
- type: "post",
- url: "home_map/map_locat",
- data: {
- req: "cbd",
- },
- dataType: "json",
- success: function (data) {
- eachItem(data)
- }
- });
- $.ajax({
- type: "post",
- url: "home_map/map_locat",
- data: {
- req: "scd",
- },
- dataType: "json",
- success: function (data) {
- eachItem(data)
- }
- });
- $.ajax({
- type: "post",
- url: "home_map/map_locat",
- data: {
- req: "qxz",
- },
- dataType: "json",
- success: function (data) {
- eachItem(data)
- }
- });
- $.ajax({
- type: "post",
- url: "home_map/map_locat",
- data: {
- req: "bzy",
- },
- dataType: "json",
- success: function (data) {
- eachItem(data)
- }
- });
- $.ajax({
- type: "post",
- url: "home_map/map_locat",
- data: {
- req: "xyq",
- },
- dataType: "json",
- success: function (data) {
- eachItem(data)
- }
- });
- } else {
- // layer.msg("此功能暂未开启!", { time: 2000 });
- }
- })
- //搜索城市
- $('#searchCityBtn').on('click', searchCity);
- $('#searchCity').on('keyup', function (event) {
- if (event.keyCode == 13) {
- searchCity();
- }
- })
- function searchCity() {
- var local = new BMap.LocalSearch(map, {
- renderOptions: { map: map, panel: "r-result" },
- pageCapacity: 5
- });
- local.search($('#searchCity').val());
- }
- //搜索imei
- $('#searchBtn').on('click', searchImei);
- $('#searchImei').on('keyup', function (event) {
- if (event.keyCode == 13) {
- searchImei();
- }
- })
- function searchImei() {
- var imei = $('#searchImei').val();
- if (imei != '') {
- $.ajax({
- type: "post",
- url: "home_map/map_locat",
- data: {
- req: "imei",
- equip_id: imei
- },
- dataType: "json",
- success: function (data) {
- if (data == '0') {
- layer.msg("没有找到该设备,请核对设备id!", { time: 2000 });
- map.clearOverlays();//清除全部
- }
- else {
- map.clearOverlays();//清除全部
- eachItem(data)
- }
- }
- });
- } else {
- layer.msg("请输入imei!", { time: 2000 });
- }
- }
- var as = [{ "equip_id": "11111111", "equip_type": 3, "equip_name": "", "lng": "113.66080475001185", "lat": "34.81039429", "equip_location": "" }]
- function gotoManageDetial(imei, orgType) {
- var sidebar = $('#sidebar', parent.document);
- var menuLi = sidebar.find('.nav-list.nav').children();
- if (orgType == 3 || orgType == 2) {
- menuLi.each(function (idx, val) {
- $(val).removeClass('active');
- if ($(val).children('a').find('.menu-text').html() == '报表管理') {
- $(val).addClass('active');
- $(val).addClass('open');
- $(val).children('ul').removeClass('nav-hide').addClass('nav-show').show();
- if (orgType == 3) {
- $(val).children('ul').children().each(function (index, obj) {
- if ($(obj).find('.menu-text').html() == '虫情测报') {
- $(obj).addClass('active');
- }
- })
- } else if (orgType == 2) {
- $(val).children('ul').children().each(function (index, obj) {
- if ($(obj).find('.menu-text').html() == '杀虫灯') {
- $(obj).addClass('active');
- }
- })
- }
- }
- })
- }
- if (orgType == 3) {
- location.href = 'cbd_report_detail?id=' + imei;
- } else if (orgType == 2) {
- location.href = 'scd_report_detail?id=' + imei;
- }
- }
|