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

Content insets #3583

Merged
merged 8 commits into from
Jan 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Known issues:
- Tapping now selects annotations more reliably. Tapping near the top of a large annotation image now selects that annotation. An annotation image’s alignment insets influence how far away the user can tap and still select the annotation. For example, if your annotation image has a large shadow, you can keep that shadow from being tappable by excluding it from the image’s alignment rect. ([#3261](https://github.com/mapbox/mapbox-gl-native/pull/3261))
- A new method on MGLMapView, `-flyToCamera:withDuration:completionHandler:`, lets you transition between viewpoints along an arc as if by aircraft. ([#3171](https://github.com/mapbox/mapbox-gl-native/pull/3171), [#3301](https://github.com/mapbox/mapbox-gl-native/pull/3301))
- MGLMapCamera’s `altitude` values now match those of MKMapCamera. ([#3362](https://github.com/mapbox/mapbox-gl-native/pull/3362))
- MGLMapView properties like `centerCoordinate` and `camera` now offset the center to account for any translucent top or bottom bar. As a result, when user tracking is enabled and the map view is an immediate child of a view controller, the user dot is centered in the unobscured portion of the map view. To override this offset, modify the `contentInset` property; you may also need to set the containing view controller’s `automaticallyAdjustsScrollViewInsets` property to `NO`. ([#3583](https://github.com/mapbox/mapbox-gl-native/pull/3583))
- The user dot’s callout view is now centered above the user dot. It was previously offset slightly to the left. ([#3261](https://github.com/mapbox/mapbox-gl-native/pull/3261))
- Fixed an issue with small map views not properly fitting annotations within bounds. (#[3407](https://github.com/mapbox/mapbox-gl-native/pull/3407))
- When the user rotates the map to within 7° of true north, the map view now snaps to true north. ([#3403](https://github.com/mapbox/mapbox-gl-native/pull/3403))
Expand Down
16 changes: 16 additions & 0 deletions include/mbgl/ios/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,22 @@ IB_DESIGNABLE
*/
- (void)flyToCamera:(MGLMapCamera *)camera withDuration:(NSTimeInterval)duration peakAltitude:(CLLocationDistance)peakAltitude completionHandler:(nullable void (^)(void))completion;

/**
The distance from the edges of the map view’s frame to the edges of the map
view’s logical viewport.

When the value of this property is equal to `UIEdgeInsetsZero`, viewport
properties such as `centerCoordinate` assume a viewport that matches the map
view’s frame. Otherwise, those properties are inset, excluding part of the
frame from the viewport. For instance, if the only the top edge is inset, the
map center is effectively shifted downward.

When the map view’s superview is an instance of `UIViewController` whose
`automaticallyAdjustsScrollViewInsets` property is `YES`, the value of this
property may be overridden at any time.
*/
@property (nonatomic, assign) UIEdgeInsets contentInset;

#pragma mark Converting Geographic Coordinates

/**
Expand Down
4 changes: 4 additions & 0 deletions include/mbgl/map/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ struct CameraOptions {
/** Coordinate at the center of the map. */
mapbox::util::optional<LatLng> center;

/** Padding around the interior of the view that affects the frame of
reference for `center`. */
mapbox::util::optional<EdgeInsets> padding;

/** Point of reference for `zoom` and `angle`, assuming an origin at the
top-left corner of the view. */
mapbox::util::optional<PrecisionPoint> anchor;
Expand Down
18 changes: 8 additions & 10 deletions include/mbgl/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ namespace util {
template <class T> class Thread;
} // namespace util

struct EdgeInsets {
double top = 0;
double left = 0;
double bottom = 0;
double right = 0;
};

class Map : private util::noncopyable {
friend class View;

Expand Down Expand Up @@ -106,17 +99,20 @@ class Map : private util::noncopyable {
// Position
void moveBy(const PrecisionPoint&, const Duration& = Duration::zero());
void setLatLng(const LatLng&, const PrecisionPoint&, const Duration& = Duration::zero());
void setLatLng(const LatLng&, const EdgeInsets&, const Duration& = Duration::zero());
void setLatLng(const LatLng&, const Duration& = Duration::zero());
LatLng getLatLng() const;
void resetPosition();
LatLng getLatLng(const EdgeInsets& = {}) const;
void resetPosition(const EdgeInsets& = {});

// Scale
void scaleBy(double ds, const PrecisionPoint& = { NAN, NAN }, const Duration& = Duration::zero());
void setScale(double scale, const PrecisionPoint& = { NAN, NAN }, const Duration& = Duration::zero());
double getScale() const;
void setZoom(double zoom, const Duration& = Duration::zero());
void setZoom(double zoom, const EdgeInsets&, const Duration& = Duration::zero());
double getZoom() const;
void setLatLngZoom(const LatLng&, double zoom, const Duration& = Duration::zero());
void setLatLngZoom(const LatLng&, double zoom, const EdgeInsets&, const Duration& = Duration::zero());
CameraOptions cameraForLatLngBounds(const LatLngBounds&, const EdgeInsets&);
CameraOptions cameraForLatLngs(const std::vector<LatLng>&, const EdgeInsets&);
void resetZoom();
Expand All @@ -126,9 +122,11 @@ class Map : private util::noncopyable {
// Rotation
void rotateBy(const PrecisionPoint& first, const PrecisionPoint& second, const Duration& = Duration::zero());
void setBearing(double degrees, const Duration& = Duration::zero());
void setBearing(double degrees, const PrecisionPoint&);
void setBearing(double degrees, const PrecisionPoint&, const Duration& = Duration::zero());
void setBearing(double degrees, const EdgeInsets&, const Duration& = Duration::zero());
double getBearing() const;
void resetNorth(const Duration& = std::chrono::milliseconds(500));
void resetNorth(const EdgeInsets&, const Duration& = std::chrono::milliseconds(500));

// Pitch
void setPitch(double pitch, const Duration& = Duration::zero());
Expand Down
25 changes: 25 additions & 0 deletions include/mbgl/osx/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,31 @@ IB_DESIGNABLE
and zooming or `NO` to immediately display the given bounds. */
- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds animated:(BOOL)animated;

/** A Boolean value indicating whether the receiver automatically adjusts its
content insets.

When the value of this property is `YES`, the map view automatically updates
its `contentInsets` property to account for any overlapping title bar or
toolbar. To overlap with the title bar or toolbar, the containing window’s
style mask must have `NSFullSizeContentViewWindowMask` set, and the title
bar must not be transparent.

The default value of this property is `YES`. */
@property (nonatomic, assign) BOOL automaticallyAdjustsContentInsets;

/** The distance from the edges of the map view’s frame to the edges of the map
view’s logical viewport.

When the value of this property is equal to `NSEdgeInsetsZero`, viewport
properties such as `centerCoordinate` assume a viewport that matches the map
view’s frame. Otherwise, those properties are inset, excluding part of the
frame from the viewport. For instance, if the only the top edge is inset,
the map center is effectively shifted downward.

When the value of the `automaticallyAdjustsContentInsets` property is `YES`,
the value of this property may be overridden at any time. */
@property (nonatomic, assign) NSEdgeInsets contentInsets;

#pragma mark Configuring gesture recognition
/** @name Configuring How the User Interacts with the Map */

Expand Down
32 changes: 32 additions & 0 deletions include/mbgl/util/geo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,38 @@ enum class NorthOrientation : uint8_t {
Leftwards,
};

/// The distance on each side between a rectangle and a rectangle within.
struct EdgeInsets {
double top = 0; ///< Number of pixels inset from the top edge.
double left = 0; ///< Number of pixels inset from the left edge.
double bottom = 0; ///< Number of pixels inset from the bottom edge.
double right = 0; ///< Number of pixels inset from the right edge.

inline EdgeInsets() {}

inline EdgeInsets(const double t, const double l, const double b, const double r)
: top(t), left(l), bottom(b), right(r) {}

inline operator bool() const {
return top || left || bottom || right;
}

inline void operator+=(const EdgeInsets& o) {
top += o.top;
left += o.left;
bottom += o.bottom;
right += o.right;
}

inline EdgeInsets operator+(const EdgeInsets& o) const {
return {
top + o.top, left + o.left, bottom + o.bottom, right + o.right,
};
}

PrecisionPoint getCenter(uint16_t width, uint16_t height) const;
};

} // namespace mbgl

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2264,9 +2264,6 @@ public LatLng fromScreenLocation(@NonNull PointF point) {
float x = point.x;
float y = point.y;

// flip y direction vertically to match core GL
y = getHeight() - y;

return mNativeMapView.latLngForPixel(new PointF(x / mScreenDensity, y / mScreenDensity));
}

Expand All @@ -2289,9 +2286,6 @@ public PointF toScreenLocation(@NonNull LatLng location) {
float x = point.x * mScreenDensity;
float y = point.y * mScreenDensity;

// flip y direction vertically to match core GL
y = getHeight() - y;

return new PointF(x, y);
}

Expand Down
13 changes: 6 additions & 7 deletions platform/default/glfw_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
}

mbgl::LatLng GLFWView::makeRandomPoint() const {
const auto sw = map->latLngForPixel({ 0, 0 });
const auto ne = map->latLngForPixel({ double(width), double(height) });
const auto nw = map->latLngForPixel({ 0, 0 });
const auto se = map->latLngForPixel({ double(width), double(height) });

const double lon = sw.longitude + (ne.longitude - sw.longitude) * (double(std::rand()) / RAND_MAX);
const double lat = sw.latitude + (ne.latitude - sw.latitude) * (double(std::rand()) / RAND_MAX);
const double lon = nw.longitude + (se.longitude - nw.longitude) * (double(std::rand()) / RAND_MAX);
const double lat = se.latitude + (nw.latitude - se.latitude) * (double(std::rand()) / RAND_MAX);

return { lat, lon };
}
Expand Down Expand Up @@ -368,10 +368,9 @@ void GLFWView::onMouseMove(GLFWwindow *window, double x, double y) {
double dx = x - view->lastX;
double dy = y - view->lastY;
if (dx || dy) {
double flippedY = view->height - y;
view->map->setLatLng(
view->map->latLngForPixel(mbgl::PrecisionPoint(x - dx, flippedY + dy)),
mbgl::PrecisionPoint(x, flippedY));
view->map->latLngForPixel(mbgl::PrecisionPoint(x - dx, y + dy)),
mbgl::PrecisionPoint(x, y));
}
} else if (view->rotating) {
view->map->rotateBy({ view->lastX, view->lastY }, { x, y });
Expand Down
Loading