使用搜索栏进度动态更改分项叠加绘制圆 [英] dynamically Change Itemized overlay draw circle using seek bar progress

查看:105
本文介绍了使用搜索栏进度动态更改分项叠加绘制圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用地图来制作应用程序。我使用分项叠加
在特定点上绘制圆,它工作得很好。但我想用seekbar进度值改变那个圆的半径。任何机构可以指导我这个
预先感谢。

i m maikng an app using Maps. I m drawing circle on a specific point using itemized overlay and it works pretty fine. But i want to change the radius of that circle with the seekbar progress value. Can any body guide me to this Thanks in advance.

推荐答案

在地图上绘制圆形我们必须使用itemozied Overlay,但要用Seek Bar的进度来改变它我们需要做以下事情,将与Seek Bar一起工作,并且如果你想使用seek bar来设置缩放级别,它将在下面的代码中处理:片段

To Draw the Circle with on map We have to use itemozied Overlay But to change it with the Progress of Seek Bar We need to do the Following thing that will work with Seek Bar and also if you want to set the zoom level using seek bar It is handled in the following code Snippet

注意:I已经使用了最小值为0且最大值为9的搜索栏。b

Note: I have used seek bar with min value of 0 and max value of 9

   public void seekBarProgressEvent()
    {
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub


            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                // TODO Auto-generated method stub
                mapView.getOverlays().clear();

                if(progress==0)
                {
                    zoomLevel=17f;



                }
                else if(progress==1)
                {
                    zoomLevel=16f;



                }
                else if(progress==2)
                {
                    zoomLevel=15f;



                }
                else if(progress==3)
                {
                    zoomLevel=14f;



                }
                else if(progress==4)
                {
                    zoomLevel=14f;



                }
                else if(progress==5)
                {
                    zoomLevel=13.50f;



                }
                else if(progress==6)
                {
                    zoomLevel=13.10f;


                }
                else if(progress==7)
                {
                    zoomLevel=12.85f;


                }
                else if(progress==8)
                {
                    zoomLevel=12.10f;


                }
                else if(progress==9)
                {
                    zoomLevel=11.85f;

                }
                //intent.putExtra("radius", radius);
                //zoomLevel-=seekBar.getProgress();
                Log.i("ZoomLevel", ""+zoomLevel);
                mapView.getController().setZoom((int)zoomLevel);
                Drawable drawable = getApplicationContext().getResources().getDrawable(R.drawable.mapmarker);
// in Itemized overlay i m drawing circle of  Defined Radius like 100m 200m 300m etc
                itemizedoverlay = new FolloowMapOverlay(drawable, getApplicationContext(),(radius));
                MapPoint = new GeoPoint((int)(mylat*1E6), (int)(mylon*1E6));
                OverlayItem overlayitem = new OverlayItem(MapPoint, "Current Location", "");
                currentLocationOverlay = new CurrentLocationOverlay(drawable, getApplicationContext());
                currentLocationOverlay.addOverlay(overlayitem);        
                mapView.getOverlays().add(itemizedoverlay);  
                mapView.getOverlays().add(currentLocationOverlay);  
                mapView.invalidate();
                mapController.setCenter(MapPoint);
                mapController.animateTo(MapPoint);
            }
        });

    }

以下是我的分项叠加类中的Draw Circle方法

The following is my Draw Circle method in my itemized overlay class

 private void drawCircleAtPoint(GeoPoint point, Canvas canvas, MapView mapView) {

        Projection projection = mapView.getProjection();        
        Point pt2 = new Point();
        projection.toPixels(point, pt2);
// method that is used to conver the radius to pixel that takes input the radius and draw it on the coresponding pixels 
        float circleRadius = projection.metersToEquatorPixels(radius) * (1/ FloatMath.cos((float) Math.toRadians(MapController.mylat)));
        Paint circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        Paint rectangle=new Paint(Paint.ANTI_ALIAS_FLAG);
        Log.d("Circular Radius", ""+circleRadius+"             "+radius);

        circlePaint.setColor(0x99000000);
        circlePaint.setStyle(Style.STROKE);
        canvas.drawCircle((float)pt2.x, (float)pt2.y, circleRadius, circlePaint);




    }

这篇关于使用搜索栏进度动态更改分项叠加绘制圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