xzqy.js
4.72 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
$(function () {
var province = undefined
var city = undefined
$('.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 () {
map.openInfoWindow(infoWindow, point); // 开启信息窗口
});
marker1.addEventListener('click', function () {
map.openInfoWindow(infoWindow1, point); // 开启信息窗口
});
})