-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.html
126 lines (123 loc) · 5.43 KB
/
map.html
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
<!DOCTYPE html>
<html>
<title>来租客</title>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="description" content="来租客" />
<meta name="keywords" content="来租客" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="format-detection" content="telephone=no" />
<link rel="stylesheet" type="text/css" href="resource/zlzq/css/custom.css">
<script type="text/javascript" src="http://api.map.baidu.com/api?key=&v=1.4"></script>
<body>
<div id="map_canvas" ></div>
<script type="text/javascript">
var map,
locations=[
{location:[121.546540,31.228661],name:"浦东新区"},
{location:[121.408998,31.322503],name:"闸北区"},
{location:[121.454930,31.256835],name:"黄浦区"},
{location:[121.387522,31.119387],name:"闵行区"},
{location:[121.485627,31.290416],name:"虹口区"},
{location:[121.416350,31.194596],name:"徐汇区"},
{location:[121.512073,31.285725],name:"杨浦区"},
{location:[121.421358,31.255722],name:"静安区"},
{location:[121.384276,31.243252],name:"长宁区"},
{location:[121.366044,31.286959],name:"普陀区"},
{location:[121.234736,31.027085],name:"松江区"},
{location:[121.081233,31.218009],name:"青浦区"},
{location:[121.273379,31.380229],name:"嘉定区"},
{location:[121.481179,30.922957],name:"奉贤区"},
{location:[121.348327,30.747002],name:"金山区"},
{location:[121.488497,31.401586],name:"宝山区"},
{location:[121.436051,31.665070],name:"崇明县"}],
BPoint= new BMap.Point(121.51745,31.2084320000002),
polygon;
map = new BMap.Map("map_canvas");
// map.addControl(new BMap.NavigationControl()); // 添加平移缩放控件
// map.addControl(new BMap.ScaleControl()); // 添加比例尺控件
// map.addControl(new BMap.OverviewMapControl()); //添加缩略地图控件
map.enableScrollWheelZoom(); //启用滚轮放大缩小
//map.addControl(new BMap.MapTypeControl()); //添加地图类型控件
map.centerAndZoom(BPoint, 13);
map.addOverlay(polygon);
function myFun(result){
var cityName = result.name;
map.setCenter(cityName);
}
var myCity = new BMap.LocalCity();
myCity.get(myFun);
window.map=map;
function getLocation(name) {
for (var i = 0, len = locations.length; i < len; i++) {
if (locations[i].name == name) {
return locations[i];
}
}
}
function drawMap(data) {
for (var i = 0, len = data.district_counts.length; i < len; i++) {
var location = getLocation(data.district_counts[i].district);
var bp = new BMap.Point(location.location[0], location.location[1]),
opts = {
data:data.district_counts[i],
position: bp, // 指定文本标注所在的地理位置
offset: new BMap.Size(30, -30) //设置文本偏移量
};
var labelUp = new BMap.Label(data.district_counts[i].realty_count, opts); // 创建文本标注对象
labelUp.setStyle({
color: "#fff",
padding: "8px 5px 5px",
backgroundImage: "url(./resource/zlzq/images/label.png)",
backgroundColor: "transparent",
backgroundSize: "35px",
border: "none",
borderRadius: "3px",
fontSize: "10px",
height: "40px",
lineHeight: "20px",
backgroundPosition: "center",
width: "35px",
textAlign: "center",
fontFamily: "微软雅黑"
});
map.addOverlay(labelUp);
// labelUp.B.dataset.config=JSON.stringify(data.district_counts[i]);
labelUp.data=JSON.stringify(data.district_counts[i]);
var opts = {
data:data.district_counts[i],
position: bp, // 指定文本标注所在的地理位置
offset: new BMap.Size(30, 25) //设置文本偏移量
}
var labelDown = new BMap.Label(data.district_counts[i].district, opts); // 创建文本标注对象
labelDown.setStyle({
color: "#fff",
padding: "3px",
backgroundColor: "#e44691",
border: "none",
borderRadius: "3px",
fontSize: "10px",
height: "20px",
lineHeight: "20px",
backgroundPosition: "center",
width: "35px",
textAlign: "center",
fontFamily: "微软雅黑"
});
map.addOverlay(labelDown);
// labelDown.addEventListener("click", map.bridgeListener);
// labelDown.B.dataset.config=JSON.stringify(data.district_counts[i]);
labelDown.data=JSON.stringify(data.district_counts[i]);
labelDown.addEventListener("click", search);
labelUp.addEventListener("click", search);
}
}
function search(e){
var p = e.target,
// config=JSON.parse(p.B.dataset.config);
config=JSON.parse(p.data);
window.parent.Lizard.goTo("list.html?d=" + config.district_id);
}
</script>
</body>
</html>