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

[core] Refactor core annotations API - #5200

Merged
jfirebaugh merged 9 commits into
masterfrom
5158-minimal
Jun 2, 2016
Merged

jfirebaugh merged 9 commits into
masterfrom
5158-minimal

Conversation

@jfirebaugh

@jfirebaugh jfirebaugh commented May 31, 2016 •

Copy link
Copy Markdown
Contributor
  • Use geometry.hpp types (fixes mbgl::AnnotationManager should use mapbox::geometry types #5158).
  • Rename annotation types based on the underlying style layer type they use: Symbol, Line, or Fill.
  • Introduce a unified variant Annotation type; eliminate type-specific add/update methods.
  • Eliminate separate array-oriented methods. They are not significantly faster than simply calling the singleton method in a loop.
  • @1ec5, can you please review the osx and ios changes?
  • @tobrun, can you please review the android changes?
  • @brunoabinader or @tmpsantos, can you please make the necessary qt changes? I'm not sure what the best approach is for this platform.

return { segment };
}

- (mbgl::ShapeAnnotation::Properties)shapeAnnotationPropertiesObjectWithDelegate:(__unused id <MGLMultiPointDelegate>)delegate {

@1ec5 1ec5 May 31, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, if you call -[MGLMapView visibleFeaturesAtPoint:] at the location of a multipoint (in geometry.hpp terms), you get an MGLMultiPointFeature object back. MGLMultiPointFeature is a subclass of MGLMultiPoint that conforms to MGLAnnotation, so you can add this MGLMultiPoint object to the map using -[MGLMapView addAnnotations:]. With these changes, MGLMapView will end up calling -shapeAnnotationObjectWithDelegate: on an MGLMultiPoint that has no implementation of -shapeAnnotationObjectWithDelegate:, resulting in an Objective-C exception.

If it isn’t straightforward to create an mbgl::ShapeAnnotation representing a multipoint geometry at this time, I think it’d be reasonable to implement a -shapeAnnotationObjectWithDelegate: that asserts for now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MGLMultiPoint is trying to do too many things. It should represent the geometric "multi point" concept, and not also try to be a base class for MGLPolygon and MGLPolyline. (Our Java classes make a similar mistake.)

@1ec5 1ec5 Jun 1, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Unfortunately, I think we’re stuck with MapKit’s concept of a multipoint (as any shape with multiple points) for backwards compatibility. What could we call the class that represents a standard GIS multipoint? Or should we bite the bullet and bump the major version number for simplicity?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MGLSparseMultiPoint? 😬

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I make 5698978 part of this PR, how hard would it be to refactor things so that -annotationObjectWithDelegate: is implemented by every class that implements MGLAnnotation?

@1ec5 1ec5 Jun 1, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MGLAnnotation is a public protocol, so we can’t use any C++ types or expect the developer to implement this method themselves for their custom MGLAnnotation classes.

The base model class for things that get turned into mbgl::ShapeAnnotations is currently MGLMultiPoint. There’s no base model class for things that get turned into mbgl::PointAnnotations, because any Objective-C object can conform to the MGLAnnotation protocol and thus be added as a point annotation.

We could centralize this shape conversion logic to avoid any surprises, since it isn’t like the developer can really come up with their own novel geometry class. MGLMultiPoint is a natural place to host a centralized conversion method, but the most flexible approach would be to implement a standalone C function similar to MGLFeaturesFromMBGLFeatures().

@1ec5 1ec5 added refactor Core The cross-platform C++ core, aka mbgl annotations Annotations on iOS and macOS or markers on Android labels May 31, 2016
@tmpsantos

Copy link
Copy Markdown
Contributor

On it.

@tmpsantos

Copy link
Copy Markdown
Contributor

@jfirebaugh made it so it will build, but we are not really using shape annotations for Qt ATM and we are likely to rewrite it completely anyway.

@tobrun

tobrun commented Jun 1, 2016

Copy link
Copy Markdown
Member

@jfirebaugh will review later today

@jfirebaugh

Copy link
Copy Markdown
Contributor Author

Merged the larger refactor into this PR and updated the description.

@jfirebaugh jfirebaugh changed the title [core] Use geometry.hpp types for shape annotations [core] Refactor core annotations API Jun 1, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing the Darwin unit tests to fail to compile. Those tests need only a couple of the methods in this header. We should split this header into MGLGeometry_Private.h (private visibility, so it's visible to test target) and MGLGeometry_Internal.h (project visibility, so it's visible only to the dynamic and static targets).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, you can put MGLPointFromLocationCoordinate2D() in MGLFeature_Private.h, which already houses some geometry type conversion code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue was that geometry.hpp was still in src rather than include.

@jfirebaugh
jfirebaugh force-pushed the 5158-minimal branch 3 times, most recently from f1161dc to ac4ccdd Compare June 1, 2016 17:12
@tobrun

tobrun commented Jun 1, 2016

Copy link
Copy Markdown
Member

@jfirebaugh

I tried building this locally with:

git submodule update
git make clean
git make android-lib-arm-v8

I have no issues with building but at runtime I'm running into:

Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZN6mapbox9geojsonvt9GeoJSONVTC1ENSt6__ndk16vectorINS0_16ProjectedFeatureENS2_9allocatorIS4_EEEENS0_7OptionsE" referenced by "libmapbox-gl.so"...

I validated that this is not happening on master.


The code itself LGTM and reading the C++ was really useful/insightful for me.

LMK if I can help out or need to retest.

@jfirebaugh

Copy link
Copy Markdown
Contributor Author

@tobrun Looks to me like this crash does happen on master too.

@jfirebaugh

Copy link
Copy Markdown
Contributor Author

It's #5108 again. 😠

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 Core The cross-platform C++ core, aka mbgl refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mbgl::AnnotationManager should use mapbox::geometry types

4 participants