- started overlays

- started symbol layer
- move renderer and generator out of view package
  - hopefully the last big refactoring for a while...
- improve perspective, plane should be more far away to decrease foreshortening
This commit is contained in:
Hannes Janetzek
2012-10-09 13:23:15 +02:00
parent 2713f3bc6f
commit 33d8865d7b
128 changed files with 2360 additions and 1417 deletions

View File

@@ -0,0 +1,78 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.generator;
//import static org.oscim.view.mapgenerator.JobTile.LOADING;
import java.util.ArrayList;
import java.util.PriorityQueue;
/**
* A JobQueue keeps the list of pending jobs for a MapView and prioritizes them.
*/
public class JobQueue {
private static final int INITIAL_CAPACITY = 64;
private PriorityQueue<JobTile> mPriorityQueue;
/**
*/
public JobQueue() {
mPriorityQueue = new PriorityQueue<JobTile>(INITIAL_CAPACITY);
}
/**
* @param tiles
* the job to be added to this queue.
*/
public synchronized void setJobs(ArrayList<JobTile> tiles) {
mPriorityQueue.clear();
// mPriorityQueue.addAll(tiles);
for (int i = 0, n = tiles.size(); i < n; i++) {
JobTile tile = tiles.get(i);
// tile.state = LOADING;
tile.isLoading = true;
mPriorityQueue.offer(tile);
}
}
/**
* Removes all jobs from this queue.
*/
public synchronized void clear() {
for (int i = 0, n = mPriorityQueue.size(); i < n; i++) {
JobTile tile = mPriorityQueue.poll();
// tile.state = 0;
tile.isLoading = false;
}
mPriorityQueue.clear();
}
/**
* @return true if this queue contains no jobs, false otherwise.
*/
public synchronized boolean isEmpty() {
return mPriorityQueue.isEmpty();
}
/**
* @return the most important job from this queue or null, if empty.
*/
public synchronized JobTile poll() {
JobTile tile = mPriorityQueue.poll();
return tile;
}
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2012 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.generator;
import org.oscim.core.Tile;
/**
*
*/
public class JobTile extends Tile implements Comparable<JobTile> {
// public final static int LOADING = 1;
// public final static int NEWDATA = 1 << 1;
// public final static int READY = 1 << 2;
// public final static int AVAILABLE = 1 << 1 | 1 << 2;
// public final static int CANCELED = 1 << 3;
// public int state;
/**
* tile is in JobQueue
*/
public boolean isLoading;
/**
* distance from map center.
*/
public float distance;
/**
* @param tileX
* ...
* @param tileY
* ...
* @param zoomLevel
* ..
*/
public JobTile(int tileX, int tileY, byte zoomLevel) {
super(tileX, tileY, zoomLevel);
}
@Override
public int compareTo(JobTile o) {
if (this.distance < o.distance) {
return -1;
}
if (this.distance > o.distance) {
return 1;
}
return 0;
}
}

View File

@@ -0,0 +1,93 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.generator;
import org.oscim.renderer.MapRenderer;
import org.oscim.renderer.TileGenerator;
import org.oscim.utils.PausableThread;
/**
* A MapWorker uses a {@link TileGenerator} to generate map tiles. It runs in a
* separate thread to avoid blocking the UI thread.
*/
public class MapWorker extends PausableThread {
private final String THREAD_NAME;
private final JobQueue mJobQueue;
private final TileGenerator mMapGenerator;
private final MapRenderer mMapRenderer;
/**
* @param id
* thread id
* @param jobQueue
* ...
* @param tileGenerator
* ...
* @param mapRenderer
* ...
*/
public MapWorker(int id, JobQueue jobQueue, TileGenerator tileGenerator,
MapRenderer mapRenderer) {
super();
mJobQueue = jobQueue;
mMapGenerator = tileGenerator;
mMapRenderer = mapRenderer;
THREAD_NAME = "MapWorker" + id;
}
public TileGenerator getMapGenerator() {
return mMapGenerator;
}
@Override
protected void afterRun() {
// empty
}
@Override
protected void doWork() {
JobTile tile = mJobQueue.poll();
if (mMapGenerator == null || tile == null)
return;
boolean success = mMapGenerator.executeJob(tile);
if (!isInterrupted() && success) {
mMapRenderer.passTile(tile);
}
}
@Override
protected String getThreadName() {
return THREAD_NAME;
}
@Override
protected void takeabreak() {
mMapGenerator.getMapDatabase().cancel();
}
@Override
protected int getThreadPriority() {
return (Thread.NORM_PRIORITY + Thread.MIN_PRIORITY) / 3;
}
@Override
protected boolean hasWork() {
return !mJobQueue.isEmpty();
}
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.generator;
import java.util.Comparator;
/**
*
*
*/
public class TileDistanceSort implements Comparator<JobTile> {
@Override
public int compare(JobTile tile1, JobTile tile2) {
if (tile1.distance == tile2.distance)
return 0;
return tile1.distance > tile2.distance ? 1 : -1;
}
}