<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)航:
     
    主站蜘蛛池模板: 亚洲AV色吊丝无码| 亚洲乱码一区二区三区在线观看 | 亚洲熟妇无码久久精品| 久久中文字幕免费视频| 亚洲一区精品中文字幕| 麻豆高清免费国产一区| 亚洲无线电影官网| 美女视频黄的全免费视频网站| 亚洲欧洲日产国码二区首页| 免费在线视频你懂的| 亚洲人成在线免费观看| 天天摸天天操免费播放小视频| 亚洲一区AV无码少妇电影| 国产精品国产午夜免费福利看 | 色偷偷亚洲女人天堂观看欧| 西西大胆无码视频免费| 亚洲a∨国产av综合av下载| 亚洲AⅤ视频一区二区三区| 中文字幕无码免费久久9一区9| 亚洲大成色www永久网站| 国产免费丝袜调教视频| 亚洲丶国产丶欧美一区二区三区| 国产免费看插插插视频| 中文字幕版免费电影网站| 亚洲精品视频在线播放| 免费鲁丝片一级观看| 一级免费黄色毛片| 精品亚洲aⅴ在线观看| 免费观看的a级毛片的网站| 精品多毛少妇人妻AV免费久久 | 日本特黄特色aa大片免费| 亚洲免费在线观看| 久久久久亚洲精品日久生情 | 精品亚洲福利一区二区| 国产亚洲精品成人AA片新蒲金| 99精品视频免费在线观看| 精品国产亚洲AV麻豆| 亚洲精品永久www忘忧草| 免费看一级做a爰片久久| 色欲A∨无码蜜臀AV免费播| 久久亚洲精品无码网站|