在 Mapbox 上添加模糊效果
Add blur effect on a Mapbox
我想在mapbox.when中添加模糊效果第一次加载地图时只在地图中显示当前位置其他地图是blue.see截图
当我将用户位置移动到另一个位置时,其他位置在 map.also 特定位置的显示注释上很清楚
看截图
帮助我如何实现这个
这里我将一些实现代码
- (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);
}
在此代码中,我将获得 UserLocation 的完美视图像素点 coordinate.after 我想使用 CGPoint 清除视图中的模糊,但我无法获得 it.i 我想我将创建 CGPoint 数组,然后清除使用线模糊视图但我不能得到它请建议我。
我也用这个库但是我不太了解https://github.com/DenHeadless/Shapes
根据我在评论中添加的逻辑 here I have made a sample for you download it here,检查下面的结果
示例包含以下逻辑。
- 使用iOS地图,在class地图上方添加了自定义UIView
UIView 是
DrawView
它实际上处理所有绘图和
擦除部分。
- 我们当然要
CLLocationManager
来确定用户的移动。
一旦CLLocationManager
开始给出位置,我们就使用以下代码
转换相对于MapView图钉位置的坐标
CGPoint pt=[self.map convertCoordinate:location.coordinate toPointToView:self.view];
然后我们传递 CGPoint
,它是 UIView 的转换值,用于清除绘图中的区域,如
[self.drawView eraseAtPoint:pt];
当来自用户坐标的 CGPoint 传递给 DrawView eraseAtPoint
函数时,我们擦除定义半径的区域,并根据需要清除该区域。
我添加了一个示例 directions.gpx
文件来模拟 GPS 位置,示例 GIF 显示了运动。
注意:Link项目将于2017年3月14日后过期,所以请继续下载,在任何情况下如果您希望示例再次在评论中发出提示。随意根据需要进行修改。
更新:
添加擦除圆形而不是正方形区域的功能,只需将 DrawView 中的 drawRect
函数替换为以下代码
- (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;
}
干杯。
我想在mapbox.when中添加模糊效果第一次加载地图时只在地图中显示当前位置其他地图是blue.see截图
当我将用户位置移动到另一个位置时,其他位置在 map.also 特定位置的显示注释上很清楚 看截图
帮助我如何实现这个
这里我将一些实现代码
- (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);
}
在此代码中,我将获得 UserLocation 的完美视图像素点 coordinate.after 我想使用 CGPoint 清除视图中的模糊,但我无法获得 it.i 我想我将创建 CGPoint 数组,然后清除使用线模糊视图但我不能得到它请建议我。
我也用这个库但是我不太了解https://github.com/DenHeadless/Shapes
根据我在评论中添加的逻辑 here I have made a sample for you download it here,检查下面的结果
示例包含以下逻辑。
- 使用iOS地图,在class地图上方添加了自定义UIView
UIView 是
DrawView
它实际上处理所有绘图和 擦除部分。 - 我们当然要
CLLocationManager
来确定用户的移动。 一旦
转换相对于MapView图钉位置的坐标CLLocationManager
开始给出位置,我们就使用以下代码CGPoint pt=[self.map convertCoordinate:location.coordinate toPointToView:self.view];
然后我们传递
CGPoint
,它是 UIView 的转换值,用于清除绘图中的区域,如[self.drawView eraseAtPoint:pt];
当来自用户坐标的 CGPoint 传递给 DrawView
eraseAtPoint
函数时,我们擦除定义半径的区域,并根据需要清除该区域。我添加了一个示例
directions.gpx
文件来模拟 GPS 位置,示例 GIF 显示了运动。
注意:Link项目将于2017年3月14日后过期,所以请继续下载,在任何情况下如果您希望示例再次在评论中发出提示。随意根据需要进行修改。
更新:
添加擦除圆形而不是正方形区域的功能,只需将 DrawView 中的 drawRect
函数替换为以下代码
- (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;
}
干杯。