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

MGLMultiPolygon doesn't support coordinate property #7070

Closed
aayers-agrible opened this issue Nov 15, 2016 · 9 comments
Closed

MGLMultiPolygon doesn't support coordinate property #7070

aayers-agrible opened this issue Nov 15, 2016 · 9 comments
Assignees
Labels
crash iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS
Milestone

Comments

@aayers-agrible
Copy link

Platform:
iOS
Mapbox SDK version:
3.3.6

Steps to trigger behavior

  1. Create a MGLMultiPolygon object (I parse them from a geojson source)
  2. Request the MGLMultiPolygon object's 'coordinate' property
  3. Get "MGLShape is an abstract class error"

Expected behavior

The centroid of the MultiPoly would be returned from the coordinate property

Actual behavior

I get an 'MGLShape is an abstract class' error.

@boundsj boundsj added iOS Mapbox Maps SDK for iOS feature labels Nov 15, 2016
@1ec5 1ec5 added crash and removed feature labels Jan 13, 2017
@1ec5
Copy link
Contributor

1ec5 commented Jan 13, 2017

There are two issues here:

  • -[MGLMultiPolygon coordinate] should be implemented in order to avoid the exception in MGLShape. For now, we can have it return the first coordinate, as MGLPolyline and MGLPolygon do.
  • -[MGLPolyline coordinate], -[MGLPolygon coordinate], and -[MGLMultiPolygon coordinate] should return the centroid. This is a larger task that would require Polylabel.

/cc @mourner

@mourner
Copy link
Member

mourner commented Jan 13, 2017

@1ec5 wasn't Polylabel already integrated recently by @jfirebaugh?

@1ec5
Copy link
Contributor

1ec5 commented Jan 13, 2017

Ah, I missed that it got integrated (for label placement) in #7465. We'll have to figure out a way to make it accessible to SDK code as well.

@jfirebaugh
Copy link
Contributor

I would argue that the problem here is that -coordinate is even in the interface of MGLShape and subclasses. It should be in the interface of MGLPointAnnotation only. The artificial definition of a "coordinate" for polygons, multipolygons, line strings -- and the lengths we will need to go through to implement it -- are signs that this is a design error.

@1ec5
Copy link
Contributor

1ec5 commented Apr 13, 2017

coordinate is defined on the MGLAnnotation protocol, so any class that conforms to it must implement the property. This is consistent with MapKit.

@1ec5
Copy link
Contributor

1ec5 commented Apr 13, 2017

To expand on #7070 (comment), having coordinate return something meaningful for the more exotic shape types is just icing on the cake. The real bug here is that -[MGLMultiPolygon coordinate] is unimplemented, leading to a crash. Even having -[MGLMultiPolygon coordinate] return the first coordinate of the first polygon would’ve been fine, but #8713 goes the extra mile to return something more meaningful.

/cc @fabian-guerra

@1ec5 1ec5 added the macOS Mapbox Maps SDK for macOS label Apr 13, 2017
@jfirebaugh
Copy link
Contributor

jfirebaugh commented Apr 13, 2017

Right -- I'm suggesting that either:

  • MGLShape should not conform to MGLAnnotation, or
  • MGLAnnotation should not define coordinate.

If you find yourself implementing methods where the implementation is arbitrary, then something is off about your class design.

@1ec5
Copy link
Contributor

1ec5 commented Apr 13, 2017

If you find yourself implementing methods where the implementation is arbitrary, then something is off about your class design.

That’s a good argument for making the coordinate property optional in the MGLAnnotation protocol, so that it would only be provided by the classes where it makes sense.

I would contend that it should be possible to implement a non-arbitrary coordinate for every shape type – after all, we do that for labeling features in vector sources – but that it isn’t a priority for the more exotic shape types. The highest priority is fixing the crash, and I believe that’s why this issue is on the v3.6.0 milestone. A secondary priority would be to implement a sensible coordinate for MGLPolyline and MGLPolygon specifically, to simplify the task in #2082/#5502.

Changing either MGLShape’s protocol conformance or making MGLAnnotation.coordinate optional would be a major, backwards-incompatible change. We’d want to track that separately and maybe consider it at the same time as #7454.

@1ec5
Copy link
Contributor

1ec5 commented May 23, 2017

Fixed in #8713 on the release-ios-v3.6.0-android-v5.1.0 branch.

@1ec5 1ec5 closed this as completed May 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
crash iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS
Projects
None yet
Development

No branches or pull requests

6 participants