xzqy.js
8.13 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
layui.use('element', function () {
let element = layui.element; //导航的hover效果、二级菜单等功能,需要依赖element模块
});
$(function () {
$('.layui-breadcrumb a').eq(1).attr('href',GetQueryString('href'));
$('.layui-breadcrumb a').eq(1).attr('title', decodeURI(GetQueryString('title')));
$('.layui-breadcrumb a').eq(1).text(decodeURI(GetQueryString('title')));
// 初始化数据
_initData()
// 判断是否能选择办事大厅
var isSelectofficeHall;
var province = undefined
var city = undefined
// 办事大厅
var jgid = ''
$('.area_list li').click(function () {
$(".area_list li").removeClass("activeRegion")
$(this).addClass("activeRegion");
})
$(".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 {
}
});
//config的设置是全局的
layui.config({
base: '../staticJs/'
}).extend({ //设定模块别名
common: 'cityCommon'
});
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 });
// 点标记添加点击事件
// 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); // 开启信息窗口
// });
$(document).on("click", ".office_halls li", function (e) {
console.log()
$(".office_halls li").removeClass("active2");
isSelectofficeHall = true;
$('#nextButton').removeClass('layui-btn-disabled');
$(this).addClass("active2");
console.log($(this).attr('longitude'), $(this).attr('latitude'));
point = new BMap.Point($(this).attr('longitude'), $(this).attr('latitude'));
// 在地图上添加点标记
map.addOverlay(new BMap.Marker(new BMap.Point($(this).attr('longitude'), $(this).attr('latitude'))));
var point = new BMap.Point($(this).attr('longitude'), $(this).attr('latitude'));
map.centerAndZoom(point, 14);
var opts = {
width: 200,
height: 100,
title: '办事大厅'
};
var infoWindow = new BMap.InfoWindow($(this).text(), opts);
map.openInfoWindow(infoWindow, point); // 开启信息窗口
jgid = $(this).data('id')
})
$(document).on("click", ".area_list li", function (e) {
$(".area_list li").removeClass("active2")
$(this).addClass("active2");
if ($(this).index() >= 1) {
workdata($(this).index() - 1, data.workList)
} else if ($(this).index() == 0) {
workdata($(this).index() - 1, data.allList)
}
})
// 下一步
$('.nextButton').click(function () {
if (isSelectofficeHall) {
window.open("./yysj.html?jgid=" + jgid + "&title="+decodeURI(GetQueryString('title'))+ "&href="+GetQueryString('href'), "_self")
} else {
layer.msg('请先选择办事大厅');
}
})
})
function _initData() {
var area_list = $(".area_list");
area_list.empty();
var li;
$.ajax({
type: "get", //提交方式
url: portal.api_url + "/reserve/organization/queryAllOrganization?orgType=" + 1,//路径
dataType: "json",
//数据,这里使用的是Json格式进行传输
success: function (result) {//返回数据根据结果进行相应的处理
if (result.code == 200 && result.data != null) {
data.workList = result.data[0].children[0].children;
li = '<li data-id="0" class="active2">全部</li>';
area_list.append(li);
for (var i = 0; i < data.workList.length; i++) {
li = '<li data-id="' + data.workList[i].id + '">' + data.workList[i].name + '</li>';
area_list.append(li);
if (data.workList[i].children) {
data.allList = data.allList.concat(data.workList[i].children)
}
}
workdata(-1, data.allList)
}
}
});
}
// 点击区域获取办事大厅的方法
function workdata(index, workList) {
var office_halls = $('.office_halls')
office_halls.empty()
var li
if (index >= 0 && workList[index].children.length > 0) {
for (var i = 0; i < workList[index].children.length; i++) {
li = '<li data-id="' + workList[index].children[i].id + '" latitude="' + workList[index].children[i].latitude + '" longitude="' + workList[index].children[i].longitude + '" >' + workList[index].children[i].name + '</li>';
office_halls.append(li)
}
} else if (index == -1) {
for (var i = 0; i < workList.length; i++) {
li = '<li data-id="' + workList[i].id + '" latitude="' + workList[i].latitude + '" longitude="' + workList[i].longitude + '" >' + workList[i].name + '</li>';
office_halls.append(li)
}
}
}
var data = { //数据
"workList": [],
"allList": []
};