发布于 

高德地图安卓 SDK 离线加载自定义样式

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
32
33
34
35
36
37
38
public class AMapCustomStyleLoader {

private byte[] buffStyle = null;
private byte[] buffStyleExtra = null;

@SuppressWarnings("ResultOfMethodCallIgnored")
public AMapCustomStyleLoader(String stylePath, String styleExtraPath, AssetManager assetManager) {
InputStream inputStreamStyle = null;
InputStream inputStreamStyleExtra = null;
try {
inputStreamStyle = assetManager.open(stylePath);
int lenStyle = inputStreamStyle.available();
buffStyle = new byte[lenStyle];
inputStreamStyle.read(buffStyle);
inputStreamStyleExtra = assetManager.open(styleExtraPath);
int lenStyleExtra = inputStreamStyle.available();
buffStyleExtra = new byte[lenStyleExtra];
inputStreamStyleExtra.read(buffStyleExtra);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (inputStreamStyle != null) inputStreamStyle.close();
if (inputStreamStyleExtra != null) inputStreamStyleExtra.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

public byte[] getStyle() {
return buffStyle;
}

public byte[] getStyleExtra() {
return buffStyleExtra;
}
}