ios-setLatLngBounds (#1455)
Co-authored-by: Julian Bissekkou <julian.bissekkou@tapped.dev>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
MapLibre welcomes participation and contributions from everyone. Please read [`Contributing Guide`](https://github.com/maplibre/maplibre-native/blob/master/CONTRIBUTING.md) to get started.
|
||||
|
||||
## main
|
||||
|
||||
* Add `MLNMapView.setLatLngBounds` and `MLNMapView.clearLatLnBounds`
|
||||
* 💥 Breaking: Changed the prefix of files, classes, methods, variables and everything from `MGL` to `MLN`. ([#919](https://github.com/maplibre/maplibre-native/pull/919)).
|
||||
|
||||
> To migrate:
|
||||
|
||||
@@ -31,6 +31,11 @@ static const MLNCoordinateBounds colorado = {
|
||||
.ne = { .latitude = 40.989329, .longitude = -102.062592},
|
||||
};
|
||||
|
||||
static const MLNCoordinateBounds areaAroundBelgium = {
|
||||
.sw = { .latitude = 52.2782, .longitude = 8.289179999999988},
|
||||
.ne = { .latitude = 48.5584, .longitude = 1.0162300000000073},
|
||||
};
|
||||
|
||||
static NSString * const MBXViewControllerAnnotationViewReuseIdentifer = @"MBXViewControllerAnnotationViewReuseIdentifer";
|
||||
|
||||
typedef NS_ENUM(NSInteger, MBXSettingsSections) {
|
||||
@@ -99,6 +104,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsRuntimeStylingRows) {
|
||||
};
|
||||
|
||||
typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
|
||||
MBXSettingsMiscellaneousLatLngBoundsConstraints,
|
||||
MBXSettingsMiscellaneousWorldTour,
|
||||
MBXSettingsMiscellaneousRandomTour,
|
||||
MBXSettingsMiscellaneousScrollView,
|
||||
@@ -227,6 +233,7 @@ CLLocationCoordinate2D randomWorldCoordinate(void) {
|
||||
BOOL _isTouringWorld;
|
||||
BOOL _contentInsetsEnabled;
|
||||
UIEdgeInsets _originalContentInsets;
|
||||
BOOL _hasLatLngBoundConstraints;
|
||||
}
|
||||
|
||||
// MARK: - Setup & Teardown
|
||||
@@ -426,6 +433,7 @@ CLLocationCoordinate2D randomWorldCoordinate(void) {
|
||||
break;
|
||||
case MBXSettingsMiscellaneous:
|
||||
[settingsTitles addObjectsFromArray:@[
|
||||
_hasLatLngBoundConstraints ? @"Remove LatLng bound constraints" : @"Set LatLng bound box constraint",
|
||||
@"Start World Tour",
|
||||
@"Random Tour",
|
||||
@"Embedded Map View",
|
||||
@@ -645,6 +653,9 @@ CLLocationCoordinate2D randomWorldCoordinate(void) {
|
||||
case MBXSettingsMiscellaneous:
|
||||
switch (indexPath.row)
|
||||
{
|
||||
case MBXSettingsMiscellaneousLatLngBoundsConstraints:
|
||||
[self setLatLngBoundsConstraints];
|
||||
break;
|
||||
case MBXSettingsMiscellaneousLocalizeLabels:
|
||||
[self toggleStyleLabelsLanguage];
|
||||
break;
|
||||
@@ -1451,6 +1462,20 @@ CLLocationCoordinate2D randomWorldCoordinate(void) {
|
||||
}
|
||||
}
|
||||
|
||||
-(void)setLatLngBoundsConstraints
|
||||
{
|
||||
if(_hasLatLngBoundConstraints) {
|
||||
[self.mapView clearLatLnBounds];
|
||||
[self.mapView resetPosition];
|
||||
} else {
|
||||
MLNMapCamera *newCamera = [self.mapView cameraThatFitsCoordinateBounds: areaAroundBelgium];
|
||||
[self.mapView setCamera: newCamera];
|
||||
[self.mapView setLatLngBounds: areaAroundBelgium];
|
||||
}
|
||||
|
||||
_hasLatLngBoundConstraints = !_hasLatLngBoundConstraints;
|
||||
}
|
||||
|
||||
-(void)toggleStyleLabelsLanguage
|
||||
{
|
||||
_localizingLabels = !_localizingLabels;
|
||||
|
||||
@@ -1364,6 +1364,18 @@ MLN_EXPORT
|
||||
*/
|
||||
- (CGPoint)anchorPointForGesture:(UIGestureRecognizer *)gesture;
|
||||
|
||||
|
||||
/**
|
||||
* Sets a LatLngBounds that constraints map transformations to this bounds.
|
||||
* @param latLngBounds the bounds to constrain the map with
|
||||
*/
|
||||
- (void)setLatLngBounds:(MLNCoordinateBounds)latLngBounds;
|
||||
|
||||
/**
|
||||
* Clears the bounds that were set via `setLatLngBounds`
|
||||
*/
|
||||
- (void)clearLatLnBounds;
|
||||
|
||||
/**
|
||||
The distance from the edges of the map view’s frame to the edges of the map
|
||||
view’s logical viewport.
|
||||
|
||||
@@ -2698,6 +2698,7 @@ public:
|
||||
currentCameraOptions.anchor = anchor;
|
||||
MLNCoordinateBounds bounds = MLNCoordinateBoundsFromLatLngBounds(self.mbglMap.latLngBoundsForCamera(currentCameraOptions));
|
||||
|
||||
|
||||
return [self cameraThatFitsCoordinateBounds:bounds];
|
||||
}
|
||||
|
||||
@@ -3836,6 +3837,23 @@ static void *windowScreenContext = &windowScreenContext;
|
||||
self.mbglMap.setBounds(mbgl::BoundOptions().withMinZoom(minimumZoomLevel));
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void)clearLatLnBounds
|
||||
{
|
||||
mbgl::BoundOptions newBounds = mbgl::BoundOptions().withLatLngBounds(mbgl::LatLngBounds());
|
||||
self.mbglMap.setBounds(newBounds);
|
||||
}
|
||||
|
||||
- (void)setLatLngBounds:(MLNCoordinateBounds)latLngBounds
|
||||
{
|
||||
mbgl::LatLng sw = {latLngBounds.sw.latitude, latLngBounds.sw.longitude};
|
||||
mbgl::LatLng ne = {latLngBounds.ne.latitude, latLngBounds.ne.longitude};
|
||||
mbgl::BoundOptions newBounds = mbgl::BoundOptions().withLatLngBounds(mbgl::LatLngBounds::hull(sw, ne));
|
||||
|
||||
self.mbglMap.setBounds(newBounds);
|
||||
}
|
||||
|
||||
- (double)minimumZoomLevel
|
||||
{
|
||||
return *self.mbglMap.getBounds().minZoom;
|
||||
|
||||
Reference in New Issue
Block a user