forked from liaotuo/bmap-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pointInCircle.html
88 lines (78 loc) · 3.06 KB
/
pointInCircle.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
<!--
liaotuo
2016.09.25
判断点是否在圆形区域内(用于电子围栏)
-->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=百度地图API开发者密钥AK"></script>
<script type="text/javascript" src="js/GeoUtils.js"></script>
<title>圆形区域判断</title>
</head>
<body>
<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
//创建地图
var map = new BMap.Map("allmap");
//创建一个圆
var circle = new BMap.Circle(new BMap.Point(112.595384,26.904631),1000,{fillColor:"blue", strokeWeight: 1 ,fillOpacity: 0.3, strokeOpacity: 0.3});
var point2s = [
new BMap.Point(112.586149,26.913201),
new BMap.Point(112.58464,26.909432),
new BMap.Point(112.585143,26.899219),
new BMap.Point(112.600953,26.898832),
new BMap.Point(112.607421,26.900572),
new BMap.Point(112.606631,26.904825),
new BMap.Point(112.606523,26.909142),
new BMap.Point(112.59772,26.909399),
];
//创建标注点并添加到地图中
function addMarker(points) {
//循环建立标注点
for(var i=0, pointsLen = points.length; i<pointsLen; i++) {
var marker = new BMap.Marker(points[i]); //将点转化成标注点
map.addOverlay(marker); //将标注点添加到地图上
//添加监听事件
(function() {
var thePoint = points[i];
marker.addEventListener("click",
function() {
showInfo(this,thePoint);
});
})();
}
}
function showInfo(thisMarker,point) {
//判断点是否在
if(BMapLib.GeoUtils.isPointInCircle(point,circle)){
var infoWindow = new BMap.InfoWindow("在圆形区域内");
thisMarker.openInfoWindow(infoWindow); //图片加载完后重绘infoWindow
}else
{
var infoWindow = new BMap.InfoWindow("不在圆形区域内");
thisMarker.openInfoWindow(infoWindow); //图片加载完后重绘infoWindow
}
}
function initialize() {
alert("点击标注点可以显示是否在区域内");
// 百度地图API功能
map.addControl(new BMap.NavigationControl()); // 添加平移缩放控件
map.addControl(new BMap.ScaleControl()); // 添加比例尺控件
map.addControl(new BMap.OverviewMapControl()); //添加缩略地图控件
map.enableScrollWheelZoom(); //启用滚轮放大缩小
map.addControl(new BMap.MapTypeControl()); //添加地图类型控件
var point = new BMap.Point(112.595384,26.904631); // 创建点坐标
map.centerAndZoom(point,15); // 初始化地图,设置中心点坐标和地图级别。
addMarker(point2s);
map.addOverlay(circle);
}
initialize();
</script>