Huawei mapStyle is not applied properly

156 Views Asked by At

I am trying to add map style to Huawei map for my app. I had made a JSON file for style from Huawei map style editor and use it in setMapStyle method by MapStyleOptions.loadRawResourceStyle and passing the JSON file. I used huawei simple map and add some custom style to it. When I first open the app then the default map (simple) is loaded and the custom styles from JSON is not applied, but I go back to the previous screen and again launch the map screen then the style from JSON is properly applied. How to solve the problem for the first time launch?

1

There are 1 best solutions below

3
On

First you can follow this development documents all Steps:

setMapStyle method by MapStyleOptions.loadRawResourceStyle and passing the JSON file, this is load the local map.

To fix the problem need to change the cloud load mapstyle , see the above docs's Step 5:

Using a custom style after a map is created Call the setStyleId and previewId methods in HuaweiMap to use a custom map style. The sample code is as follows:

HuaweiMap hMap;
// Specify a style ID after a map is created.
hMap.setStyleId(String styleId);
// Specify a preview ID after a map is created.
hMap.previewId(String previewId);

Using a custom style before a map is created Call the styleId and previewId methods in HuaweiMapOptions to use a custom map style. If both styleId and previewId are set, styleId takes precedence. The sample code is as follows:

HuaweiMapOptions huaweiMapOptions;
// Specify a style ID before a map is created.
huaweiMapOptions.styleId(String styleId);
// Specify a preview ID before a map is created.
huaweiMapOptions.previewId(String previewId);

use method above will change the cloud map for the first time.