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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:13:02+00:00 2026-06-16T19:13:02+00:00

I wanted to add some Overlay items to MapsForge at runtime; I can successfully

  • 0

I wanted to add some Overlay items to MapsForge at runtime; I can successfully add them, but they appear only after i move or zoom the map. As it should actually be, since with every moving or zooming, MapsForge manage to redraw the tiles and the overlaying items through the invalidate() function. Anyway, as it is stated here, this is an issue already fixed since MapsForge release 0.2.0: MapView Class should automatically be able to redraw new items whenever they’re added.

I am using MapsForge 0.3.1. Either I am doing something wrong, or this issue reappeared in current release. Here is my code; I reused some code from the official MapsForge Sample activities:

public class MyMapView extends MapView{

    //I brought some variables outside the Sample's function in order to add new items dynamically to the lists
    ListOverlay mListOverlay;
    List<OverlayItem> mOverlayItems;
    Polyline mPolyline;
    Circle mLastPosition;

    //Basically here I do the same actions shown in the MapsForge samples. These items appear at once, with the onCreate() functions of the Activity
    public void addInitialOverlays(){
        Circle circle = createCircle(CENTRAL_STATION);
        Polygon polygon = createPolygon(Arrays.asList(VICTORY_COLUMN, CENTRAL_STATION, BRANDENBURG_GATE));
        mPolyline = createPolyline(Arrays.asList(BRANDENBURG_GATE, VICTORY_COLUMN));
        Marker marker1 = createMarker(R.drawable.marker_red, VICTORY_COLUMN);
        Marker marker2 = createMarker(R.drawable.marker_green, BRANDENBURG_GATE);

        mLastPosition = createCircle(VICTORY_COLUMN);

        mOverlayItems.add(circle);
        mOverlayItems.add(polygon);
        mOverlayItems.add(mPolyline);
        mOverlayItems.add(marker1);
        mOverlayItems.add(marker2);
        mOverlayItems.add(mLastPosition);
        getOverlays().add(mListOverlay);
    }

    //Here is the relevant part. This is called periodically from the main Activity
    public void addPointToRoute(double latitude, double longitude) {

        GeoPoint newPoint = new GeoPoint(latitude, longitude);
        //Tried both removing the list from the overlays and re-adding it, and leaving it where it is; same result
        //getOverlays().remove(mListOverlay);
        mOverlayItems.remove(mPolyline);
        List<GeoPoint> oldPolyline = mPolyline.getPolygonalChain().getGeoPoints();
        oldPolyline.add(newPoint);
        mPolyline = createPolyline(oldPolyline);
        mOverlayItems.add(mPolyline);
        mLastPosition.setGeoPoint(newPoint);
        //getOverlays().add(mListOverlay);

        invalidateOnUiThread();//This MapView function calls either invalidate() or postInvalidate(), depending on the situation
    }
}
  • 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-16T19:13:04+00:00Added an answer on June 16, 2026 at 7:13 pm

    try adding the overlaycontroller after adding the overlay items

    In fact i found out that you can just use another function instead.

    example:

    mapView.getOverlays().add(listOverlay);
    //redraw once overlay items have been added/removed
    mapView.getOverlayController().redrawOverlays(); //method 1
    /**OR**/
    mapView.redraw(); //method 2
    

    hope this helps!

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

Sidebar

Related Questions

I'm looking to add some custom functionality to a VB installation, but I can't
I wanted to add some analytics functionnalities to my app so I created an
I have a table of 26 million records, and wanted to add some columns
I wanted to add <br> after every 2 loops. The loop will run 8
Lets say i wanted to add another variable to the database can anybody tell
I have a UIImageView and I wanted to add a black overlay on top
I wanted to know if there's a way to add some sort of image
I have a lengthy context menu and I wanted to add some visual effect
In continuation of the question at this link I wanted to add some functionality
I am using Zend Framework 1.12. I wanted to add some routers. There are

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.