forked from marsprj/Map5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_set_center.html
66 lines (54 loc) · 2.07 KB
/
map_set_center.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../lib/css/Map5.min.css">
<script type="text/javascript" src="../lib/Map5.min.js"></script>
<style type="text/css">
body{
margin: 0px;
}
</style>
<script type="text/javascript">
// 地图变量
var mapObj = null;
function init(){
// 1、设置地图的范围
var extent = new GeoBeans.Envelope(-180,-90,180,90);
// 2、初始化地图变量,参数分别为:
// 地图的容器为"mapDiv",地图名称"map",地图范围,地图的空间参考,4326为经纬度
mapObj = new GeoBeans.Map("mapDiv","map",extent,4326);
if(mapObj == null){
return;
}
// 3、添加一个图层
// 定义一个QuadServer图层,作为底图,第一个参数为图层名称,第二个参数为QuadServer地址
var layer = new GeoBeans.Layer.QSLayer("base","/QuadServer/maprequest?services=world_vector");
// 添加图层
mapObj.addLayer(layer);
// 4、设置中心点和显示级别
var zoom = 2;
var center = new GeoBeans.Geometry.Point(0,0);
var viewer = mapObj.getViewer();
viewer.setZoomCenter(zoom,center);
}
function setCenter(){
// 1、定义一个点
var center = new GeoBeans.Geometry.Point(100,29);
// 2、设置中心点
mapObj.getViewer().setCenter(center);
}
function getCenter(){
// 返回中心点
var center = mapObj.getCenter();
alert("当前地图的中心点是:" + center.x + "," + center.y);
}
</script>
<title>Map5 -- 地图级别</title>
<body onload="init()">
<!-- mapDiv 为初始化地图的容器,给定高度和宽度,并指定定位方式为绝对定位 -->
<div id="mapDiv" style="height:800px;width:100%;position:absolute;top:30px;">
</div>
<button onclick="getCenter()">显示中心点</button>
<button onclick="setCenter()">设置中心点</button>
</body>