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

Commit

Permalink
extend annotation bounds querying for shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
incanus committed Jun 1, 2015
1 parent da01318 commit 376ad5e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
9 changes: 8 additions & 1 deletion include/mbgl/util/geo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@ struct LatLngBounds {
if (point.longitude > ne.longitude) ne.longitude = point.longitude;
}

inline bool contains(const LatLng& point) {
inline bool contains(const LatLng& point) const {
return (point.latitude >= sw.latitude &&
point.latitude <= ne.latitude &&
point.longitude >= sw.longitude &&
point.longitude <= ne.longitude);
}

inline bool intersects(const LatLngBounds area) const {
return (area.ne.latitude > sw.latitude &&
area.sw.latitude < ne.latitude &&
area.ne.longitude > sw.longitude &&
area.sw.longitude < ne.longitude);
}
};

}
Expand Down
13 changes: 6 additions & 7 deletions src/mbgl/map/annotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,13 @@ AnnotationIDs AnnotationManager::getAnnotationsInBounds(const LatLngBounds& quer
}

// check bounds
const LatLngBounds annoBounds = it->second->getBounds();
return (annoBounds.sw.latitude >= queryBounds.sw.latitude &&
annoBounds.ne.latitude <= queryBounds.ne.latitude &&
annoBounds.sw.longitude >= queryBounds.sw.longitude &&
annoBounds.ne.longitude <= queryBounds.ne.longitude);
} else {
return false;
if (it->second->type == AnnotationType::Point) {
return queryBounds.contains(it->second->getPoint());
} else if (it->second->type == AnnotationType::Shape) {
return queryBounds.intersects(it->second->getBounds());
}
}
return false;
});
}
}
Expand Down

0 comments on commit 376ad5e

Please sign in to comment.