qq.maps.Circle 类
继承自MVCObject类
圆形覆盖物。
构造函数
方法
| 方法 |
返回值 |
说明 |
| getBounds() |
LatLngBounds |
返回圆形的地理区域范围。 |
| getCenter() |
LatLng |
返回圆形的中心点坐标。 |
| getMap() |
Map |
返回圆形所在的map对象。 |
| getRadius() |
Number |
返回圆形半径。 |
| getVisible() |
Boolean |
获取圆形的可见性。 |
| getZIndex() |
Number |
获取圆形的zIndex值。 |
| setCenter(center:LatLng) |
none |
设置圆心坐标。 |
| setMap(map:Map) |
none |
设置圆形所在的map对象。 |
| setRadius(radius:Number) |
none |
设置圆形半径。 |
| setVisible(visible:Boolean) |
none |
设置圆形覆盖物的可见性。 |
| setZIndex(zIndex:Number) |
none |
设置圆形覆盖物的zIndex。 |
| setOptions(options:CircleOptions) |
none |
设置圆形参数。 |
事件
| 事件名 |
参数 |
说明 |
| center_changed |
none |
当此圆形中心点更改时会触发此事件。 |
| map_changed |
none |
当此圆形覆盖物所在地图更改时会触发此事件。 |
| radius_changed |
none |
当此圆形半径更改时会触发此事件。 |
| visible_changed |
none |
当此圆形可见性更改时会触发此事件。 |
| zindex_changed |
none |
当此圆形zIndex更改时会触发此事件。 |
| click |
event:MouseEvent |
点击圆形后会触发此事件。 |
| dblclick |
event:MouseEvent |
双击圆形后会触发此事件。 |
| rightclick |
event:MouseEvent |
右键点击圆形后会触发此事件。 |
| mousedown |
event:MouseEvent |
鼠标在圆形内按下触发此事件。 |
| mouseup |
event:MouseEvent |
鼠标在圆形上抬起时触发此事件。 |
| mouseover |
event:MouseEvent |
当鼠标进入圆形区域时会触发此事件。 |
| mouseout |
event:MouseEvent |
鼠标离开圆形时触发此事件。 |
| mousemove |
event:MouseEvent |
鼠标在圆形内移动时触发此事件。 |
实例
本示例中,介绍如何使用圆形覆盖物的方法
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>向地图上添加一个圆</title>
<style type="text/css">
* {
margin: 0px;
padding: 0px;
}
body,
button,
input,
select,
textarea {
font: 12px/16px Verdana, Helvetica, Arial, sans-serif;
}
#info {
width: 603px;
padding-top: 3px;
overflow: hidden;
}
.btn {
width: 190px;
}
</style>
<script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77"></script>
<script>
function init() {
var center = new qq.maps.LatLng(39.982163, 116.306070);
var center2 = new qq.maps.LatLng(39.98555, 116.3);
var map = new qq.maps.Map(document.getElementById("container"), {
center: center,
zoom: 14
});
var circle = new qq.maps.Circle({
map: map,
center: center,
radius: 1000,
fillColor: "#00f",
strokeWeight: 5
});
//setMap()设置圆形覆盖物所在地图
var mapM = document.getElementById("mapM");
qq.maps.event.addDomListener(mapM, "click", function() {
circle.setVisible(true);
if (circle.getMap()) {
circle.setMap(null);
} else {
circle.setMap(map);
}
});
//setCursor()设置鼠标经过圆形覆盖物的样式
var curF = true;
var cursor = document.getElementById("cursor");
qq.maps.event.addDomListener(cursor, "click", function() {
circle.setMap(map);
circle.setVisible(true);
if (curF) {
curF = false;
circle.setCursor("default");
} else {
curF = true;
circle.setCursor("pointer");
}
});
//setFillColor()设置圆形覆盖物的填充颜色
var fillCF = true;
var fillC = document.getElementById("fillC");
qq.maps.event.addDomListener(fillC, "click", function() {
circle.setMap(map);
circle.setVisible(true);
if (fillCF) {
fillCF = false;
circle.setFillColor("#0f0");
} else {
fillCF = true;
circle.setFillColor("#111");
}
});
//setCenter()设置圆形覆盖物圆心
var centerF = true;
var centerC = document.getElementById("centerC");
qq.maps.event.addDomListener(centerC, "click", function() {
circle.setMap(map);
circle.setVisible(true);
if (centerF) {
centerF = false;
circle.setCenter(center2);
} else {
centerF = true;
circle.setCenter(center);
}
});
//setRadius()设置圆形覆盖物的半径
var pathF = true;
var path = document.getElementById("path");
qq.maps.event.addDomListener(path, "click", function() {
circle.setMap(map);
circle.setVisible(true);
if (pathF) {
pathF = false;
circle.setRadius(500);
} else {
pathF = true;
circle.setRadius(1000);
}
});
//setStrokeColor()设置圆形覆盖物边线颜色
var strokeCF = true;
var strokeC = document.getElementById("strokeC");
qq.maps.event.addDomListener(strokeC, "click", function() {
circle.setMap(map);
circle.setVisible(true);
if (strokeCF) {
strokeCF = false;
circle.setStrokeColor("#1c29d8");
} else {
strokeCF = true;
circle.setStrokeColor("#000");
}
});
//setStrokeDashStyle()设置圆形覆盖物的边线样式
var dashF = true;
var dash = document.getElementById("dash");
qq.maps.event.addDomListener(dash, "click", function() {
circle.setMap(map);
circle.setVisible(true);
if (dashF) {
dashF = false;
circle.setStrokeDashStyle("dash");
} else {
dashF = true;
circle.setStrokeDashStyle("solid");
}
});
//setStrokeWeight()设置圆形覆盖物的边线宽度
var strokeWeightF = true;
var strokeWeight = document.getElementById("strokeWeight");
qq.maps.event.addDomListener(strokeWeight, "click", function() {
circle.setMap(map);
circle.setVisible(true);
if (strokeWeightF) {
strokeWeightF = false;
circle.setStrokeWeight(10);
} else {
strokeWeightF = true;
circle.setStrokeWeight(5);
}
});
//setVisible()设置圆形覆盖物的可见性
var visibleTF = true;
var visibleT = document.getElementById("visibleT");
qq.maps.event.addDomListener(visibleT, "click", function() {
circle.setMap(map);
if (visibleTF) {
visibleTF = false;
circle.setVisible(false);
} else {
visibleTF = true;
circle.setVisible(true);
}
});
}
window.onload = init;
</script>
</head>
<body onload="init()">
<div style="width:603px;height:300px" id="container"></div>
<div id="info">
<button id="mapM" class="btn">setMap</button>
<button id="cursor" class="btn">setCursor</button>
<button id="centerC" class="btn">setCenter</button>
<button id="fillC" class="btn">setFillColor</button>
<button id="path" class="btn">setRadius</button>
<button id="strokeC" class="btn">setStrokeColor</button>
<button id="dash" class="btn">setStrokeDashStyle</button>
<button id="strokeWeight" class="btn">setStrokeWeight</button>
<button id="visibleT" class="btn">setVisible</button>
</div>
</body>
</html>
在线试一试