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

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