高德舆图 Javascript API 入门(三)
间隔丈量插件
区分
虽然鼠标东西插件也供应间隔量测功用,
然则间隔量测插件,供应更加雄厚的款式设置功用。
加载插件
JS
map.plugin(["AMap.RangingTool"],function () {
var rangingTool=new AMap.RangingTool(map);
rangingTool.turnOn(); // 开启量测功用
});
预览
款式设置
RangingToolOptions | 范例 | 申明 |
---|---|---|
startMarkerOptions | Object | 设置量测起始点标记属性对象,包含点标记款式、大小等,参考 MarkerOptions 列表 |
midMarkerOptions | Object | 设置量测中心点标记属性对象,包含点标记款式、大小等,参考 MarkerOptions 列表 |
endMarkerOptions | Object | 设置量测完毕点标记属性对象,包含点标记款式、大小等,参考 MarkerOptions 列表 |
lineOptions | Object | 设置间隔量测线的属性对象,包含线款式、色彩等,参考 PolylineOptions 列表 |
tmpLineOptions | Object | 设置间隔量测过程当中暂时量测线的属性对象,包含线款式、色彩等,参考 PolylineOptions 列表 |
startLabelText | String | 设置量测起始点标签的笔墨内容,默以为“出发点” |
midLabelText | String | 设置量测中心点处标签的笔墨内容,默以为当前量测效果值 |
endLabelText | String | 设置量测完毕点处标签的笔墨内容,默以为当前量测效果值 |
startLabelOffset | Pixel | 设置量测起始点标签的偏移量。默认值:Pixel(-6, 6) |
midLabelOffset | Pixel | 设置量测中心点标签的偏移量。默认值:Pixel(-6, 6) |
endLabelOffset | Pixel | 设置量测完毕点标签的偏移量。默认值:Pixel(-6, 6) |
#### 示例 转变标签笔墨 JS
map.plugin(["AMap.RangingTool"],function () {
var rangingTool=new AMap.RangingTool(map,{
startLabelText:"START",
midLabelText:"MID",
endLabelText:"END"
});
rangingTool.turnOn();
});
预览
转变线条款式
JS
map.plugin(["AMap.RangingTool"],function () {
var rangingTool=new AMap.RangingTool(map,{
lineOptions:{
strokeColor:"#ff3300",
strokeStyle:"dashed",
strokeWeight:10,
strokeOpacity:0.5,
isOutline:true,
outlineColor:"#009933",
showDir:true
}
});
rangingTool.turnOn();
});
预览
小演习
绘制太原市区的也许局限
JS
// 用坐标拾取器取得坐标
var lineArr=[
[112.490931,37.898793],
[112.553588,37.898793],
[112.603026,37.899877],
[112.605086,37.855028],
[112.605601,37.831169],
[112.610236,37.824661],
[112.610236,37.798487],
[112.602683,37.793739],
[112.499171,37.793739],
[112.495051,37.794553],
[112.500544,37.830762],
[112.500716,37.843099],
[112.48973,37.847301],
[112.489901,37.896897],
[112.492476,37.8992]
];
// 实例化一个Polyline类
var polyline=new AMap.Polyline({
path:lineArr,
strokeColor:"#ff2200",
strokeWeight:5
});
// 添加到舆图中
polyline.setMap(map);
预览
参考泉源:http://lbs.amap.com/
作者:Yangfan