| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449 |
- /**
- * 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", { 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);
- var pointArray = [];
- window.onload = function () {
- var ele = $('#scdlist').children();
- var num = 0;
- var currjson = {};
- for(var i = 0;i<ele.length;i++){
- num++;
- if(num == 1){
- currjson.equip_id = $(ele[i]).html()
- }
- if(num == 2){
- currjson.lat = $(ele[i]).html()
- }
- if(num == 3){
- currjson.lng = $(ele[i]).html()
- }
- if(num>3){
- console.log(currjson.lng)
- console.log(currjson.lat)
- console.log(currjson.equip_id)
- addArea(currjson.lng,currjson.lat,2,"equip_name",currjson.equip_id,'')
- currjson = {}
- num = 0;
- }
- console.log($(ele[0]).html())
- console.log($(ele[i]).html())
- }
- //请求数据:
- // $.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 addArea(lng,lat,equip_type,equip_name,equip_id,equip_location){
- if (lng > 999) {
- var lng = Math.floor(lng / 100) + ((lng % 100) / 60);
- var lat = Math.floor(lat / 100) + ((lat % 100) / 60);
- } else {
- var lat = lat;
- var lng = lng;
- }
- alert(111)
- if (lat && lng) {
- //标注图标
- var orgType = 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>名称:' + equip_name + '</p><p class="gotoDetial" onclick="gotoManageDetial(\'' + equip_id + ' \',' + orgType + ')">IMEI:' + equip_id + '</p><p>经度:' + lng2[0] + '</p><p>纬度:' + lng2[1] + '</p><p class="area">位置:' + equip_location + '</p></br>';
- if (equip_location) {
- var flag = true;
- } else {
- var flag = false;
- }
- // 将标注添加到地图中
- addClickHandler(content, marker, enterNum, flag);
- }
- }
- function eachItem(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();
- 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;
- }
- }
|