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

Exposing MGLGeometry_Private.h C++ globals #9819

Closed
ambientlight opened this issue Aug 21, 2017 · 5 comments
Closed

Exposing MGLGeometry_Private.h C++ globals #9819

ambientlight opened this issue Aug 21, 2017 · 5 comments
Labels
iOS Mapbox Maps SDK for iOS

Comments

@ambientlight
Copy link

ambientlight commented Aug 21, 2017

Hi guys,

It would be great to have tile geometry available to a client for feature reconstitution discussed in #9647, so I have exposed tile geometry with:

/* 
 Returns z/x/y tile id given coordinate belongs to.
 */
MGLTileID MGLTileIDContainingCoordinate2D(CLLocationCoordinate2D coordinate, double zoomLevel){
    
    mbgl::LatLng latLng = { coordinate.latitude, coordinate.longitude };
    const double scale = std::pow(2.0, zoomLevel);
    const mbgl::TileCoordinatePoint point = mbgl::Projection::project(latLng, scale) / double(mbgl::util::tileSize);
    return { uint8_t(zoomLevel), uint32_t(point.x), uint32_t(point.y) };
}

/*
 Returns the coordinate bounds corresponding to z/x/y tile id
 */
MGLCoordinateBounds MGLCoordinateBoundsForTileId(MGLTileID tileID){
    
    const mbgl::TileCoordinatePoint point = { double(tileID.x), double(tileID.y) };
    const mbgl::TileCoordinatePoint nextPoint = { double(tileID.x + 1), double(tileID.y + 1) };
    const double scale = std::pow(2.0, tileID.z);
    
    const mbgl::LatLng nw = mbgl::Projection::unproject(point * double(mbgl::util::tileSize), scale);
    const mbgl::LatLng se = mbgl::Projection::unproject(nextPoint * double(mbgl::util::tileSize), scale);
    
    return MGLCoordinateBoundsMake(CLLocationCoordinate2DMake(se.latitude(), nw.longitude()),
                                   CLLocationCoordinate2DMake(nw.latitude(), se.longitude()));
}

in MGLGeometry_Private.h, while MGLTileID is defined as:

/**
 Identifies z/x/y tile.
 */
typedef struct __attribute__((objc_boxable)) MGLTileID {
    uint8_t z;
    uint32_t x;
    uint32_t y;
} MGLTileID;

It does work for me when I wrap these functions inside Objective-C++ methods, however I am hitting linker failures when I try exposing them directly as

/** Returns z/x/y tile id given coordinate belongs to. */
MGLTileID MGLTileIDContainingCoordinate2D(CLLocationCoordinate2D coordinate, double zoomLevel);

/** Returns the coordinate bounds corresponding to z/x/y tile id. */
MGLCoordinateBounds MGLCoordinateBoundsForTileId(MGLTileID tileID);

in MGLGeometry.h.
(ref: GeoThings@2d6d23b)

It feels like I am missing something obvious that I don't know here, any thoughts guys?

@kkaefer kkaefer added the iOS Mapbox Maps SDK for iOS label Aug 25, 2017
@1ec5
Copy link
Contributor

1ec5 commented Feb 27, 2018

We have no plans to expose any C++ interfaces as part of the iOS or macOS SDK’s public API, because it would break applications written in pure Objective-C or Swift. That said, if there are opportunities to implement these conversions independently in Objective-C, there might be a viable path to adding such an implementation to the public API.

@ambientlight
Copy link
Author

Yes that is the approach(tile covertion done seperately at my swift/js client side) I actually followed in the end.

@ambientlight
Copy link
Author

But if it will be available in SDK out of the box that would be certainly helpful.

@ambientlight
Copy link
Author

@1ec5: does it make sense for me to go with a pull request to js/ios sdks?

@1ec5
Copy link
Contributor

1ec5 commented Feb 28, 2018

Yes, we’d be open to a PR for the iOS and macOS SDKs at least. MGLComputedShapeSource (#6940 #9983) introduced x/y/z tile coordinates as a concept. For that feature, we ultimately went with a series of method parameters (e.g., -invalidateTileAtX:y:zoomLevel:) instead of a struct. But now that we have APIs that deal in x/y/z and other APIs that deal in coordinate bounds, it does make sense to expose conversion functions publicly.

We have no plans to expose any C++ interfaces as part of the iOS or macOS SDK’s public API, because it would break applications written in pure Objective-C or Swift.

On second thought, C++ is only a concern because these methods are currently inlined. If we move the implementations of these methods to a .mm file – probably a good idea anyways – then they’d be perfectly compatible with pure Objective-C.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

No branches or pull requests

3 participants