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

[core] Refactor core annotations API #5200

Merged
merged 9 commits into from
Jun 2, 2016
Merged

[core] Refactor core annotations API #5200

merged 9 commits into from
Jun 2, 2016

Conversation

jfirebaugh
Copy link
Contributor

@jfirebaugh jfirebaugh commented May 31, 2016

  • 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 {
Copy link
Contributor

@1ec5 1ec5 May 31, 2016

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
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.)

Copy link
Contributor

@1ec5 1ec5 Jun 1, 2016

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
Contributor

Choose a reason for hiding this comment

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

MGLSparseMultiPoint? 😬

Copy link
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?

Copy link
Contributor

@1ec5 1ec5 Jun 1, 2016

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
Contributor

On it.

@tmpsantos
Copy link
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
Copy link
Member

tobrun commented Jun 1, 2016

@jfirebaugh will review later today

@jfirebaugh
Copy link
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
@@ -6,6 +6,7 @@
#endif

#import <mbgl/util/geo.hpp>
#import <mbgl/util/geometry.hpp>
Copy link
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
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
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.

@tobrun
Copy link
Member

tobrun commented Jun 1, 2016

@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
Contributor Author

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

@jfirebaugh
Copy link
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