How to implement text frame overlay on MapView?

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

How to implement text frame overlay on MapView?

Postby thl16888 » Sun Jan 04, 2009 3:51 pm

Would you like to let me know how to implement text frame overlay on Mapview? Thank you very much.
Attachments
text overlay.JPG
text overlay.JPG (64.1 KiB) Viewed 3997 times
thl16888
Junior Developer
Junior Developer
 
Posts: 11
Joined: Tue Nov 04, 2008 2:18 pm

Top

Postby ndroid » Mon Jan 05, 2009 8:33 am

do something like this
Paint paint1 = new Paint();
paint1.setARGB(255, 255, 255, 0);
Paint textPaint = new Paint();
textPaint.setARGB(255, 255, 0, 0);
textPaint.setAntiAlias(true);
textPaint.setFakeBoldText(true);
canvas.drawOval(oval1, paint1);
Paint backPaint = new Paint();
backPaint.setARGB(255, 255, 255, 0);
backPaint.setAntiAlias(true);
RectF backRect = new RectF(point.x + 2 + 5, point.y - 3 * 5, point.x + 65, point.y + 5);
canvas.drawRoundRect(backRect, 5, 5, backPaint);
canvas.drawText(text, point.x + 2 * 5, point.y, textPaint);

in the draw function of the overlay..and you can see the text..
ndroid
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Dec 15, 2008 1:29 pm

Postby thl16888 » Tue Jan 06, 2009 2:07 am

I want to add a static text discription to each marker OverlayItem in ItemizedOverlay. I tried to Override draw procedure of class ItemizedOverlay, but nothing can show up on the mapview. Of course, it can display on Overriding OverLay's draw. But in this case the text does not bind to the mareker. Would you like to help me out? Thank you very much.
thl16888
Junior Developer
Junior Developer
 
Posts: 11
Joined: Tue Nov 04, 2008 2:18 pm

Postby sikus » Mon Mar 09, 2009 2:38 pm

I have the same problem. Do you solve the problem? I can use OverlayItem overlayitem = new OverlayItem(p, "firma", "adresa"); I have got no idea how can I do "the click handler for the OverlayItem". This is sentence from developer third article, 3.
sikus
Junior Developer
Junior Developer
 
Posts: 12
Joined: Mon Dec 15, 2008 3:48 pm

Balloon

Postby androidUser » Wed Apr 15, 2009 8:49 am

Envrionment: SDK1.0

Question:

1) I need to display balloon similarly as you shown in your image text_overlay_878.jpg.

2) Is it possible to add link in the balloon. So that if i click the link in balloon i can goto newIntent screen taking the input of current clicked message.

Please find the below code and the attached output.png, also you can find the attached complete java file.

private void drawInfoWindow(Canvas canvas, MapView mapView, boolean shadow) {

if ( selectedMapLocation != null) {
if ( shadow) {
// Skip painting a shadow in this tutorial
} else {
// First determine the screen coordinates of the selected MapLocation
Point selDestinationOffset = new Point();
mapView.getProjection().toPixels(selectedMapLocation.getPoint(), selDestinationOffset);

// Setup the info window with the right size & location
int INFO_WINDOW_WIDTH = 250;
int INFO_WINDOW_HEIGHT = 50;
RectF infoWindowRect = new RectF(0,0,INFO_WINDOW_WIDTH,INFO_WINDOW_HEIGHT);
int infoWindowOffsetX = selDestinationOffset.x-INFO_WINDOW_WIDTH/2;
int infoWindowOffsetY = selDestinationOffset.y-INFO_WINDOW_HEIGHT-bubbleIcon.getHeight();
infoWindowRect.offset(infoWindowOffsetX,infoWindowOffsetY);


// Draw inner info window
canvas.drawRoundRect(infoWindowRect, 5, 5, getInnerPaint());

// Draw border for info window
canvas.drawRoundRect(infoWindowRect, 5, 5, getBorderPaint());

// Draw the MapLocation's name
int TEXT_OFFSET_X = 10;
int TEXT_OFFSET_Y = 15;

canvas.drawText(selectedMapLocation.getName(),infoWindowOffsetX+TEXT_OFFSET_X,infoWindowOffsetY+TEXT_OFFSET_Y,getTextPaint());


}
}
}
Attachments
MapLocationOverlay.java
(6.38 KiB) Downloaded 186 times
output.PNG
output.PNG (124.11 KiB) Viewed 3948 times
androidUser
Junior Developer
Junior Developer
 
