提供一个坐标点,返回该点附近的建筑物信息,最后以三维动画的形式将建筑物展示在地图上。自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:[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;/// 是否开启生长动画 (仅对建筑物生效),默认yesprismoverlayview.isgrowthanimation=yes;/// 动画结束代理prismoverlayview.delegate= self;return prismoverlayview;}return nil;}
-(__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;/// 是否开启生长动画 (仅对建筑物生效),默认yesprismoverlayview.isgrowthanimation=yes;/// 动画结束代理prismoverlayview.delegate= self;return prismoverlayview;}return nil;}
效果如下:
上一篇
下一篇
本篇文章对您是否有帮助?