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

Map jumps from one position to another #4214

Merged
merged 7 commits into from
Mar 10, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Known issues:

## iOS master

- Fixed screen coordinates for LatLng coordinates accross the antimeridian. ([#4215](https://github.com/mapbox/mapbox-gl-native/issues/4155))
- Fixed a bounce-back effect when panning the map. ([#4214](https://github.com/mapbox/mapbox-gl-native/pull/4214))
- An icon laid out along a line no longer appears if it would extend past the end of the line. Some one-way arrows no longer point the wrong way. ([#3839](https://github.com/mapbox/mapbox-gl-native/pull/3839))
- Reduce slanted segments in dashed lines near corners. ([#3914](https://github.com/mapbox/mapbox-gl-native/pull/3914))
- Telemetry location gathering now only occurs when the device is in motion. ([#4115](https://github.com/mapbox/mapbox-gl-native/pull/4115))
Expand Down
5 changes: 2 additions & 3 deletions include/mbgl/annotation/point_annotation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ namespace mbgl {

class PointAnnotation {
public:
inline PointAnnotation(const LatLng& position_, const std::string& icon_ = "")
: position(position_), icon(icon_) {
}
PointAnnotation(const LatLng& position_, const std::string& icon_ = "")
: position(position_.wrapped()), icon(icon_) {}

const LatLng position;
const std::string icon;
Expand Down
17 changes: 15 additions & 2 deletions include/mbgl/annotation/shape_annotation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,24 @@ class ShapeAnnotation {
std::string>; // creates an annotation whose type and properties are sourced from a style layer

ShapeAnnotation(const AnnotationSegments& segments_, const Properties& properties_)
: segments(segments_), properties(properties_) {
}
: segments(wrapCoordinates(segments_)), properties(properties_) {}

const AnnotationSegments segments;
const Properties properties;

private:
AnnotationSegments wrapCoordinates(const AnnotationSegments& segments_) {
AnnotationSegments wrappedSegments;
// Wrap all segments coordinates.
for (const auto& segment_ : segments_) {
AnnotationSegment wrappedSegment;
for (const auto& latLng_ : segment_) {
wrappedSegment.push_back(latLng_.wrapped());
}
wrappedSegments.push_back(wrappedSegment);
}
return wrappedSegments;
}
};

} // namespace mbgl
Expand Down
29 changes: 14 additions & 15 deletions include/mbgl/util/geo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,17 @@ class LatLng {
LatLng wrapped() const { return { latitude, longitude, Wrapped }; }

void wrap() {
if (longitude < -util::LONGITUDE_MAX) longitude = std::fmod(longitude, util::LONGITUDE_MAX * 2);
if (longitude > util::LONGITUDE_MAX) longitude = -util::LONGITUDE_MAX + std::fmod(longitude, util::LONGITUDE_MAX);
}

/** If a path crossing the antemeridian would be shorter, extend the final
coordinate so that interpolating between the two endpoints will cross it. */
void unwrapForShortestPath(const LatLng& start) {
if (std::abs(start.longitude) + std::abs(longitude) > util::LONGITUDE_MAX) {
if (start.longitude > 0 && longitude < 0) {
longitude += util::DEGREES_MAX;
} else if (start.longitude < 0 && longitude > 0) {
longitude -= util::DEGREES_MAX;
}
if (longitude < -util::LONGITUDE_MAX) longitude = util::LONGITUDE_MAX + std::fmod(longitude + util::LONGITUDE_MAX, util::DEGREES_MAX);
if (longitude > util::LONGITUDE_MAX) longitude = -util::LONGITUDE_MAX + std::fmod(longitude + util::LONGITUDE_MAX, util::DEGREES_MAX);
}

// If we pass through the antimeridian, we update the start coordinate to make sure
// the end coordinate is always wrapped.
void unwrapForShortestPath(const LatLng& end) {
if (end.longitude < -util::LONGITUDE_MAX) {
longitude += util::DEGREES_MAX;
} else if (end.longitude > util::LONGITUDE_MAX) {
longitude -= util::DEGREES_MAX;
}
}

Expand Down Expand Up @@ -201,9 +199,10 @@ class EdgeInsets {
: top(t), left(l), bottom(b), right(r) {}

explicit operator bool() const {
return top || left || bottom || right;
return !(std::isnan(top) || std::isnan(left) || std::isnan(bottom) || std::isnan(right))
&& (top || left || bottom || right);
}

void operator+=(const EdgeInsets& o) {
top += o.top;
left += o.left;
Expand Down
25 changes: 25 additions & 0 deletions include/mbgl/util/vec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ struct vec3 {
inline bool operator==(const vec3& rhs) const {
return x == rhs.x && y == rhs.y && z == rhs.z;
}

template<typename U = T, typename std::enable_if<std::numeric_limits<U>::has_quiet_NaN, int>::type = 0>
inline operator bool() const {
return !std::isnan(x) && !std::isnan(y) && !std::isnan(z);
}

template<typename U = T, typename std::enable_if<!std::numeric_limits<U>::has_quiet_NaN, int>::type = 0>
inline operator bool() const {
return x != std::numeric_limits<T>::min()
&& y != std::numeric_limits<T>::min()
&& z != std::numeric_limits<T>::min();
}
};

template <typename T = double>
Expand All @@ -117,6 +129,19 @@ struct vec4 {
inline bool operator==(const vec4& rhs) const {
return x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w;
}

template<typename U = T, typename std::enable_if<std::numeric_limits<U>::has_quiet_NaN, int>::type = 0>
inline operator bool() const {
return !std::isnan(x) && !std::isnan(y) && !std::isnan(z) && !std::isnan(w);
}

template<typename U = T, typename std::enable_if<!std::numeric_limits<U>::has_quiet_NaN, int>::type = 0>
inline operator bool() const {
return x != std::numeric_limits<T>::min()
&& y != std::numeric_limits<T>::min()
&& z != std::numeric_limits<T>::min()
&& w != std::numeric_limits<T>::min();
}
};


Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/annotation/point_annotation_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ void PointAnnotationImpl::updateLayer(const TileID& tileID, AnnotationTileLayer&

mbgl::ScreenCoordinate projected = point.position.project();
projected *= 1 << tileID.z;
projected.x -= int16_t(projected.x);
projected.y -= int16_t(projected.y);
projected.x = std::fmod(projected.x, 1);
projected.y = std::fmod(projected.y, 1);
projected *= GeometryTileFeature::defaultExtent;

layer.features.emplace_back(
Expand Down
Loading