Posts: 24
Joined: Sun Apr 05, 2009 1:08 pm

Balloons

Postby newman » Wed Apr 15, 2009 2:44 pm

hi ,
I need to display balloon similarly as you shown in your image"" text overlay.jpg. ""
can u plz help me with code.
newman
Freshman
Freshman
 
Posts: 5
Joined: Mon Apr 13, 2009 6:02 pm

Top

Re: Balloon

Postby burakkilic » Mon Oct 05, 2009 7:22 am

androidUser wrote:Envrionment: SDK1.0

Question:

1) I need to display balloon similarly as you shown in your image text_overlay_878.jpg.

2) Is it possible to add link in the balloon. So that if i click the link in balloon i can goto newIntent screen taking the input of current clicked message.

Please find the below code and the attached output.png, also you can find the attached complete java file.

private void drawInfoWindow(Canvas canvas, MapView mapView, boolean shadow) {

if ( selectedMapLocation != null) {
if ( shadow) {
// Skip painting a shadow in this tutorial
} else {
// First determine the screen coordinates of the selected MapLocation
Point selDestinationOffset = new Point();
mapView.getProjection().toPixels(selectedMapLocation.getPoint(), selDestinationOffset);

// Setup the info window with the right size & location
int INFO_WINDOW_WIDTH = 250;
int INFO_WINDOW_HEIGHT = 50;
RectF infoWindowRect = new RectF(0,0,INFO_WINDOW_WIDTH,INFO_WINDOW_HEIGHT);
int infoWindowOffsetX = selDestinationOffset.x-INFO_WINDOW_WIDTH/2;
int infoWindowOffsetY = selDestinationOffset.y-INFO_WINDOW_HEIGHT-bubbleIcon.getHeight();
infoWindowRect.offset(infoWindowOffsetX,infoWindowOffsetY);


// Draw inner info window
canvas.drawRoundRect(infoWindowRect, 5, 5, getInnerPaint());

// Draw border for info window
canvas.drawRoundRect(infoWindowRect, 5, 5, getBorderPaint());

// Draw the MapLocation's name
int TEXT_OFFSET_X = 10;
int TEXT_OFFSET_Y = 15;

canvas.drawText(selectedMapLocation.getName(),infoWindowOffsetX+TEXT_OFFSET_X,infoWindowOffsetY+TEXT_OFFSET_Y,getTextPaint());


}
}
}


Could you solve the problem? I added a TableLayout object in the onTap event of the overlay. But it's not beautiful as the shadowed overlay. I am looking for a better way.
burakkilic
Developer
Developer
 
Posts: 37
Joined: Thu Oct 01, 2009 10:24 am

Re: Balloon

Postby bugtester » Sun Nov 01, 2009 7:45 am

burakkilic wrote:
Could you solve the problem? I added a TableLayout object in the onTap event of the overlay. But it's not beautiful as the shadowed overlay. I am looking for a better way.


May I know how do you "Add" a tablelayout to a map?
If your shadowed overlay is not beautiful, could you just do the drawing in draw method when shadow parameter is false?
bugtester
Freshman
Freshman
 
Posts: 8
Joined: Sun Nov 01, 2009 7:42 am

Postby burakkilic » Sun Nov 01, 2009 2:19 pm

I used Inflater finally. But that overlay is not shadowed.
burakkilic
Developer
Developer
 
Posts: 37
Joined: Thu Oct 01, 2009 10:24 am

Postby bugtester » Sun Nov 01, 2009 3:08 pm

burakkilic wrote:I used Inflater finally. But that overlay is not shadowed.



May you share a code snippet that draw the tablelayout view that pin on the map? I can use Drawable object to pin on map as a marker. But I find no way to pin the view, button on a map at specific geopoint location. I notice google map and google places directory work well on drawing view on map and both of them are shadowed too. I am wondering how they can do that.
bugtester
Freshman
Freshman
 
Posts: 8
Joined: Sun Nov 01, 2009 7:42 am

