Android MapView overlay disappearing when zooming in

前端 未结 2 1955
暖寄归人
暖寄归人 2021-01-23 08:23

I\'m working on a simple Android app for plotting routes on a map. All is going well, but I have an issue when zooming in on my Samsung Galaxy S2. It works fine on a Galaxy S3

2条回答
  •  我在风中等你
    2021-01-23 08:59

    The problem is that you are painting the overlay yourself for a very specific state of the mapview. You should use OverlayItem instead.

    The OverlayItem is added to the MapView overlays collection, and the MapView handles all the re-drawing depending on it's own state ( zoom, location, etc )

    @Override
    public void draw( Canvas canvas, MapView mapView, boolean shadow )
    {
        super.draw( canvas, mapView, shadow );
    
        int x1 = -1;
        int y1 = -1;
        int x2 = -1;
        int y2 = -1;
    
        Paint paint = new Paint();
        paint.setStyle( Paint.Style.STROKE );
        paint.setColor( GeoLocation.ROUTE_COLOR );
        paint.setStrokeWidth( STROKE_WIDTH );
    
        for ( int i = 0; i < mRouteGeoPoints.size(); i++ )
        {
            Point point = new Point();
            mapView.getProjection().toPixels( geoPoints.get( i ), point );
            x2 = point.x;
            y2 = point.y;
            if ( i > 0 )
            {
                canvas.drawLine( x1, y1, x2, y2, paint );
            }
            x1 = x2;
            y1 = y2;
        }
    }
    

提交回复
热议问题