作者:只喝大瓶的雪碧 | 来源:互联网 | 2023-05-19 06:37
I have the following problem:
我有以下问题:
I have a "drawn map" (image) which I add to the MapView as an Overlay. No Problem with that.. but I need to limit the MapView to the region of the Overlay, so a user isn't able to scroll/zoom outside of this region.. but it should be possible to scroll/zoom inside the "bounds" of the overlay - means I cannot just disable zoom/scrolling for the MapView.
我有一个“绘制的地图”(图像),我将它作为叠加添加到MapView中。这个模式没有任何的问题。但是我需要将MapView限制在覆盖区域,这样用户就不能在这个区域之外滚动/缩放。但是在覆盖层的“界限”内滚动/缩放应该是可能的——这意味着我不能仅为MapView禁用缩放/滚动。
Are there any ideas/solution on this topic? The reason for using the MapView/-Kit is that I need to add various POIs to the custom map. This may become more complex when just using an ImageView+ScrollView for presenting the custom map.
关于这个话题有什么想法/解决办法吗?使用MapView/-Kit的原因是我需要向自定义映射添加各种POIs。如果只是使用ImageView+ScrollView来表示定制映射,这可能会变得更加复杂。
I've researched alot on this topic, but I didn't found a nice solution.
关于这个话题我已经研究了很多,但是我没有找到一个好的解决方案。
Any help is appreciated!
任何帮助都是赞赏!
Best Regards, Christian
最好的祝福,基督教
Edit: This is our solution: You supply a topleft and a bottomright coordinate to limit the map. The (minimum) zoomlevel is also limited. I've deactivated decelerating and you are able to bounce a bit out of the map (for better performance/ux). I added a ~1km grey border to the overlay so the user isnÄt able to see the orignal worldmap of google.
编辑:这是我们的解决方案:您提供一个左上角和右下角的坐标来限制映射。zoomlevel也是有限的。我已经停用了减速,您可以从地图上反弹一点(为了更好的性能/用户体验)。我在覆盖层添加了一个~1km的灰色边框,这样用户就可以看到谷歌的原始世界地图了。
LimitedMapView.h:
LimitedMapView.h:
#import
#import
@interface LimitedMapView : MKMapView {
}
@property (nonatomic, assign) CLLocationCoordinate2D topLeftCoordinate;
@property (nonatomic, assign) CLLocationCoordinate2D bottomRightCoordinate;
@end
LimitedMapView.m:
LimitedMapView.m:
#import "LimitedMapView.h"
@implementation LimitedMapView
@synthesize topLeftCoordinate, bottomRightCoordinate;
- (void)scrollViewDidZoom:(UIScrollView *)scrollView{
if([super respondsToSelector:@selector(scrollViewDidZoom:)]) [super scrollViewDidZoom:scrollView];
if ([self region].span.latitudeDelta > 0.002401f || [self region].span.longitudeDelta > 0.003433f) {
CLLocationCoordinate2D center = self.centerCoordinate;
MKCoordinateSpan span = MKCoordinateSpanMake(0.002401f, 0.003433f);
self.region = MKCoordinateRegionMake(center, span);
}
}
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
if([super respondsToSelector:@selector(scrollViewDidEndDragging:)]) [super scrollViewDidEndDragging:scrollView willDecelerate:decelerate];
MKCoordinateRegion currentRegion = self.region;
bool changeRegiOnLong= YES;
bool changeRegiOnLat= YES;
// LONGITUDE
if((currentRegion.center.longitude - (currentRegion.span.longitudeDelta/2)) self.bottomRightCoordinate.longitude) {
currentRegion.center.lOngitude= (bottomRightCoordinate.longitude - (currentRegion.span.longitudeDelta/2));
} else {
changeRegiOnLong= NO;
}
// LATITUDE
if((currentRegion.center.latitude + (currentRegion.span.latitudeDelta/2)) > self.topLeftCoordinate.latitude) {
currentRegion.center.latitude = (topLeftCoordinate.latitude - (currentRegion.span.latitudeDelta/2));
} else if((currentRegion.center.latitude - (currentRegion.span.latitudeDelta/2))
3 个解决方案