Mapbox-gl-native: Second polyline with identical coordinates not rendered

Created on 23 Jan 2017  路  9Comments  路  Source: mapbox/mapbox-gl-native

Platform: iOS 10.2
Mapbox SDK version: 3.4

Steps to trigger behavior

  1. Add polyline with same start and end coordinate

Expected behavior

Polyline visible on map

Actual behavior

Polyline does not added to map

annotations bug iOS macOS release blocker

Most helpful comment

Cool! thanks for a prompt response. In the meantime just wanted to post about the workaround that we use for polylines: we add one polyline with coords in a normal order and then the second polyline with coords in a reversed order. This prevents isEqual from returning true for these two polylines.

All 9 comments

Could you perhaps post code that reproduces this issue? Modifying our our test shapes example to start/end on the same coordinate works as expected:

simulator screen shot jan 23 2017 11 39 47 am

func creatMapboxLine() -> MGLPolyline {
    var coordinates = self.coordinates
    return MGLPolyline(coordinates: &coordinates, count: UInt(coordinates.count))
}

self.mapView.addOverlays(lines)

Basically this is what I do, (I need to spend some time to test with a hardcoded line so I can get a better code snippet but a bit pressed for time right now). But if the line has identical start/ends it will not show up, and will not even ask for their styling (strokeColorForShapeAnnotation or lineWidthForPolylineAnnotation)

If i remove the last coordinate it works every time as expected.

In 3.3.7 there are no problems with this.

I am drawing fairly short lines (indoor maps for a building) if that changes anything.

Right, after further testing it seems that its not lines that start and end at the same place, its polylines that perfectly matches a polygons outline that disappear (no calls for stroke color etc).

edit: Potentially its also because rendering order of overlays has changed?

We're experiencing the same issue. The actual use-case is that we want to draw a polyline with an outline and we do that by adding two polylines: one wider on the back and then another one on top. They both have the same coords.

I've identified that the issue is this line here https://github.com/mapbox/mapbox-gl-native/blob/62ea1f21858c69f6921c775ba7a3de201f0514d8/platform/ios/src/MGLMapView.mm#L2936

Introduced here: 751aff2ddd1770d9842c273f65e8aad768112151 cc @boundsj

This line prevent from adding two annotation that has the same set of coords. Comparator for polyline objects (and for other annotation types too) compares the actual coords one by one, I think author's intention was to compare only references to prevent two same objects being added.

Thanks for digging into this @kmagiera! I'll put this on the our 3.5.0 release milestone.

In the meantime, using the runtime styling API introduced in the Mapbox iOS SDK release 3.4.0 should not suffer from the same issue and would offer you many more styling options -- a single feature can visualized with multiple style layers.

Cool! thanks for a prompt response. In the meantime just wanted to post about the workaround that we use for polylines: we add one polyline with coords in a normal order and then the second polyline with coords in a reversed order. This prevents isEqual from returning true for these two polylines.

I've identified that the issue is this line here https://github.com/mapbox/mapbox-gl-native/blob/62ea1f21858c69f6921c775ba7a3de201f0514d8/platform/ios/src/MGLMapView.mm#L2936

Thanks for tracking this down! This line used to be innocuous, but #6559 implemented custom -isEqual: methods for the shape classes, which means we now deep-compare annotations before adding them. I think we鈥檇 only want to consider pointer equality in this case, using -[NSArray indexOfObjectIdenticalTo:].

we add one polyline with coords in a normal order and then the second polyline with coords in a reversed order

I would鈥檝e suggested a simpler workaround of varying the title property, but that led me to #8351.

@kmagiera, another workaround is to vary the title or subtitle property.

A compounding factor is that -[MGLMultiPoint isEqual:] only requires the two objects to both be MGLMultiPoints, and MGLPolyline and MGLPolygon lack stricter class membership tests.

Fixed in #8355 on the release-v3.5.0-android-v5.0.0 branch.

Was this page helpful?
0 / 5 - 0 ratings