Postby burakkilic » Sun Nov 01, 2009 3:13 pm

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. if(table==null){
  2.  
  3.                                                 table = (LinearLayout)inflater.inflate(R.layout.infooverlay, null);
  4.  
  5.                                                 table.setWillNotDraw(false);
  6.  
  7.                                         }              
  8.  
  9.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


table is an instance of a LinearLayout. and the R.layout.infooverlay is an xml layout file in the resources.
inflater is a LayoutInflater inflater;
burakkilic
Developer
Developer
 
Posts: 37
Joined: Thu Oct 01, 2009 10:24 am

Postby bugtester » Sun Nov 01, 2009 3:54 pm

burakkilic wrote:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. if(table==null){
  2.                                                 table = (LinearLayout)inflater.inflate(R.layout.infooverlay, null);
  3.                                                 table.setWillNotDraw(false);
  4.                                         }              
  5.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


table is an instance of a LinearLayout. and the R.layout.infooverlay is an xml layout file in the resources.
inflater is a LayoutInflater inflater;


Sorry, may you please tell me more about that? I think I have some misunderstanding about using the overlay on a map. My understanding is that when I need to draw things on map, it is required to add Overlay to the MapView.getOverlays(). And in the Overlay class, we have to override the draw method to implement the drawing on the map, so that we have the following code in the overlay class:

Code: Select all
   @Override
   public void draw(Canvas canvas, MapView mapView, boolean shadow) {
      if (shadow == false) {
         Projection projection = mapView.getProjection();
         if(myGeoPoint!=null){
            Point myPoint = new Point();
            projection.toPixels(myGeoPoint, myPoint);
            drawGeoPoint(canvas, myPoint);
         }
      } else {

      }
   }

   private void drawGeoPoint(Canvas canvas, Point point){
      Paint paint = new Paint();
      paint.setARGB(250, 255, 0, 0);
      if(highlighted)
         paint.setARGB(250, 0, 255, 0);         
      paint.setAntiAlias(true);
      paint.setFakeBoldText(true);
      // Create the circle
      int rad = 10;
      RectF oval = new RectF(point.x-rad, point.y-rad,
            point.x+rad, point.y+rad);
      // Draw on the canvas
      canvas.drawOval(oval, paint);
      canvas.drawText(myTitle, point.x+rad, point.y, paint);
      this.hitTestArea = oval; 
   }


I found that your code is inflating a table layout view. But I have no idea about drawing the view on the map in the Draw function. Do I just need to call MapView.addView ? but we cannot specific the position of the view inside the map, and so we cannot pin the view at the specific geopoint. Is there anyway to convert the view to drawable object? So that I can draw that Drawable object in Overlay or ItemizedOverlay?

Thank you very much.
bugtester
Freshman
Freshman
 
Posts: 8
Joined: Sun Nov 01, 2009 7:42 am

Postby burakkilic » Sun Nov 01, 2009 3:58 pm

To draw a view on the map: mapview.addView() method
To add overlays: mapview.getOverlays().add() method.

I advise u to search for these methods.
burakkilic
Developer
Developer
 
Posts: 37
Joined: Thu Oct 01, 2009 10:24 am

Postby bugtester » Sun Nov 01, 2009 4:16 pm

burakkilic wrote:To draw a view on the map: mapview.addView() method
To add overlays: mapview.getOverlays().add() method.

I advise u to search for these methods.


OK. Thanks. It seems that I have misunderstand somethings. actually what I need is to pin a view to a geopoint on a map, so that it works like a marker on a map. (see my attachment)
But may I know, is your table view is pin to a geographic location on map or a static position on the map canvas?
Attachments
transit-android-google-maps.png
transit-android-google-maps.png (36.66 KiB) Viewed 3790 times
bugtester
Freshman
Freshman
 
Posts: 8
Joined: Sun Nov 01, 2009 7:42 am

Postby burakkilic » Sun Nov 01, 2009 4:22 pm

Pin to a geo point on the map. I add it to the overlays of the mapview. And in the onTap method, I get the OverlayItem and pop the layout that I want.
burakkilic
Developer
Developer
 
Posts: 37
Joined: Thu Oct 01, 2009 10:24 am

Top
Next

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 1 guest