浏览器版本低!无法浏览完整内容,建议升级或更换浏览器。

文档全面上新

更科技的视觉体验,更高效的页面结构,快前往体验吧!

体验新版
个性化地图
功能场景
示例说明了个性化地图的黑夜、白天样式如何在同一页面进行切换或者关闭个性化地图。
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); 
                    
                
复制
深色
复制成功
  • 文档根本没法用

  • 文档水平很差

  • 文档水平一般

  • 文档不错

  • 文档写的很好

如发现文档错误,或对此文档有更好的建议,请在下方反馈。问题咨询请前往反馈平台提交工单咨询。

提交反馈

拖动标注工具

添加矩形标注

添加箭头标注

完成

取消