Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8316061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:16:21+00:00 2026-06-08T21:16:21+00:00

Recently I have drew a custom polygon around my country by creating a overlay

  • 0

Recently I have drew a custom polygon around my country by creating a overlay class and drew it using path.
I have many sector of a map, each sector is divided and filled with color with a overlay class. However when I use the ontap function, only the last overlay item ontap function get called.

I believe is because I did not set a boundary for the overlay? The following is my overlay code

public class SectorOverlay  extends  Overlay{

CustomPolygon customPolygon =null;
Context context;

public SectorOverlay(Context context, CustomPolygon customPolygon) {
    this.context=context;
    this.customPolygon =customPolygon;
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) 
{
    shadow=false;

    Paint paint = new Paint();
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStrokeWidth(2);
    paint.setColor(0x10000000);     
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
    paint.setAntiAlias(true);
    Point point1_draw = new Point();        

    if(customPolygon!=null)
    {

            Path path = new Path();
            path.setFillType(Path.FillType.EVEN_ODD);
            for(int n=0;n<customPolygon.getCorrdinateList().size();n++)
            {

                GeoPoint sector1 = new GeoPoint((int)(customPolygon.getCorrdinateList().get(n).getLatitude()*1e6), (int)((customPolygon.getCorrdinateList().get(n).getLongitude())*1e6));
                if(n==0){
                    mapView.getProjection().toPixels(sector1, point1_draw);
                    path.moveTo(point1_draw.x,point1_draw.y);
                }else
                {
                    mapView.getProjection().toPixels(sector1, point1_draw);
                    path.lineTo(point1_draw.x,point1_draw.y);
                }
            }

            path.close();
            canvas.drawPath(path, paint);



    }

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


    new CommonOpearation().showToast(context, customPolygon.getName());


return  true;
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:16:22+00:00Added an answer on June 8, 2026 at 9:16 pm

    It is being called for the “last” Overlay, because it is the topmost. MapView draws its overlays from 0..end, but when there is an event, the last drawn is on top, so it gets the event first, and since you return true in Overlay.onTap (same applies to Overlay.onTouchEvent, and practically a lot of Android events) you’re saying that the event is handled, therefore it doesn’t bother calling the overlays down the line. So the event handlers are called in end..0 order.

    I did not use onTap, but according to CommonsWare at Android – Map overlay onTouchEvent / onTap howto? if you use ItemizedOverlay you should get onTap only for your bounded/drawn area.
    It is surely possible that common onTap and onTouchEvents are called for any touch point on screen. In this case you can find the GeoPoint with getProjection from MapView applying it reversly to (x,y) getting (lon,lat). Or using onTap (again, I haven’t heard about this before).

    If you need to do a hit-test with the drawn polygon of the overlay, here’s one which helps zou determine whether the point is in the (not necessarily convex) polygon:
    http://verkkoopetus.cs.utu.fi/vhanke/trakla/PointInPolygon.html

    • for 2. LStart.x = minXOfPolygon, LEnd.x = maxXOfPolygon, LStart.y = LEnd.y = 0
      (you may need extend the line by 1 unit at LStart.x and LEnd.x just to be safe.)
    • for 4. use findIntersection from http://workshop.evolutionzone.com/2007/09/10/code-2d-line-intersection/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I have been reading more and more about people using custom attributes in
Currently I am creating VBA Macros for Excel and recently have started using UserForms.
I'm using Visual Studio 2005 on a Windows XP SP3 machine and recently have
I recently have began using prepared statements again in a web application, and I
I recently have discovered a warning happening in Firefox that says Warning: Unknown pseudo-class
Recently I have been told that static class/methods are evil. Take for example my
Recently I have migrated my project from SQLServer 2000 to MySQL 5.2 using MySQL
Recently I have developed an automation application using WatiN API, in .NET Framework 3.5,
I recently have a project using GSL. After I installed the GSL package on
I have a fair amount of experience using MOQ, while I've recently have stumbled

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.