Add blur effect to Mapbox

I want to add a blur effect to mapbox.when the first time loading map is that time only displays the current location on the map, the other map is a blue screenshot.

enter image description here

when I move userlocation to a different place than another place clear on the map. Also annotating the display in a specific place see screenshot

enter image description here

help me how to implement this

here i will use the code

- (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); } 

in this code I get the perfect pixel point of view of the UserLocation coordinate. After I want to clear the blur in the view using CGPoint, but I can not get it. I think I will create a CGPoint array and then clean it using the blur line, but I cannot get it by suggesting to me.

I also use this lib, but I can not understand what is needed https://github.com/DenHeadless/Shapes

+5
source share
1 answer

in accordance with the logic that I added in my comment here I made a sample for you, upload it here , check the result below

enter image description here

The sample contains the following logic.

  • Using iOS Map, a custom UIView over Map is added, a class for the UIView DrawView that actually handles all drawings and the eraser.
  • We have a CLLocationManager , of course, to determine the movement of the user.
  • As soon as the CLLocationManager begins to give locations, we will transform the coordinates relative to the location of the MapView contacts using the following code

     CGPoint pt=[self.map convertCoordinate:location.coordinate toPointToView:self.view]; 

    and we pass CGPoint , which is a converted value for UIView, to clear the area in the drawing as

     [self.drawView eraseAtPoint:pt]; 
  • When CGPoint is passed from the user coordinate to the DrawView eraseAtPoint function, we delete the area with a certain radius and clear the area as desired.

  • I added a directions.gpx sample to simulate a GPS location, a GIF sample showing movement.

Note. . The link to the project expires after March 14, 2017 , so keep it loaded, in any case, if you want the sample to ping in the comment again. Feel free to make changes as needed.

Update:

Adding the ability to erase the area in circles instead of squares, just replace the drawRect function in DrawView with the code below

 - (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; } 

Greetings.

+3
source

Source: https://habr.com/ru/post/1262168/


All Articles