在Mapbox上添加模糊效果

Jig*_*rji 5 objective-c ios mapbox

我想在mapbox中添加模糊效果.第一次加载地图时,时间只显示地图中的当前位置其他地图是蓝色.

在此输入图像描述

当我将用户位置移动到另一个位置时,地图上的其他位置清晰.另外在特定位置显示注释,请参见屏幕截图

在此输入图像描述

帮助我如何实现这一点

在这里,我将实现一些代码

- (CGPoint)convertLatLongCoord:(CGPoint)latLong {
    CGSize screenSize = [UIScreen mainScreen].applicationFrame.size];
    CGFloat SCALE = MIN(screenSize.width, screenSize.height) / (2.0 * EARTH_RADIUS);
    CGFloat OFFSET = MIN(screenSize.width, screenSize.height) / 2.0;
    CGFloat x = EARTH_RADIUS * cos(latLong.x) * cos(latLong.y) * SCALE + OFFSET;
    CGFloat y = EARTH_RADIUS * cos(latLong.x) * sin(latLong.y) * SCALE + OFFSET;

    return CGPointMake(x, y);
}

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations
{
    NSLog(@"data=%f",self.mapview.userLocation.coordinate.latitude);
    CLLocation *currentLoc=[locations objectAtIndex:0];
    _coordinate=currentLoc.coordinate;
CGPoint latLong = {_coordinate.latitude, _coordinate.longitude};
    oldcord = [self convertLatLongCoord:latLong];
    NSLog(@"Cartesian Coordinate: (%f, %f)",oldcord.x, oldcord.y);

}
Run Code Online (Sandbox Code Playgroud)

在这个代码中,我将得到UserLocation坐标的完美视图像素点.之后我想用CGPoint清除视图中的模糊,但我无法得到它.我想我会创建CGPoint数组,而不是清除使用线来模糊视图但我不能得到它请建议我.

我也使用这个lib但我无法得到很多想法 https://github.com/DenHeadless/Shapes

iph*_*nic 4

根据逻辑,我在此处的评论中添加了一个示例,供您在此处下载,检查下面的结果

在此输入图像描述

该示例包含以下逻辑。

  1. 使用 iOS Map,在 Map 上方添加了一个自定义 UIView,UIView 的类DrawView实际上处理所有绘图和擦除部分。
  2. 我们当然必须CLLocationManager确定用户的移动。
  3. 一旦CLLocationManager开始给出位置,我们就使用以下代码转换 MapView 引脚位置的坐标

    CGPoint pt=[self.map convertCoordinate:location.coordinate toPointToView:self.view];
    
    Run Code Online (Sandbox Code Playgroud)

    我们传递CGPointUIView 的转换值来清除绘图中的区域

    [self.drawView eraseAtPoint:pt];
    
    Run Code Online (Sandbox Code Playgroud)
  4. 当用户坐标中的 CGPoint 传递给 DrawVieweraseAtPoint函数时,我们擦除定义半径的区域,并根据需要清除该区域。

  5. 我添加了一个示例directions.gpx文件来模拟 GPS 位置,示例 GIF 显示了运动。

注意:该项目的链接将在2017 年 3 月 14 日之后过期,因此请保持下载状态,无论如何,如果您想要该示例,请在评论中再次 ping。请随意根据需要进行修改。

更新:

添加擦除圆形区域而不是方形区域的功能,只需将DrawViewdrawRect中的函数替换为以下代码即可

- (void)drawRect:(CGRect)rect {    

    // Drawing code
    UIColor *backgroundColor=[UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1.0f];//Grey

    [backgroundColor setFill];
    UIRectFill(rect);

    if(!self.initialLoad){//If the view has been loaded from next time we will try to clear area where required..

        // clear the background in the given rectangles
        for (NSValue *holeRectValue in _rectArray) {
            CGContextRef context = UIGraphicsGetCurrentContext();

            CGRect holeRect = [holeRectValue CGRectValue];

            [[UIColor clearColor] setFill];

            CGRect holeRectIntersection = CGRectIntersection( holeRect, rect );

            CGContextSetFillColorWithColor( context, [UIColor clearColor].CGColor );
            CGContextSetBlendMode(context, kCGBlendModeClear);

            CGContextFillEllipseInRect( context, holeRectIntersection );

        }
    }

    self.initialLoad=NO;
}
Run Code Online (Sandbox Code Playgroud)

干杯。