Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Second polyline with identical coordinates not rendered #7811

Closed
LesSvant opened this issue Jan 23, 2017 · 9 comments
Closed

Second polyline with identical coordinates not rendered #7811

LesSvant opened this issue Jan 23, 2017 · 9 comments
Assignees
Labels
annotations Annotations on iOS and macOS or markers on Android bug iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS release blocker Blocks the next final release
Milestone

Comments

@LesSvant
Copy link

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

@friedbunny
Copy link
Contributor

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

@friedbunny friedbunny added the iOS Mapbox Maps SDK for iOS label Jan 23, 2017
@LesSvant
Copy link
Author

LesSvant commented Jan 24, 2017

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.

@boundsj boundsj added the annotations Annotations on iOS and macOS or markers on Android label Jan 24, 2017
@LesSvant
Copy link
Author

LesSvant commented Jan 26, 2017

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?

@kmagiera
Copy link

kmagiera commented Feb 2, 2017

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

if ([self.annotations containsObject:annotation])

Introduced here: 751aff2 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.

@boundsj
Copy link
Contributor

boundsj commented Feb 2, 2017

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.

@boundsj boundsj added this to the ios-v3.5.0 milestone Feb 2, 2017
@kmagiera
Copy link

kmagiera commented Feb 3, 2017

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.

@jfirebaugh jfirebaugh changed the title Polylines does not render if they start/end at the same coordinate since 3.4 Second polylines with identical coordinates not rendered Mar 9, 2017
@jfirebaugh jfirebaugh changed the title Second polylines with identical coordinates not rendered Second polyline with identical coordinates not rendered Mar 9, 2017
@jfirebaugh jfirebaugh added the release blocker Blocks the next final release label Mar 9, 2017
@1ec5
Copy link
Contributor

1ec5 commented Mar 10, 2017

I've identified that the issue is this line here

if ([self.annotations containsObject:annotation])

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’d 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’ve 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.

@1ec5 1ec5 added the macOS Mapbox Maps SDK for macOS label Mar 10, 2017
@1ec5 1ec5 self-assigned this Mar 10, 2017
@1ec5
Copy link
Contributor

1ec5 commented Mar 10, 2017

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.

@1ec5
Copy link
Contributor

1ec5 commented Mar 10, 2017

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

@1ec5 1ec5 closed this as completed Mar 10, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
annotations Annotations on iOS and macOS or markers on Android bug iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS release blocker Blocks the next final release
Projects
None yet
Development

No branches or pull requests

6 participants