# 路线
# (一)概述
路线数据包括路线要素[LineFeature]、路线集合[LineSet]两个数据类。
路线要素[LineFeature]是一种地图数据,可用来记录地图上的任意的路线。例如跑步路线,巡逻路线,行车路线...等等。如下图,一个路线要素对象可以表示一整条跑步路线:

路线集合[LineSet]用来分类存放、管理路线要素[LineFeature]。
# (二)路线集合[LineSet]
所有的路线数据,都存放在不同的路线集合之下。想要对路线进行操作,需要先获取路线集合。 路线集合[LineSet]的常用属性如下:
属性名 | 值类型 | 属性描述 |
---|---|---|
name | String | 路线集合名称 |
remark | String | 备注 |
symbol | PolylineSymbol | 线符号 |
常用方法如下:
方法名 | 返回类型 | 方法描述 |
---|---|---|
queryLines | Promise< QueryResult > | 查询集合下的所有路线要素 |
createLine | Promise< LineFeature > | 创建路线 |
updateLine | Promise< void > | 更新路线信息 |
deleteLine | Promise< void > | 删除路线 |
# 1、获取路线集合
初始化成功后,可直接从Cellsys的organization对象中获取到组织下所有的路线集合。具体代码示例如下:
/*执行初始化成功后,可直接获取到路线集合*/
let lineSets = Cellsys.organization.lineSets;//lineSets可能为null
if (lineSets != null && lineSets.length > 0) {
let lineSet = lineSets[0];
let name = lineSet.name;//集合名称
let remark = lineSet.remark;//集合备注信息
let polylineSymbol = lineSet.symbol;//获取地图符号对象
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# (1)线符号[PolylineSymbol]
线符号决定了路线要素在地图上的具体参数,如:线颜色、线透明度、线宽度等。具体参数获取示例如下:
let color = polylineSymbol.fillColor;//路线填充颜色
let colorValue = color.value;//返回一个带#号的色值:如#3c3c3c
let width = polylineSymbol.width;//路线宽度,单位px
let alpha = polylineSymbol.alpha;//不透明度。取值范围0~1,1为不透明
1
2
3
4
2
3
4
有关线符号[PolylineSymbol]的详细介绍,可查看附-样式
# 2、新增路线集合
路线集合通过组织[Organization]对象创建。具体操作见代码示例
let color = new Cellsys.Color(Cellsys.Ribbon["Red"], Cellsys.RibbonLevel["L1"]);
let polylineSymbol = new Cellsys.PolylineSymbol(color);//路线集合的地图符号
Cellsys.organization.createLineSet({
"name": "集合名称",
"remark": "集合备注",
"polylineSymbol":polylineSymbol
})
.then((lineSet) => {
console.log(lineSet); //创建成功后会返回路线集合对象
})
.catch(error => {
console.log(error.code)
console.log(error.message)
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 3、修改路线集合
路线集合通过组织[Organization]对象修改。具体操作见代码示例
lineSet.setName("输入修改名称");
lineSet.setRemark("修改备注");
/*设置样式*/
let color = new Cellsys.Color(Cellsys.Ribbon["Red"], Cellsys.RibbonLevel["L1"]);
let polylineSymbol = new Cellsys.PolylineSymbol(color);//路线集合的地图符号
polylineSymbol.width = 10;
polylineSymbol.alpha = 0.5;
lineSet.setSymbol(polylineSymbol);
/*提交修改*/
Cellsys.organization.updateLineSet(lineSet)
.then(() => {
let name = lineSet.name;//修改后的集合名称
let remark = lineSet.remark;//修改后的备注
})
.catch(error => {
console.log(error.code)
console.log(error.message)
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 4、删除路线集合
路线集合通过组织[Organization]对象来删除。具体操作见代码示例
Cellsys.organization.deleteLineSet(lineSet)
.then(() => {
//删除成功
})
.catch(error => {
console.log(error.code)
console.log(error.message)
})
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# (三)路线要素[LineFeature]
路线要素是地图数据,一个路线要素对象可以表示一条地图路线。路线要素的常用属性表如下:
属性名 | 值类型 | 属性描述 |
---|---|---|
name | String | 路线集合名称 |
remark | String | 备注 |
symbol | PolylineSymbol | 线符号 |
polyline | Polyline | 线坐标集合 |
fenceInfo | FenceInfo | 围栏信息 |
# 1、获取路线要素
路线集合[LineSet]提供了query方法来查询自身集合中的路线要素。具体操作见代码示例
//实例化查询配置,代表当前查询第1页数据,1页10条数据
let queryConfig = new Cellsys.QueryConfig(1, 10);
lineSet.queryLines(queryConfig)
.then((queryResult) => {
/*分页信息-查询方法特有*/
let pageInfo = queryResult.pageInfo;//查询接口特有的分页信息
let totalCount = pageInfo.totalCount;//数据总数
let totalPage = pageInfo.totalPage;//总页数
let pageNo = pageInfo.pageNo;//当前页码(从1开始)
let pageSize = pageInfo.pageSize;//每页查询数量(注意!不一定和当前查询的数据总量匹配)
/*获取查询结果*/
let lineFeatures = queryResult.data;
if (lineFeatures != null && lineFeatures.length > 0) {//查询结果可能为null
for (let lineFeature of lineFeatures) {
/*路线要素基础信息获取示例*/
let name = lineFeature.name;//路线要素名称
let remark = lineFeature.remark;//备注
let polylineSymbol = lineFeature.symbol;//路线符号
let polyline = lineFeature.polyline;//路线坐标
let fenceInfo = lineFeature.fenceInfo;//电子围栏属性
}
}
})
.catch(error => {
console.log(error.code)
console.log(error.message)
})
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
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
# 2、新增路线要素
路线要素[LineFeature]通过路线集合[LineSet]对象创建。具体操作见代码示例
/*生成路线坐标*/
let points = [];
points.add(new Cellsys.MapPoint(36.576037, 101.792951));
points.add(new Cellsys.MapPoint(36.115893, 103.814436));
points.add(new Cellsys.MapPoint(38.458087, 106.363264));
points.add(new Cellsys.MapPoint(34.899654, 113.570295));
points.add(new Cellsys.MapPoint(36.857848, 117.173811));
let polyline = new Cellsys.Polyline(points);
lineSet.createLine({
"name": "路线名称",
"remark": "路线备注",
"polyline": polyline
})
.then((lineFeature) => {
//创建成功
})
.catch(error => {
console.log(error.code)
console.log(error.message)
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 3、修改路线要素
路线要素[LineFeature]通过路线集合[LineSet]对象修改。具体操作见代码示例
lineFeature.setName("修改名字");
lineFeature.setRemark("修改备注");
let points = [];
points.add(new Cellsys.MapPoint(39.909627, 116.397504));
points.add(new Cellsys.MapPoint(31.239919, 121.500446));
points.add(new Cellsys.MapPoint(23.106414, 113.324553));
points.add(new Cellsys.MapPoint(22.561611, 114.108159));
let polyline = new Cellsys.Polyline(points);
lineFeature.setPolyline(polyline);
lineSet.updateLine(lineFeature)
.then(() => {
/*成功,可在回调中直接查看原对象修改后的数据*/
let name = lineFeature.name;
let remark = lineFeature.remark;
let polyline = lineFeature.polyline;
})
.catch(error => {
console.log(error.code)
console.log(error.message)
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 4、删除路线要素
路线要素[LineFeature]通过路线集合[LineSet]对象删除。具体操作见代码示例
lineSet.deleteLine(lineFeature)
.then(() => {
/*删除成功*/
})
.catch(error => {
console.log(error.code)
console.log(error.message)
})
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8