qq.maps.Polyline 类
继承自MVCObject
类
折线覆盖物。
构造函数
构造函数 |
---|
Polyline(options:PolylineOptions)
|
方法
方法 | 返回值 | 说明 |
---|---|---|
getBounds()
|
LatLngBounds
|
返回折线的地理区域范围。 |
getMap()
|
Map
|
获取折线所在的map对象 |
getPath()
|
MVCArray.<LatLng>
|
获取折线的经纬度坐标数组。 |
getStrokeColor()
|
Color
|
获取折线的颜色。 |
getStrokeWeight()
|
Number
|
获取折线的宽度。 |
getStrokeLinecap()
|
String
|
获取折线末端线帽的样式。 |
getVisible()
|
Boolean
|
获取折线的可见性。 |
getZIndex()
|
Number
|
获取折线的zIndex值。 |
setMap(map:Map)
|
none
|
设置折线所在的map对象 |
setPath(path:Array.<LatLng> | MVCArray.<LatLng>)
|
none
|
设置折线的路径。 |
setStrokeColor(color:Color)
|
none
|
设置折线的颜色(包括透明度)。 |
setStrokeWeight(width:Number)
|
none
|
设置折线的宽度。 |
setStrokeLinecap(linecap:String)
|
none
|
设置折线末端线帽的样式,圆形为round(默认),方形为square,平直为butt。 |
setVisible(visible:Boolean)
|
none
|
设置折线的可见性。 |
setZIndex(zIndex:Number)
|
none
|
设置折线的zIndex。 |
setOptions(options:PolylineOptions)
|
none
|
事件
事件名 | 参数 | 说明 |
---|---|---|
map_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
|
鼠标在折线上移动时触发此事件。 |
insertNode
|
event:MouseEvent
|
添加折线节点时触发此事件。 |
removeNode
|
event:MouseEvent
|
删除折线节点时触发此事件。 |
adjustNode
|
event:MouseEvent
|
移动折线节点时触发此事件。 |
实例
例子 1:
本示例中,介绍如何设置线条颜色及透明度
var map = new qq.maps.Map(document.getElementById("container"), { // 地图的中心地理坐标。 center: new qq.maps.LatLng(39.916527, 116.397128), zoom: 14 }); var path = [ new qq.maps.LatLng(39.910, 116.399), new qq.maps.LatLng(39.920, 116.405), new qq.maps.LatLng(39.930, 116.420) ]; var polyline = new qq.maps.Polyline({ map: map, path: path, strokeColor: new qq.maps.Color(0, 0, 0, 0.5) });
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>腾讯地图-简单地图示例</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77"></script> <style type="text/css"> html, body { height: 100%; margin: 0px; padding: 0px } #container { width: 100%; height: 100% } </style> </head> <body> <div id="container"></div> <script type="text/javascript"> var map = new qq.maps.Map(document.getElementById("container"), { // 地图的中心地理坐标。 center: new qq.maps.LatLng(39.916527, 116.397128), zoom: 14 }); var path = [ new qq.maps.LatLng(39.910, 116.399), new qq.maps.LatLng(39.920, 116.405), new qq.maps.LatLng(39.930, 116.420) ]; var polyline = new qq.maps.Polyline({ map: map, path: path, strokeColor: new qq.maps.Color(0, 0, 0, 0.5) }); </script> </body> </html>
例子 2:
本示例中,介绍如何开启编辑功能
var map = new qq.maps.Map(document.getElementById("container"), { // 地图的中心地理坐标。 center: new qq.maps.LatLng(39.916527, 116.397128), zoom: 14 }); var path = [ new qq.maps.LatLng(39.910, 116.399), new qq.maps.LatLng(39.920, 116.405), new qq.maps.LatLng(39.930, 116.420) ]; var polyline = new qq.maps.Polyline({ map: map, path: path, editable: true });
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>腾讯地图-简单地图示例</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77"></script> <style type="text/css"> html, body { height: 100%; margin: 0px; padding: 0px } #container { width: 100%; height: 100% } </style> </head> <body> <div id="container"></div> <script type="text/javascript"> var map = new qq.maps.Map(document.getElementById("container"), { // 地图的中心地理坐标。 center: new qq.maps.LatLng(39.916527, 116.397128), zoom: 14 }); var path = [ new qq.maps.LatLng(39.910, 116.399), new qq.maps.LatLng(39.920, 116.405), new qq.maps.LatLng(39.930, 116.420) ]; var polyline = new qq.maps.Polyline({ map: map, path: path, editable: true }); </script> </body> </html>
例子 3:
本示例中,介绍如何使用折线覆盖物的方法
var init = function() { var center = new qq.maps.LatLng(39.916527, 116.397128); var map = new qq.maps.Map(document.getElementById('container'), { center: center, zoom: 13 }); var path1 = [ new qq.maps.LatLng(39.910, 116.399), new qq.maps.LatLng(39.920, 116.405), new qq.maps.LatLng(39.930, 116.420) ]; var path2 = [ new qq.maps.LatLng(39.930456, 116.387554), new qq.maps.LatLng(39.929008, 116.414162), new qq.maps.LatLng(39.909786, 116.379314), new qq.maps.LatLng(39.908206, 116.416908) ]; var polyline = new qq.maps.Polyline({ path: path1, strokeColor: '#000000', strokeWeight: 5, editable: false, map: map }); //setMap()设置折线覆盖物所在地图 var mapM = document.getElementById("mapM"); qq.maps.event.addDomListener(mapM, "click", function() { polyline.setVisible(true); if (polyline.getMap()) { polyline.setMap(null); } else { polyline.setMap(map); } }); //setCursor()设置鼠标经过折线时的样式 var curF = true; var cursor = document.getElementById("cursor"); qq.maps.event.addDomListener(cursor, "click", function() { polyline.setMap(map); polyline.setVisible(true); if (curF) { curF = false; polyline.setCursor("default"); } else { curF = true; polyline.setCursor("pointer"); } }); //setPath()设置折线路径 var pathF = true; var path = document.getElementById("path"); qq.maps.event.addDomListener(path, "click", function() { polyline.setMap(map); polyline.setVisible(true); if (pathF) { pathF = false; polyline.setPath(path2); } else { pathF = true; polyline.setPath(path1); } }); //setStrokeColor()设置折线的颜色 var strokeF = true; var strokeC = document.getElementById("strokeC"); qq.maps.event.addDomListener(strokeC, "click", function() { polyline.setMap(map); polyline.setVisible(true); if (strokeF) { strokeF = false; //设置折线的颜色和透明度 polyline.setStrokeColor(new qq.maps.Color(0, 0, 0, 0.5)); } else { strokeF = true; polyline.setStrokeColor("#1c29d8"); } }); //setStrokeDashStyle()设置折线的样式 var dashF = true; var dash = document.getElementById("dash"); qq.maps.event.addDomListener(dash, "click", function() { polyline.setMap(map); polyline.setVisible(true); if (dashF) { dashF = false; polyline.setStrokeDashStyle("dash"); } else { dashF = true; polyline.setStrokeDashStyle("solid"); } }); //setStrokeWeight()设置折线的宽度 var strokeWeightF = true; var strokeWeight = document.getElementById("strokeWeight"); qq.maps.event.addDomListener(strokeWeight, "click", function() { polyline.setMap(map); polyline.setVisible(true); if (strokeWeightF) { strokeWeightF = false; polyline.setStrokeWeight(10); } else { strokeWeightF = true; polyline.setStrokeWeight(5); } }); //setVisible()设置折线的可见性 var visibleF = true; var visibleT = document.getElementById("visibleT"); qq.maps.event.addDomListener(visibleT, "click", function() { polyline.setMap(map); if (visibleF) { visibleF = false; polyline.setVisible(false); } else { visibleF = true; polyline.setVisible(true); } }); };
<!DOCTYPE html> <html> <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: 142px; } </style> <script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77"></script> <script> var init = function() { var center = new qq.maps.LatLng(39.916527, 116.397128); var map = new qq.maps.Map(document.getElementById('container'), { center: center, zoom: 13 }); var path1 = [ new qq.maps.LatLng(39.910, 116.399), new qq.maps.LatLng(39.920, 116.405), new qq.maps.LatLng(39.930, 116.420) ]; var path2 = [ new qq.maps.LatLng(39.930456, 116.387554), new qq.maps.LatLng(39.929008, 116.414162), new qq.maps.LatLng(39.909786, 116.379314), new qq.maps.LatLng(39.908206, 116.416908) ]; var polyline = new qq.maps.Polyline({ path: path1, strokeColor: '#000000', strokeWeight: 5, editable: false, map: map }); //setMap()设置折线覆盖物所在地图 var mapM = document.getElementById("mapM"); qq.maps.event.addDomListener(mapM, "click", function() { polyline.setVisible(true); if (polyline.getMap()) { polyline.setMap(null); } else { polyline.setMap(map); } }); //setCursor()设置鼠标经过折线时的样式 var curF = true; var cursor = document.getElementById("cursor"); qq.maps.event.addDomListener(cursor, "click", function() { polyline.setMap(map); polyline.setVisible(true); if (curF) { curF = false; polyline.setCursor("default"); } else { curF = true; polyline.setCursor("pointer"); } }); //setPath()设置折线路径 var pathF = true; var path = document.getElementById("path"); qq.maps.event.addDomListener(path, "click", function() { polyline.setMap(map); polyline.setVisible(true); if (pathF) { pathF = false; polyline.setPath(path2); } else { pathF = true; polyline.setPath(path1); } }); //setStrokeColor()设置折线的颜色 var strokeF = true; var strokeC = document.getElementById("strokeC"); qq.maps.event.addDomListener(strokeC, "click", function() { polyline.setMap(map); polyline.setVisible(true); if (strokeF) { strokeF = false; //设置折线的颜色和透明度 polyline.setStrokeColor(new qq.maps.Color(0, 0, 0, 0.5)); } else { strokeF = true; polyline.setStrokeColor("#1c29d8"); } }); //setStrokeDashStyle()设置折线的样式 var dashF = true; var dash = document.getElementById("dash"); qq.maps.event.addDomListener(dash, "click", function() { polyline.setMap(map); polyline.setVisible(true); if (dashF) { dashF = false; polyline.setStrokeDashStyle("dash"); } else { dashF = true; polyline.setStrokeDashStyle("solid"); } }); //setStrokeWeight()设置折线的宽度 var strokeWeightF = true; var strokeWeight = document.getElementById("strokeWeight"); qq.maps.event.addDomListener(strokeWeight, "click", function() { polyline.setMap(map); polyline.setVisible(true); if (strokeWeightF) { strokeWeightF = false; polyline.setStrokeWeight(10); } else { strokeWeightF = true; polyline.setStrokeWeight(5); } }); //setVisible()设置折线的可见性 var visibleF = true; var visibleT = document.getElementById("visibleT"); qq.maps.event.addDomListener(visibleT, "click", function() { polyline.setMap(map); if (visibleF) { visibleF = false; polyline.setVisible(false); } else { visibleF = true; polyline.setVisible(true); } }); }; </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="path" class="btn">setPath</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>