有个图层,图层很大,点击某一块,进行高亮
。
点击图层选择到代码那块
说下思路,首先我高亮的是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];
//上面那个就是添加图层的没啥可研究的