Location:

Control Interaction

Map controls include a compass, a scale control, and a zoom button.


Compass, Scale and Zoom Controls

At present, sdk requires the client to define the compass scale and zoom control by itself, the compass and zoom controls are of UIButton type, and the scale is MBScaleView type. The MBScaleView definition method is as follows:

                (For complete code, see MBMapController.m of the SDKDemo project)
                // scale
                scaleView = [[MBScaleView alloc]initWithFrame:CGRectZero];
                [baseMapView addSubview:scaleView];
                scaleView.logo = @"Demo Demo";
                

When the map is rotated, the receiving direction changes the message, and the processing is as follows to implement the compass function.

                    (For complete code, see MBMapController.m of the SDKDemo project)
                    /**
                    * Triggered when using a gesture to rotate the map
                    * @param mapView Current map
                    * @return 空
                    */
                    - (void)mbMapViewOnRotate:(MBMapView *)mapView {
                        CGFloat angle = baseMapView.heading * (M_PI/180);
                        compass.transform = CGAffineTransformMakeRotation(-angle);  
                    }                             
                

When the map is updated, the scale control is updated and processed as follows to display the current scale.

                (For complete code, see MBMapController.m of the SDKDemo project)
                /** Update scale */
                - (void)updateScaleView {
                    CGFloat scale = [baseMapView zoomLevel2Scale:ceil(baseMapView.zoomLevel)];
                    scaleView.pixelSize = [baseMapView meter2Pixel:scale];
                    scaleView.scale = baseMapView.scale;
                }                     
                

When the zoom control is clicked, it is processed as follows to zoom in and out.

                (For complete code, see MBMapController.m of the SDKDemo project)
                - (void)zoomInButtonClick:(float)zoomLevel {
                    [baseMapView setZoomLevel:baseMapView.zoomLevel + 1.0 animated:YES];
                }

                - (void)zoomOutButtonClick:(float)zoomLevel {
                    [baseMapView setZoomLevel:baseMapView.zoomLevel - 1.0 animated:YES];
                }                  
                

TOP