since6.4.0起ios地图sdk支持3d棱柱(bmkprismoverlay)绘制。提供一组多边形有序序列的点,根据序列点和高度生成3d棱柱。
nsstring*filepath =[[nsbundle mainbundle] pathforresource:@"haidian"oftype:@"txt"];nsstring*pointsstring =[nsstring stringwithcontentsoffile:filepath encoding:nsutf8stringencoding error:nil];nsarray<nsstring*>*pointsarray =[pointsstring componentsseparatedbystring:@"\n"];bmkmappoint points[pointsarray.count];for(nsuinteger i =0; i < pointsarray.count;i){if([pointsarray[i] rangeofstring:@","].location !=nsnotfound){nsarray<nsstring*>*tmppoints =[pointsarray[i] componentsseparatedbystring:@","];points[i]=bmkmappointmake([tmppoints.firstobject doublevalue],[tmppoints.lastobject doublevalue]);}}bmkprismoverlay*_prism =[bmkprismoverlay prismoverlaywithpoints:points count:pointsarray.count];_prism.height=1000.f;[_mapview addoverlay:_prism];
-(bmkoverlayview*)mapview:(bmkmapview*)mapview viewforoverlay:(id<bmkoverlay>)overlay {if([overlay iskindofclass:[bmkprismoverlayclass]]){bmkprismoverlayview*prismoverlayview =[[bmkprismoverlayview alloc] initwithprismoverlay:(bmkprismoverlay*)overlay];if([overlay isequal:_prismoverlay]){prismoverlayview.sidefacecolor=[uicolor colorwithred:0green:0blue:0.5alpha:1.0];prismoverlayview.topfacecolor=[uicolor colorwithred:0.0green:0blue:0.5alpha:0.4];return prismoverlayview;}return nil;}return nil;}
效果如下:
上一篇
下一篇
本篇文章对您是否有帮助?