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 8415543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:28:34+00:00 2026-06-10T01:28:34+00:00

I’ve this custom class that extends the Overlay that is being added into my

  • 0

I’ve this custom class that extends the Overlay that is being added into my mapview. i have just one of this class that adds all my polygon and text into this overlay class. However this results in a very slow mapview. I added a draw integer and tested out that this class will draw 84 times each time the ondraw function is being called. Is there any solution that will help to reduce the loading speed of the mapview? Right now the mapview is very slow, each time i move left right or even zoom will be very slow. looking at the android catlog, it seems to me that overlay class ondraw is being called everysecond? should i be looking at another type of layer instead of using overlay?

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) 
{
    shadow=false;
    int numberofdraw= 0;




    //outline 
    Paint paint = new Paint();
    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStrokeWidth(2);
    //paint.setColor(0x10000000);    
    paint.setColor(Color.BLACK); 
    paint.setStyle(Paint.Style.STROKE);
    paint.setAntiAlias(true);
    Point point1_draw = new Point();     

    for (int i =0;i<data.getCustomPolygonList().size();i++)
    {

        CustomPolygon customPolygon= data.getCustomPolygonList().get(i);
        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);
        numberofdraw++;
        //  canvas.clipPath(path, Op.DIFFERENCE);

    }


    //inside sector color
    for (int i =0;i<data.getCustomPolygonList().size();i++)
    {
        CustomPolygon customPolygon= data.getCustomPolygonList().get(i);
        paint = new Paint();
        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setStrokeWidth(2);
        paint.setColor(0x186666ff);    
        //paint.setColor(customPolygon.getColor()); 
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        paint.setAntiAlias(true);
        point1_draw = new Point();     
        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();
        numberofdraw++;
        canvas.drawPath(path, paint);

    }



    //inside sector text
    for (int i =0;i<data.getCustomPolygonList().size();i++)
    {
        CustomPolygon customPolygon= data.getCustomPolygonList().get(i);
        TextPaint paintText = new TextPaint();
        Point   point1 = new Point();     
        String text=customPolygon.getName();

        for(int n=0;n<customPolygon.getCorrdinateList().size();n++)
        {
            if(customPolygon.getTextLocation()!=null)
            {
                paintText.setTextSize(24);
                Rect rect = new Rect();
                paintText.getTextBounds(text, 0, text.length(), rect);
                paintText.setTextAlign(Paint.Align.CENTER);

                paintText.setTypeface(Typeface.DEFAULT_BOLD); 

                paintText.setColor(Color.BLACK);

                GeoPoint sector1 = new GeoPoint((int)(customPolygon.getTextLocation().getLatitude()*1e6), (int)((customPolygon.getTextLocation().getLongitude())*1e6));


                mapView.getProjection().toPixels(sector1, point1);

            }
        }

        numberofdraw++;
        canvas.drawText(text, point1.x, point1.y, paintText);
    }



    Log.e(Config.log_id,"draw no. "+    numberofdraw+"");
}
  • 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-10T01:28:35+00:00Added an answer on June 10, 2026 at 1:28 am

    there are many ways you can improve it, I will suggest you one.

    Buffering:
    For each polygon create a new canvas and a new bitmap

    Canvas myBufferCanvas;
    Bitmap myBufferBitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    myBufferCanvas = new Canvas(myBufferBitmap);
    

    Then only call draw when the polygon is change, call the draw with myBufferCanvas and then call drawBitmap on the true canvas.

    The advantage of this method is performance, it will be extremely fast! The disadvantage is memory, if you have to many polygons, you can kill the device. Just try reusing them some home and you will be fine.
    Just remember that you can apply any transformation to your buffered image without redrawing it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this

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.