ios地图sdk | 百度地图api sdk-凯发k8官方旗舰厅

浏览器版本低!无法浏览完整内容,建议升级或更换浏览器。
绘制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:[bmkprismoverlayclass]]){
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:[bmkprismoverlayclass]]){
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棱柱

下一篇

绘制海量点

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

网站地图