Switching the building heights on

Hello,

I am trying to turn on the building heights in the map.

Below is what I have been doing so far.

  1. load the vector tiles by calling the below function when the map is ready.

tomtomMap.getUiSettings().loadDefaultStyle();

  1. create 3d layer regex

private static final String LAYERS_IN_3D_REGEX = "Subway Station 3D | Place of worship 3D | Railway Station 3D | Government Administration Office 3D | Other building 3D | School building 3D | Other town block 3D | Factory building 3D | Hospital building 3D | Hotel building 3D | Cultural Facility 3D";

  1. set visibility of 3d layers

List<Layer> layers = tomtomMap.getStyleSettings().findLayersById(LAYERS_IN_3D_REGEX);
int size = layers.size();
for(int i = 0; i < size; i++){
layers.get(i).setVisibility(Visibility.VISIBLE);
}

But when I run the code, the map is terminated with an exception. Is there anything I am missing here? Any help would be appreciated.

Hi there!

  1. Could you post a exception log?
  2. What version of the SDK are you using?
  3. You don’t actually need to call tomtomMap.getUiSettings().loadDefaultStyle(); unless you loaded a custom style and want to reload the default one.

Hi Damian,

Thank you for your reply.

Below is the log when the crash is occurred.

09-27 01:31:51.884 17623-17623/com.apps.testApp V/be: set25DMode() 09-27 01:31:51.884 17623-17623/com.apps.testApp V/UiSettingsImpl: setMapModeType(mapModeType = MODE_3D) 09-27 01:31:51.885 17623-17623/com.apps.testApp V/aq: setPerspectiveRatio(v = 1.0) 09-27 01:31:51.898 17623-17623/com.apps.testApp A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0x80e89410 in tid 17623 (bapps.testApp)

After some more tests, I noticed the above crash was caused by incorrect REGEX grammar.

Originally I didn’t have a space between separator ‘|’ and the layer name, and that was why I got the above error.

After the REGEX was revised, I didn’t get an error.

However, I am still struggling with turning on the building heights.

It seems like the 3d layers can’t be found when below line is called because the size of returned list is zero.

List<Layer> layers = tomtomMap.getStyleSettings().findLayersById(LAYERS_IN_3D_REGEX);

Below is the library version that I am using right now.

`implementation("com.tomtom.online:sdk-maps:2.4637")
implementation("com.tomtom.online:sdk-search:2.4637")
implementation("com.tomtom.online:sdk-routing:2.4637")
implementation("com.tomtom.online:sdk-traffic:2.4637")
implementation("com.tomtom.online:sdk-geofencing:2.4637")
implementation("com.tomtom.online:sdk-maps-ui-extensions:2.4637")
implementation("com.tomtom.online:sdk-maps-rx-extensions:2.4637")
implementation("com.tomtom.online:sdk-maps-ktx-extensions:2.4637") 
implementation("com.tomtom.online:sdk-maps-static-image:2.4637")
implementation("com.tomtom.online:sdk-maps-driving-extensions:2.4637")`

I’ve tried your regex and indeed there were no layers found. I think it might be the space between “|” and the layer name because without spaces I’ve managed to find 11 layers.

    private const val LAYERS_IN_3D_REGEX =
        "Subway Station 3D|Place of worship 3D|Railway Station 3D|Government Administration Office 3D|Other building 3D|School building 3D|Other town block 3D|Factory building 3D|Hospital building 3D|Hotel building 3D|Cultural Facility 3D"

Could you try my regex without calling tomtomMap.getUiSettings().loadDefaultStyle(); before?

Okay, I tried your suggestion.

I removed the spaces between the separator and layer name, and I deleted the below line.

tomtomMap.getUiSettings().loadDefaultStyle();

As a result, I didn’t get any crash, and I was able to find the 11 layers.
Also, the map was showing in 2.5D perspective.

However, the building heights was still not turned on although I called below line for every layers.

layers.get(i).setVisibility(Visibility.VISIBLE);

I think that crash happened because style was not fully loaded when you tried to find layers.

The code you posted looks okay. Only thing I can think of is that even with perspective set to 2.5D the map is not zoomed enough.

Building are shown when map is zoomed in significantly.

Could you try to zoom in on the map? Also what area are you trying to check building for? There might be no 3D building data available.

Here is our sample application and it contains the exact example you are trying to achieve:

2 Likes

Yes! Finally got it.

As you mentioned, I deleted

tomtomMap.getUiSettings().loadDefaultStyle();

then I zoomed in very closely and finally the 3D building data begun to show up.

Thank you for the help.

1 Like