Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
448 views
in Technique[技术] by (71.8m points)

android - Osmdroid: How to force a map to refresh?

I am displaying a large number of overlays on a map; the process takes 5-10 seconds. Rather than using a progress bar I want the overlays to appear gradually on the map over this time. So for every 25 lines that are calculated I am trying to show them before continuing:

    for (KmlRoad road :roads)
    {
// 25 lines in this array
        Polyline pline = new Polyline();
        pline.getOutlinePaint().setColor(Color.RED);
        pline.setPoints(road.points);
        map.getOverlayManager().add(pline);
        ++roadsShown;
    }
    map.invalidate();
    progressText.setText(roadsShown + " roads");

But nothing happens for a while and then all the overlays (several hundred of them) appear at once. The 'progressText' isn't updated, either.

I have also tried doing the calculation part in an async task, and sending an intent to the map activity for every 25 lines. It gives the same result, unless I add

    SystemClock.sleep(xx);

to to async task, which seems very crude and is only guessing at how long the lines take to draw. Here's the code in the async task, which is called every time 25 lines have been calculated:

private void sendRoads(ArrayList<KmlRoad> roads25)
{
    ArrayList<KmlRoad> theseRoads = new ArrayList<>(roads25);
    // prepare array for next batch while we deal with this one
    roads25.clear();
    Intent intent = new Intent("newRoads");
    intent.putParcelableArrayListExtra("newRoads", theseRoads);
    LocalBroadcastManager.getInstance(activity).sendBroadcast(intent);
    // procSpped is a crude assessment of how slow the device runs,
    // generated by doing  a repeat loop of math functions
    SystemClock.sleep(2 * activity.procSpeed);
}

... and (if using the async method) the receiver in the main activity, which surrounds the line-drawing code above:

private final BroadcastReceiver onNewRoad = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        ArrayList<KmlRoad> roads =  intent.getParcelableArrayListExtra("newRoads");
        ....
        ....
     }
  };

What can I do to make this show as intended?.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...