提供一个坐标点,返回该点附近的建筑物信息,最后以三维动画的形式将建筑物展示在地图上。自6.5.7版本开始支持楼层动画效果。
首先通过BMKBuildingSearch 类来设置3D建筑物的属性,然后检索对应的建筑物,最后在检索成功的回调中绘制建筑物:
BMKBuildingSearch *buildingSearch = [[BMKBuildingSearch alloc] init];buildingSearch.delegate = self;BMKBuildingSearchOption *opeiton = [[BMKBuildingSearchOption alloc] init];opeiton.location = CLLocationCoordinate2DMake(40.03558, 116.34301);[buildingSearch buildingSearch:opeiton];
#pragma mark - BMKBuildingSearchDelegate- (void)onGetBuildingResult:(BMKBuildingSearch *)searcher result:(BMKBuildingSearchResult *)result errorCode:(BMKSearchErrorCode)error {if (error != BMK_SEARCH_NO_ERROR) return;_isBuilding = NO;[_mapView removeOverlays:_mapView.overlays];NSMutableArray<BMKPrismOverlay *> *buildingOverlays = [NSMutableArray array];BMKMapRect resultRect = BMKMapRectNull;for (BMKBuildInfo *info in result.buildingList) {BMKPrismOverlay *prismOverlay = [[BMKPrismOverlay alloc] init];prismOverlay.buildInfo = info;/// 楼层高度 (仅对建筑物生效)prismOverlay.floorHeight = _floorHeight;[buildingOverlays addObject:prismOverlay];BMKMapRect bounds = BMKMapRectFromEncodedGeoPoints(info.paths, BMKEncodePointTypeBuildInfo);if (BMKMapRectIsNull(resultRect)) {resultRect = bounds;} else {resultRect = BMKMapRectUnion(resultRect, bounds);}if (info.label == 1) {_coord = info.center;_buildingHeight = info.height;}}[_mapView fitVisibleMapRect:resultRect edgePadding:UIEdgeInsetsMake(10, 40, 40, 40) withAnimated:YES];[_mapView addOverlays:buildingOverlays];self.buildings = [buildingOverlays copy];_isBuilding = YES;}
- (__kindof BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id<BMKOverlay>)overlay {if([overlay isKindOfClass:[BMKPrismOverlay class]]){BMKPrismOverlayView *prismOverlayView = [[BMKPrismOverlayView alloc] initWithPrismOverlay:overlay];/// 建筑物侧面纹理prismOverlayView.sideTextureImage = [UIImage imageNamed:@"64x32"];/// 顶部颜色prismOverlayView.topFaceColor = [UIColor colorWithRed:1.f green:0.f blue:0.f alpha:1.f];/// 自定义建筑物的楼层颜色 (仅对建筑物生效)prismOverlayView.floorColor = [UIColor colorWithRed:1.f green:0.f blue:0.f alpha:0.5f];/// 自定义建筑物的楼层侧面纹理 (仅对建筑物生效)prismOverlayView.floorSideTextureImage = [UIImage imageNamed:@"64x32"];/// 自定义建筑物的楼层动画类型prismOverlayView.buildingFloorAnimateType = kBMKBuildingFloorAnimateSlow;/// 是否开启生长动画 (仅对建筑物生效),默认YESprismOverlayView.isGrowthAnimation = YES;/// 动画结束代理prismOverlayView.delegate = self;return prismOverlayView;}return nil;}
- (__kindof BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id<BMKOverlay>)overlay {if([overlay isKindOfClass:[BMKPrismOverlay class]]){BMKPrismOverlayView *prismOverlayView = [[BMKPrismOverlayView alloc] initWithPrismOverlay:overlay];/// 建筑物侧面纹理prismOverlayView.sideTextureImage = [UIImage imageNamed:@"64x32"];/// 顶部颜色prismOverlayView.topFaceColor = [UIColor colorWithRed:1.f green:0.f blue:0.f alpha:1.f];/// 自定义建筑物的楼层颜色 (仅对建筑物生效)prismOverlayView.floorColor = [UIColor colorWithRed:1.f green:0.f blue:0.f alpha:0.5f];/// 自定义建筑物的楼层侧面纹理 (仅对建筑物生效)prismOverlayView.floorSideTextureImage = [UIImage imageNamed:@"64x32"];/// 自定义建筑物的楼层动画类型prismOverlayView.buildingFloorAnimateType = kBMKBuildingFloorAnimateSlow;/// 是否开启生长动画 (仅对建筑物生效),默认YESprismOverlayView.isGrowthAnimation = YES;/// 动画结束代理prismOverlayView.delegate = self;return prismOverlayView;}return nil;}
效果如下:
上一篇
下一篇
本篇文章对您是否有帮助?