googlemaps/android-maps-utils

Google maps does not render KML polygons with inner boundaries correctly (one or more polygons never get rendered)

OlavAa opened this issue · 3 comments

Background

While creating bathymetric maps as KML I like to make the map earier to read by adding different colored polygons to each 1m level. If using completely filled polygons, the KML is rendered differently each time I do a addLayerToMap (leading me to believe Google Maps have no way to control the order the polygons are added like Google Earth has).

Problem

To solve this I altered the KML to also include inner boundaries to "cut out" the inner and eliminate the need for the rendering of the polygons to come in a particular order. Using Google Earth I can verify that the filled polygons never overlap. Google Earth also renders this KML perfectly. But Google Maps can no longer render them all. No clear pattern. On one water every other, on another water perhaps one or two of them are missing.

Expected behavior

Using Google Earth: Sample water with all colored polygons selected. Each meter level rendered:
image

Also using Google Earth, I deselected the all levels but 2-3 meters to illustrate that its inner is "cut out". All other polygons but the deepest one have their inner "cut out":
image

I have built my KMLs in two ways: The "hard way" by writing strings with tabs and tags "manually" and by using Python and "simpleKml". I first thought the problem (see below) was caused by simpleKml adding multiple (when applicable, often needed for a water) "LinerarRing" within a single "innerBoundaryIs". So I dropped simpleKml and coded manually to get multiple "innerBoundaryIs" with a single "LinearRing" inside each. But for Google Maps that did not matter, behaviour is identical.

Sample from the KML-file for the illustrated 2 meter polygon (coordinates are abbreviated - this polygon has one outer boundary (always) and 1+ inner boundaries, this one has 3):
<Placemark> <name>2</name> <styleUrl>#2</styleUrl> <Polygon> <tessellate>true</tessellate> <altitudeMode>clampToGround</altitudeMode> <outerBoundaryIs> <LinearRing> <coordinates>10.592408209489095,59.64232214633835,0 ... 10.592408209489095,59.64232214633835,0</coordinates> </LinearRing> </outerBoundaryIs> <innerBoundaryIs> <LinearRing> <coordinates>10.592191189077477,59.642402279689236,0 ... 10.592191189077477,59.642402279689236,0</coordinates> </LinearRing> </innerBoundaryIs> <innerBoundaryIs> <LinearRing> <coordinates>10.590486028700466,59.643027621876,0 ... 10.590486028700466,59.643027621876,0</coordinates> </LinearRing> </innerBoundaryIs> <innerBoundaryIs> <LinearRing> <coordinates>10.589741958717772,59.64305730583021,0 ... 10.589741958717772,59.64305730583021,0</coordinates> </LinearRing> </innerBoundaryIs> </Polygon> </Placemark>

The KML code is not easy to read in the code editor, here's a picture to easier see the typical structure:
image

Observed behavior

As stated and visualized above, while Google Earth renders each polygon and also the entire "depth map" perfectly, Google Maps using Android does not. For this particular depth map only one colored polygon is missing. On another water depth map every second is invisible. Here's a screen shot:
image

Environment details

Multiple devices used, all experience the same behaviour. My development device is a Samsung Galaxy Tab S6 lite (SM-P610), running Android 12 and One UI 4.1.1.
Environment for the app is:

  • com.google.android.gms:play-services-maps:18.0.2
  • com.google.maps.android:android-maps-utils:2.4.0

Steps to reproduce

The behaviour in Google Maps is fairly consistent, at least it never displays all polygons properly. But the amount of polygons gone missing is not consistent.

Using a second water map, first in Google Earth:
image

Then using Google Maps:
image

I have also attached the KML for this latter sample (file type altered to "txt", change back to "kml" to use):
sample.txt

@OlavAa Thank you for opening this issue. 🙏
Please check out these other resources that might help you get to a resolution in the meantime:

This is an automated message, feel free to ignore.

After playing around with a sample "depth map" I see the root cause may be some polygons within the KML. The fact that Google Earth is able to correctly render the polygons may also be a result of GE filtering away bad information somehow. Will have to look more closely an how I build my polygons outer and in particular inner boundaries.

@OlavAa Do you still think this is a bug or was the problem all with the input polygons? Feel free to re-open if you've found that it's a bug after fixing the polygons.