全部服务产品
开发者频道
定价
登录
绘制3D建筑物
下载开发文档
绘制3D建筑物简介

提供一个坐标点,返回该点附近的建筑物信息,最后以三维动画的形式将建筑物展示在地图上。自6.5.7版本开始支持楼层动画效果。

3D建筑物绘制

首先通过BMKBuildingSearch 类来设置3D建筑物的属性,然后检索对应的建筑物,最后在检索成功的回调中绘制建筑物:

注意:建筑物检索为高级服务,需申请AK权限。
1. 发起建筑物检索
BMKBuildingSearch *buildingSearch = [[BMKBuildingSearch alloc] init];
buildingSearch.delegate = self;
BMKBuildingSearchOption *opeiton = [[BMKBuildingSearchOption alloc] init];
opeiton.location = CLLocationCoordinate2DMake(40.03558, 116.34301);
[buildingSearch buildingSearch:opeiton];
2. 实现代理方法,获取检索结果,添加3D建筑物数据
#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;
}
3. 实现代理方法生成对应的view
- (__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;
/// 是否开启生长动画 (仅对建筑物生效),默认YES
prismOverlayView.isGrowthAnimation = YES;
/// 动画结束代理
prismOverlayView.delegate = self;
return prismOverlayView;
}
return nil;
}
4. 设置楼层增长动画
- (__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;
/// 是否开启生长动画 (仅对建筑物生效),默认YES
prismOverlayView.isGrowthAnimation = YES;
/// 动画结束代理
prismOverlayView.delegate = self;
return prismOverlayView;
}
return nil;
}

效果如下:

上一篇

绘制3D棱柱

下一篇

绘制海量点

本篇文章对您是否有帮助?