0

我已经设法使用交互式离线 mbtiles(在 TileMill 上创建)来:

  • 快速加载超过 1000 个点
  • 让他们了解用户何时单击每个点并显示带有每个点名称的弹出窗口

我无法再次使名称为可点击的气泡。

我使用以下代码为每个点的注释生成图层

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

    RMMarker *marker = [[RMMarker alloc] initWithMapboxMarkerImage:@"embassy"];

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 32)];

    imageView.contentMode = UIViewContentModeScaleAspectFit;

    imageView.image = annotation.userInfo;

    marker.leftCalloutAccessoryView = imageView;

    marker.canShowCallout = YES;

    return marker;
}

这就是我获取预告片并从 mbtiles 文件构建注释的方式:

- (void)singleTapOnMap:(RMMapView *)mapView at:(CGPoint)point{
    [mapView removeAllAnnotations];

    RMMBTilesSource *source = (RMMBTilesSource *)mapView.tileSource;

    if ([source conformsToProtocol:@protocol(RMInteractiveSource)] && [source supportsInteractivity])
    {
        NSString *formattedOutput = [source formattedOutputOfType:RMInteractiveSourceOutputTypeTeaser
                                                         forPoint:point
                                                        inMapView:mapView];

        if (formattedOutput && [formattedOutput length])
        {
            // parse the country name out of the content
            //
            NSUInteger startOfCountryName = [formattedOutput rangeOfString:@"<strong>"].location + [@"<strong>" length];
            NSUInteger endOfCountryName   = [formattedOutput rangeOfString:@"</strong>"].location;

            NSString *countryName = [formattedOutput substringWithRange:NSMakeRange(startOfCountryName, endOfCountryName - startOfCountryName)];

            // parse the flag image out of the content
            //
            NSUInteger startOfFlagImage = [formattedOutput rangeOfString:@"base64,"].location + [@"base64," length];
            NSUInteger endOfFlagImage   = [formattedOutput rangeOfString:@"\" style"].location;

            UIImage *flagImage = [UIImage imageWithData:[NSData dataFromBase64String:[formattedOutput substringWithRange:NSMakeRange(startOfFlagImage, endOfFlagImage)]]];

            RMAnnotation *annotation = [RMAnnotation annotationWithMapView:mapView coordinate:[mapView pixelToCoordinate:point] andTitle:countryName];

            annotation.userInfo = flagImage;

            [mapView addAnnotation:annotation];

            [mapView selectAnnotation:annotation animated:YES];
        }
    }
}

更新 我想出了如何通过在标记上使用 leftCalloutAccessoryView 来做到这一点(我在 layerForAnnotation 方法的末尾添加了以下内容:

marker.leftCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

并使用以下委托方法来跟踪事件:

-(void)tapOnCalloutAccessoryControl:(UIControl *)control forAnnotation:(RMAnnotation *)annotation onMap:(RMMapView *)map{
    NSLog(@"I will now pass to the next screen !  YEAH! %@",annotation.title);
}

现在的问题是我想摆脱左边的calloutAccesoryView。有什么建议么?

4

1 回答 1

0

您在这里所拥有的关于地图的任何内容都不需要。您真正想要的是标注(类型为SMCalloutView,是您正在使用的 Mapbox SDK 的一个依赖项目)来注册其点击次数。

查看此问题以获取更多详细信息:

https://github.com/mapbox/mapbox-ios-sdk/issues/422

于 2014-08-19T00:44:44.837 回答