xzqy.js 6.04 KB
$(function () {

    var province = undefined
    var city = undefined
    // 办事大厅
    var halloffice = '不夜城'
    $('.area_list li').click(function () {
        $(".area_list li").removeClass("active1")
        $(this).addClass("active1");

    })

    $(".single_input").on("click", function () {
        var par_label = $(this).parent();
        if (this.checked) {
            $(".input_label").removeClass("choose_radioed").addClass("choose_radio");
            par_label.removeClass("choose_radio").addClass("choose_radioed");
        } else {
        }
    });

    layui.use('element', function () {
        let element = layui.element; //导航的hover效果、二级菜单等功能,需要依赖element模块
        //监听导航点击
        element.on('nav(demo)', function (elem) {
            //console.log(elem)
            layer.msg(elem.text());
        });
    });
    //config的设置是全局的
    layui.config({
        base: './js/'
    }).extend({ //设定模块别名
        common: 'common'
    });

    layui.use(['form', 'common'], function () {
        var common = layui.common,
            form = layui.form;
        //三级地址联动
        common.showCity('province', 'city');
        //区域选择
        form.on('select(selectCity)', function (data) {
            return false;
        });
    });
    var map = new BMap.Map('container');
    var point = new BMap.Point(108.95346, 34.265725);
    map.centerAndZoom(point, 14);
    var geolocation = new BMap.Geolocation();
    var gc = new BMap.Geocoder();
    geolocation.getCurrentPosition(function (r) {
        if (this.getStatus() == BMAP_STATUS_SUCCESS) {
            var pt = r.point;
            gc.getLocation(pt, function (rs) {
                var addComp = rs.addressComponents;
                province = addComp.province;
                city = addComp.city;
                var cityName = province;
                map.centerAndZoom(cityName, 14);                     // 初始化地图,设置中心点坐标和地图级别。    map.addControl(new BMap.ScaleControl());                    // 添加比例尺控件
                map.addControl(new BMap.OverviewMapControl());              //添加缩略地图控件
                map.enableScrollWheelZoom();
                map.addControl(new BMap.NavigationControl({ type: BMAP_NAVIGATION_CONTROL_LARGE, anchor: BMAP_ANCHOR_TOP_LEFT, offset: new BMap.Size(40, 250) }));
                var bdary = new BMap.Boundary();
                bdary.get(cityName, function (rs) {       //获取行政区域       
                    var EN_JW = "180, 90;";         //东北角
                    var NW_JW = "-180,  90;";       //西北角
                    var WS_JW = "-180, -90;";       //西南角
                    var SE_JW = "180, -90;";        //东南角
                    //4.添加环形遮罩层
                    var ply1 = new BMap.Polygon(rs.boundaries[0] + SE_JW + SE_JW + WS_JW + NW_JW + EN_JW + SE_JW, { strokeColor: "none", fillColor: "rgb(246,246,246)", fillOpacity: 1, strokeOpacity: 0.5 }); //建立多边形覆盖物
                    map.addOverlay(ply1);
                    //5. 给目标行政区划添加边框,其实就是给目标行政区划添加一个没有填充物的遮罩层
                    var ply = new BMap.Polygon(rs.boundaries[0], { strokeWeight: 2, strokeColor: "#0091FF", fillColor: "" });
                    map.addOverlay(ply);
                    //map.setViewport(ply.getPath());    //调整视野
                });
                $('.Pselected').attr('data-area', province)
                $('.Cselected').attr('data-area', city)
                layui.use(['form', 'common'], function () {
                    var common = layui.common,
                        form = layui.form;
                    //三级地址联动
                    common.showCity('province', 'city');
                })
            })
        }
        else {
            alert("定位失败");
        }
    }, { enableHighAccuracy: true });

    // 办事大厅标记
    var marker = new BMap.Marker(new BMap.Point(108.95346, 34.265725));
    var marker1 = new BMap.Marker(new BMap.Point(108.953381, 34.256923));
    // 在地图上添加点标记
    map.addOverlay(marker);
    map.addOverlay(marker1);
    // 创建信息窗口
    var opts = {
        width: 200,
        height: 100,
        title: '办事大厅'
    };
    var infoWindow = new BMap.InfoWindow('西安市大唐不夜城', opts);
    var infoWindow1 = new BMap.InfoWindow('南门', opts);
    
    // 点标记添加点击事件
    marker.addEventListener('click', function () {
        $('.office_halls li').removeClass('hallActive')
        $('.office_halls li').eq(0).addClass('hallActive')
        point = new BMap.Point(108.95346, 34.265725);
        map.openInfoWindow(infoWindow, point); // 开启信息窗口
    });
    marker1.addEventListener('click', function () {
        $('.office_halls li').removeClass('hallActive')
        $('.office_halls li').eq(1).addClass('hallActive')
        point = new BMap.Point(108.953381, 34.256923);
        map.openInfoWindow(infoWindow1, point); // 开启信息窗口

        
    });
    // 办事大厅点亮
    $('.office_halls li').click(function () {
        $('.office_halls li').removeClass('hallActive')
        $(this).addClass('hallActive')
        var index = $(this).index();
        if (index == 1) {
            point = new BMap.Point(108.95346, 34.265725);
            map.openInfoWindow(infoWindow, point); // 开启信息窗口
        } else if (index == 2) {
            point = new BMap.Point(108.953381, 34.256923);
            map.openInfoWindow(infoWindow1, point);
        }
    })

    infoWindow.addEventListener('close', function (type, target, point) {
        $('.office_halls li').eq(0).removeClass('hallActive')
    })
    infoWindow1.addEventListener('close', function (type, target, point) {
        $('.office_halls li').eq(1).removeClass('hallActive')
    })

    // 下一步
    $('.nextButton').click(function(){
        window.open("../yysj/index.html?halloffice="+halloffice+"","_self")
    })
})