个性化地图
功能场景
示例说明了个性化地图的黑夜、白天样式如何在同一页面进行切换或者关闭个性化地图。
Android
iOS

//mapopen-website-wiki.bj.bcebos.com/demos/AndroidVideos/个性化地图@android.mp4

扫码体验
核心接口
类
接口
描述
MapView
setMapCustomStylePath(String customStyleFilePath)
设置个性化地图样式文件的路径
ReverseGeoCodeOption
setMapCustomStyleEnable(boolean customMapStyleEnable)
动态设置个性化地图样式是否生效
核心代码
1.示例中是本地样式加载,sty样式存储在工程的assets文件下
JAVA
/** /** * 获取个性化地图存储路径 */ private String getCustomStyleFilePath(Context context, String customStyleFileName) { FileOutputStream outputStream = null; InputStream inputStream = null; String parentPath = null; try { inputStream = context.getAssets().open("customConfigdir/" + customStyleFileName); byte[] buffer = new byte[inputStream.available()]; inputStream.read(buffer); parentPath = context.getFilesDir().getAbsolutePath(); File customStyleFile = new File(parentPath + "/" + customStyleFileName); if (customStyleFile.exists()) { customStyleFile.delete(); } customStyleFile.createNewFile(); outputStream = new FileOutputStream(customStyleFile); outputStream.write(buffer); } catch (IOException e) { Log.e("CustomMapDemo", "Copy custom style file failed", e); } finally { try { if (inputStream!= null) { inputStream.close(); } if (outputStream!= null) { outputStream.close(); } } catch (IOException e) { Log.e("CustomMapDemo", "Close stream failed", e); return null; } } return parentPath + "/" + customStyleFileName; }
复制
深色
复制成功
2.设置个性化地图样式文件的路径并开启个性化
JAVA
// 获取路径
String customStyleFilePath = getCustomStyleFilePath(MainActivity.this, CUSTOM_FILE_NAME_GRAY);
// 设置路径
mMapView.setMapCustomStylePath(customStyleFilePath);
// 开启个性化
mMapView.setMapCustomStyleEnable(true);
复制
深色
复制成功