<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    super

    android mapView中畫軌跡的overlay


    使用方法:
    LineItemizedOverlay overlay = new LineItemizedOverlay();

    overlay.addOverlay(/*起點的OverlayItem*/);
    overlay.addOverlay(/*終點的OverlayItem*/);
    overlay.addLinePoint(/*要畫的軌跡的GeoPoint的List*/);

    mapView.getOverlays().add(overlay);

    /**
     *
     */
    package com.xtyon.tuola.truck.map;

    import java.util.ArrayList;

    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.graphics.Point;
    import android.graphics.drawable.Drawable;

    import com.google.android.maps.GeoPoint;
    import com.google.android.maps.ItemizedOverlay;
    import com.google.android.maps.MapView;
    import com.google.android.maps.OverlayItem;
    import com.google.android.maps.Projection;

    /**
     * 地圖上的線型圖層:包括一個起點,一個終點,以及之間的曲線
     * @author superwang
     */
    public class LineItemizedOverlay extends ItemizedOverlay<OverlayItem> {
     private static final int LAYER_FLAGS = Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG
       | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG;
     /**
      * 用于保存起點/終點數(shù)據(jù)
      */
     private final ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();

     /**
      * 用于保存構(gòu)成曲線的點的數(shù)據(jù)
      */
     private final ArrayList<GeoPoint> linePoints = new ArrayList<GeoPoint>();

     /**
      * @param defaultMarker
      */
     public LineItemizedOverlay() {
      super(null);

      // TODO Auto-generated constructor stub
     }

     /* (non-Javadoc)
      * @see com.google.android.maps.ItemizedOverlay#createItem(int)
      */
     @Override
     protected OverlayItem createItem(int i) {
      return mOverlays.get(i);

     }

     /* (non-Javadoc)
      * @see com.google.android.maps.ItemizedOverlay#size()
      */
     @Override
     public int size() {
      // TODO Auto-generated method stub
      return mOverlays.size();
     }

     /**
      * 調(diào)價起點/終點
      * description:
      * @param overlay
      */
     public void addOverlay(OverlayItem overlay) {
      mOverlays.add(overlay);
      populate();
     }

     /**
      * 添加曲線中的點
      * description:
      * @param point
      */
     public void addLinePoint(GeoPoint point) {
      linePoints.add(point);
     }

     public ArrayList<GeoPoint> getLinePoints() {
      return linePoints;
     }

     /**
      * 畫起點/終點/軌跡
      */
     @Override
     public void draw(Canvas canvas, MapView mapView, boolean shadow) {
      if (!shadow) {
       //System.out.println("!!!!!!!!!!!!!!");

       canvas.save(LAYER_FLAGS);
       //canvas.save();

       Projection projection = mapView.getProjection();
       int size = mOverlays.size();
       Point point = new Point();
       Paint paint = new Paint();
       paint.setAntiAlias(true);
       OverlayItem overLayItem;

       //畫起點/終點
       for (int i = 0; i < size; i++) {

        overLayItem = mOverlays.get(i);

        Drawable marker = overLayItem.getMarker(0);
        //marker.getBounds()
        /* 象素點取得轉(zhuǎn)換 */
        projection.toPixels(overLayItem.getPoint(), point);

        if (marker != null) {
         boundCenterBottom(marker);
        }

        /* 圓圈 */
        //Paint paintCircle = new Paint();
        //paintCircle.setColor(Color.RED);
        paint.setColor(Color.RED);
        canvas.drawCircle(point.x, point.y, 5, paint);

        /* 文字設(shè)置 */
        /* 標題 */
        String title = overLayItem.getTitle();
        /* 簡介 */
        //    String snippet = overLayItem.getSnippet();
        //
        //    StringBuffer txt = new StringBuffer();
        //    if (title != null && !"".equals(title))
        //     txt.append(title);
        //
        //    if (snippet != null && !"".equals(snippet)) {
        //     if (txt.length() > 0) {
        //      txt.append(":");
        //     }
        //     txt.append(snippet);
        //    }    
        //Paint paintText = new Paint();

        if (title != null && title.length() > 0) {
         paint.setColor(Color.BLACK);
         paint.setTextSize(15);
         canvas.drawText(title, point.x, point.y, paint);
        }

       }

       //畫線

       boolean prevInBound = false;//前一個點是否在可視區(qū)域
       Point prev = null;
       int mapWidth = mapView.getWidth();
       int mapHeight = mapView.getHeight();
       //Paint paintLine = new Paint();
       paint.setColor(Color.RED);
       //paint.setPathEffect(new CornerPathEffect(10));
       paint.setStrokeWidth(2);
       int count = linePoints.size();

       //Path path = new Path();
       //path.setFillType(Path.FillType.INVERSE_WINDING);
       for (int i = 0; i < count; i++) {
        GeoPoint geoPoint = linePoints.get(i);
        //projection.toPixels(geoPoint, point); //這一行似乎有問題
        point = projection.toPixels(geoPoint, null);
        if (prev != null) {
         if (point.x >= 0 && point.x <= mapWidth && point.y >= 0 && point.y <= mapHeight) {
          if ((Math.abs(prev.x - point.x) > 2 || Math.abs(prev.y - point.y) > 2)) {
           //這里判斷點是否重合,重合的不畫線,可能會導(dǎo)致畫線不在路上
           canvas.drawLine(prev.x, prev.y, point.x, point.y, paint);
           //path.lineTo(point.x, point.y);

           prev = point;
           prevInBound = true;

          }
         } else {
          //在可視區(qū)與之外
          if (prevInBound) {//前一個點在可視區(qū)域內(nèi),也需要劃線
           //path.lineTo(point.x, point.y);
           canvas.drawLine(prev.x, prev.y, point.x, point.y, paint);
          }
          prev = point;
          prevInBound = false;
         }
        } else {
         //path.moveTo(point.x, point.y);
         prev = point;

        }
       }
       //canvas.drawPath(path, paint);
       canvas.restore();
       //DebugUtils.showMemory();
      }
      super.draw(canvas, mapView, shadow);
     }

    }

    posted on 2010-08-12 14:21 王衛(wèi)華 閱讀(1680) 評論(0)  編輯  收藏 所屬分類: android


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: h视频在线免费看| 黄色大片免费网站| 精品亚洲A∨无码一区二区三区| 久久久久久A亚洲欧洲AV冫| 在线综合亚洲欧洲综合网站| 久久亚洲国产精品成人AV秋霞 | 一区二区三区在线免费看| 成人国产精品免费视频| 精品亚洲成AV人在线观看| 亚洲最大福利视频网站| 亚洲综合区图片小说区| 亚洲婷婷综合色高清在线| 亚洲国产成人资源在线软件| 亚洲人成在线播放| 亚洲一区二区无码偷拍| 久久久久亚洲精品无码网址色欲 | 亚洲日本香蕉视频| 色偷偷女男人的天堂亚洲网| 精品亚洲成A人无码成A在线观看| 亚洲一级免费视频| 亚洲精品无码久久久久秋霞| 亚洲欧洲日产国码久在线观看| 亚洲国产成人久久精品动漫| 亚洲电影唐人社一区二区| 亚洲中文精品久久久久久不卡| 亚洲a∨无码精品色午夜| 免费看黄福利app导航看一下黄色录像| 青青久久精品国产免费看| 两个人看的www免费视频| 亚洲精品免费在线观看| 无码免费午夜福利片在线| 国产免费午夜a无码v视频| 中文字幕亚洲专区| 亚洲视频在线观看网站| 亚洲国产精品无码久久九九大片| 深夜特黄a级毛片免费播放| 黄色片免费在线观看| 无码免费午夜福利片在线| 亚洲日本中文字幕一区二区三区| 在线jyzzjyzz免费视频| 亚洲精品无码永久在线观看|