简体   繁体   English

自定义标注(mapBox iOS sdk)

[英]Custom callout (mapBox iOS sdk)

i want to create callout with custom view - such as this one 我想用自定义视图创建标注 - 比如这个 在此输入图像描述
(source: arcgis.com ) (来源: arcgis.com

But i can't find any workaround to do this stuff, only solution i find is to use following code: 但我找不到任何解决方法来做这个东西,只有我找到的解决方案是使用以下代码:

- (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation

         ... 
        marker = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"marker.png"]]; 
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
        CalloutViewController* callout = [storyboard instantiateViewControllerWithIdentifier:@"callout"]; 
        [marker setLabel:callout.view];
}

but result not quite what i want, because when I set the label property of the marker, the view appears without tapping on the marker. 但结果不是我想要的,因为当我设置标记的label属性时,视图会出现而不会点击标记。

Any idea how to solve this problem? 知道如何解决这个问题吗? Or maybe there's some other approaches to achieve this? 或者也许有其他方法来实现这一目标?

EDIT: 编辑:

also i find this article on github , but i can't figure out how to implement it. 我也在github上找到这篇文章,但我无法弄清楚如何实现它。

look at https://github.com/iNima/mapbox-ios-sdk/blob/91d8614fa4549b25dd8b647d82f270382c279a8c/MapView/Map/RMMapView.m 看看https://github.com/iNima/mapbox-ios-sdk/blob/91d8614fa4549b25dd8b647d82f270382c279a8c/MapView/Map/RMMapView.m

it tells you that on click the RMMapView class will handle showing a callout for you given your marker's layer has canShowCallout == YES and title != nil set on it 它告诉你,点击RMMapView类将处理为你显示一个标注,因为你的标记图层有canShowCallout == YEStitle != nil设置就可以了

if your marker fulfils this you get the same callout as with MapKit :) 如果你的标记符合这个,你得到与MapKit相同的标注:)

set contentView or left- or right- CalloutView variables to modify that callout view 设置contentView或left-或right- CalloutView变量来修改该标注视图

- (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation

     ... 
    marker = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"marker.png"]]; 
    [marker setCanShowCallout:YES];
    [marker setTitle"Test"];

    //Following only works with iNimas version
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
    CalloutViewController* callout = [storyboard instantiateViewControllerWithIdentifier:@"callout"]; 
    [marker setContentView:callout.view];

    return marker ; 
}

This is outside the scope of the SDK, as it's done in the SMCalloutView dependent project. 这超出了SDK的范围,因为它是在依赖于SMCalloutView项目中完成的。 Since both are open source, you can add this behavior but it's currently not possible. 由于两者都是开源的,因此您可以添加此行为,但目前无法实现。

(I wrote the SDK in question). (我写了有问题的SDK)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM