无法绘制文本地图上叠加作为 [英] Unable to draw text onto map as overlay

查看:95
本文介绍了无法绘制文本地图上叠加作为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加文本标签,我旁边的叠加图像。到目前为止,我可以看到这样做的唯一方法是使用抽签的方法,绘制文本叠加。我这样做,但不知何故,它没有显示我绘制的文本。我的code如下:

I'm trying to add text labels next to my overlay images. So far the only way I can see to do this would be to use the draw method and draw the text as overlay. I did this, but somehow it isn't showing me the drawn text. My code looks like:

 SitesOverlay that extends ItemizedOverlay<OverlayItem>
    public void draw(Canvas canvas, MapView mapView,boolean shadow) {  
    int i;  
    Paint paint=new Paint();  
    paint.setStrokeWidth(1);  
    paint.setARGB(255, 255, 255, 255);  
    paint.setStyle(Paint.Style.STROKE);  
    super.draw(canvas, mapView, shadow);  
    boundCenterBottom(station);  
    canvas.drawText("hullo",28632877,77219722, paint);  
    }  

我在SitesOverlay类的构造函数只是增加了图像到许多不同的GeoPoints。
现在,在我的OnCreate我有这块code的:

My constructor in the SitesOverlay class just adds the images to many different GeoPoints. Now, in my OnCreate I have this piece of code:

 map.getOverlays().add(new SitesOverlay(station));

这是加在我的构造函数的图像列表 - SitesOverlay(站)为叠加结果
我的问题是,既然我已经在SitesOverlay类的Draw方法,而不是在这个构造函数添加我的文字,这是为什么文字不被在地图上绘制?如果是的话我怎么添加文字到地图?

This is adding the list of images in my constructor - SitesOverlay(station) as overlays.
My question is that since I have added my text in the Draw method of the SitesOverlay class and not in this constructor, is this why the text is not being drawn on the map? If so how do I add the text to the map?

不要在绘制的东西画()方法自动添加为覆盖?怎么我认为多数民众赞成在这里引起的问题...
任何其他方式,我可以我旁边的叠加图像添加文本标签?结果
PLZ帮助...

Do the things drawn in the draw() method automatically get added as an overlay? Coz i think thats what is causing the problem here... Any other way I can add text labels next to my overlay images?
Plz help...

推荐答案

试试这个..

MyLocationOverlay myTouchOverlay = new MyLocationOverlay ();
List<Overlay> list1 = myMapView.getOverlays();
list1.add(myTouchOverlay);



class MyLocationOverlay extends com.google.android.maps.Overlay {


@Override
    public boolean onTap(GeoPoint p, MapView    mapView)  {
    }

    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
            long when) {

        super.draw(canvas, mapView, shadow);

        Paint paint = new Paint();
        // Converts lat/lng-Point to OUR coordinates on the screen.
        Point myScreenCoords = new Point();

        mapView.getProjection().toPixels(point, myScreenCoords);
        paint.setStrokeWidth(1);
        paint.setARGB(255, 255, 255, 255);
        paint.setStyle(Paint.Style.STROKE);

        paint.setTextSize(20);
        paint.setColor(Color.RED);
        paint.setStrokeWidth(2);


         canvas.drawText("Here I am...", myScreenCoords.x-10,myScreenCoords.y-48, paint);
        return true;
    }
}

这篇关于无法绘制文本地图上叠加作为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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