xzqy.js
4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
$('.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) {
console.log(data)
return false;
});
//办事大厅
form.on('select(officehall)', function (data) {
let latitude = undefined
let longitude = undefined
let title = ''
if (data.value == 1) {
latitude = 116.397469
longitude = 39.908821
title = '北京'
} else if (data.value == 2) {
latitude = 121.491119
longitude = 31.235172
title = '上海'
} else {
latitude = 120.21201
longitude = 30.2084
title = '杭州'
}
var point = new BMapGL.Point(latitude, longitude);
var infoWindow = new BMapGL.InfoWindow(title, opts);
map.openInfoWindow(infoWindow, point);
return false;
});
});
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;
var province = addComp.province;
var city = addComp.city;
$('.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 map = new BMap.Map('container');
var point = new BMap.Point(108.95309828, 34.2777999);
map.centerAndZoom(point, 20);
var cityName = '陕西省';
map.centerAndZoom(cityName, 15); // 初始化地图,设置中心点坐标和地图级别。 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: "#00f", fillColor: "" });
map.addOverlay(ply);
//map.setViewport(ply.getPath()); //调整视野
});
var opts = {
width: 100,
height: 60,
title: '办事大厅'
};
var infoWindow = new BMap.InfoWindow('雁塔区南二环西段', opts);
map.openInfoWindow(infoWindow, point);
map.centerAndZoom(new BMap.Point(108.95309828, 34.2777999), 15); // 初始化地图,设置中心点坐标和地图级别
map.enableScrollWheelZoom(true); // 开启鼠标滚轮缩放