(以“<div id="examples_center"><!-- 页面标题 --><div class="title-hd">个性化地图</div><!-- 标题下子标题及简介,可有多个 --><div class="title-mi">...”为内容创建页面) |
|||
第27行: | 第27行: | ||
} finally { | } finally { | ||
try { | try { | ||
− | if (inputStream | + | if (inputStream!= null) { |
inputStream.close(); | inputStream.close(); | ||
} | } | ||
− | if (outputStream | + | if (outputStream!= null) { |
outputStream.close(); | outputStream.close(); | ||
} | } |
2022年1月21日 (五) 12:11的版本
个性化地图
功能场景
示例说明了个性化地图的黑夜、白天样式如何在同一页面进行切换或者关闭个性化地图。
Android
iOS
//mapopen-website-wiki.bj.bcebos.com/demos/AndroidVideos/个性化地图@android.mp4
1590746640|//mapopen-website-wiki.bj.bcebos.com/demos/newqrcodes/个性化地图@2xanidroid.png
扫码体验
使用产品
Android地图SDK|/index.php?title=androidsdk
>
个性化地图|/index.php?title=androidsdk/guide/create-map/custommap
下载源码
//mapopen-website-wiki.bj.bcebos.com/demos/BaiduMapSDKExample.zip
核心接口
类
接口
描述
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);
复制
深色
复制成功