Mapbox Ios 图层 选择高亮

有个图层,图层很大,点击某一块,进行高亮

点击图层选择到代码那块
说下思路,首先我高亮的是line图层,别的没试过。
1.拿到点击图层
2.获取点击的那块图层的geojson
3.根据geojson创建图层,放到地图上,换个颜色
4.关于取消图层,我做的是移除图层,记录上一次记录的点击的idf也就是标识符,这个标识符一定是唯一的不然会崩溃,至于你怎么去搞这个标识符自己去想,然后去获取shaper 移除,再去移除layer
// An highlighted block
//移除图层代码
  MGLStyleLayer *layer = [self.mapBoxmapView.style layerWithIdentifier:你的标识符];
            // Create new layer for the line.

   MGLSource *idfSource = [self.mapBoxmapView.style sourceWithIdentifier:你的标识符(这俩是统一的)];
            // Set the line join and cap to a rounded end.
            
   if (idfSource && layer) {
                
        [self.mapBoxmapView.style removeLayer:layer];
        [self.mapBoxmapView.style removeSource:idfSource];
    }
//正文
[features enumerateObjectsUsingBlock:^(MGLPolygonFeature *obj, NSUInteger idx, BOOL * _Nonnull stop) ]
//在这个方法里可以拿到OBJ 利用obj 转为JSON 这个就是你点击的图层 一小部分图层
 *最主要的方法*'NSDictionary *objDict = [obj geoJSONDictionary];'****
 //在这里还能取到当前obj的数据,我是拿到obj的一个字段当作标识符,这个标识符是唯一的
 MGLShape *shape = [MGLShape shapeWithData:[xxx yy_modelToJSONData] 	    encoding:NSUTF8StringEncoding error:nil];
 
 MGLSource *source = [[MGLShapeSource alloc] initWithIdentifier:xxxx shape:shape options:nil];
 
 [self.mapBoxmapView.style addSource:source];
//上面那个就是添加图层的没啥可研究的
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值