Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ColorMap.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ColorMap.java	(revision 29963)
+++ applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ColorMap.java	(revision 29964)
@@ -1,2 +1,15 @@
+/**
+ * This program is free software: you can redistribute it and/or modify it under 
+ * the terms of the GNU 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 General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License along with this program. 
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
 package org.openstreetmap.josm.plugins.elevation;
 
Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ColoredElevationLayer.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ColoredElevationLayer.java	(revision 29963)
+++ 	(revision )
@@ -1,110 +1,0 @@
-package org.openstreetmap.josm.plugins.elevation;
-
-import java.awt.Graphics2D;
-import java.awt.Point;
-import java.util.concurrent.BlockingDeque;
-
-import javax.swing.Action;
-import javax.swing.Icon;
-
-import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.data.Bounds;
-import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
-import org.openstreetmap.josm.gui.MapView;
-import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
-import org.openstreetmap.josm.gui.layer.Layer;
-import org.openstreetmap.josm.plugins.elevation.gui.Triangle;
-import org.openstreetmap.josm.tools.ImageProvider;
-
-public class ColoredElevationLayer extends Layer implements IEleRenderingListener {
-    private GridRenderer gridRenderer;
-    private IVertexRenderer vertexRenderer;
-
-    public ColoredElevationLayer(String name) {
-	super(name);
-
-	// make this layer transparent by 20%
-	setOpacity(0.8);
-	vertexRenderer = new SimpleVertexRenderer();
-    }
-
-    @Override
-    public void paint(Graphics2D g, MapView mv, Bounds box) {
-	if (gridRenderer == null) {
-	    gridRenderer = new GridRenderer(getName(), box, this);
-	    System.out.println("Start renderer...");
-	    Main.worker.submit(gridRenderer);
-	}
-	
-	if (gridRenderer.getVertices().size() > 0) {
-	    BlockingDeque<EleVertex> list = gridRenderer.getVertices();
-	    for (EleVertex eleVertex : list) {
-		Point p0 = mv.getPoint(eleVertex.get(0));
-		Point p1 = mv.getPoint(eleVertex.get(1));
-		Point p2 = mv.getPoint(eleVertex.get(2));
-		Triangle t = new Triangle(p0, p1, p2);
-		
-		// obtain vertex color
-		g.setColor(vertexRenderer.getElevationColor(eleVertex));
-		g.fill(t);
-	    }
-	}
-    }
-
-    @Override
-    public Icon getIcon() {	
-	return ImageProvider.get("layer", "elevation");
-    }
-
-    @Override
-    public String getToolTipText() {
-	return null;
-    }
-
-    @Override
-    public void mergeFrom(Layer from) {
-	// TODO Auto-generated method stub
-
-    }
-
-    @Override
-    public boolean isMergable(Layer other) {
-	// TODO Auto-generated method stub
-	return false;
-    }
-
-    @Override
-    public void visitBoundingBox(BoundingXYVisitor v) {
-	// TODO Auto-generated method stub
-
-    }
-
-    @Override
-    public Object getInfoComponent() {
-	// TODO Auto-generated method stub
-	return null;
-    }
-
-    @Override
-    public Action[] getMenuEntries() {
-	return new Action[] { new LayerListPopup.InfoAction(this) };
-    }
-
-    @Override
-    public void finished(EleVertex vertex) {
-	
-    }
-
-    @Override
-    public void finishedAll() {
-	Main.map.mapView.repaint();	
-    }
-
-    public IVertexRenderer getVertexRenderer() {
-        return vertexRenderer;
-    }
-
-    public void setVertexRenderer(IVertexRenderer vertexRenderer) {
-        this.vertexRenderer = vertexRenderer;
-    }
-}
Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/EleCoordinate.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/EleCoordinate.java	(revision 29963)
+++ 	(revision )
@@ -1,38 +1,0 @@
-package org.openstreetmap.josm.plugins.elevation;
-
-import org.openstreetmap.josm.data.coor.LatLon;
-
-public class EleCoordinate extends LatLon {    
-    /**
-     * 
-     */
-    private static final long serialVersionUID = 9121465585197496570L;
-    
-    private double ele = Double.NaN; 
-
-    public EleCoordinate() {
-	this(Double.NaN, Double.NaN, Double.NaN);
-    }
-    
-    public EleCoordinate(double lat, double lon, double ele) {
-	super(lat, lon);
-	this.ele = ele;
-    }
-    
-    public EleCoordinate(LatLon latLon, double ele) {
-	this(latLon.lat(), latLon.lon(), ele);	
-    }
-
-    /**
-     * Gets the elevation in meter.
-     *
-     * @return the ele
-     */
-    public double getEle() {
-        return ele;
-    }
-  
-    public String toString() {
-        return "EleCoordinate[" + lat() + ", " + lon() + ", " + getEle() + "]";
-    }
-}
Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/EleVertex.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/EleVertex.java	(revision 29963)
+++ 	(revision )
@@ -1,220 +1,0 @@
-package org.openstreetmap.josm.plugins.elevation;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.openstreetmap.josm.data.coor.LatLon;
-
-public class EleVertex {
-    private static final int NPOINTS = 3;
-    private static final double MIN_DIST = 90;
-    
-    private double avrgEle = Double.NaN;
-    private double area = Double.NaN;
-    private EleCoordinate[] points = new EleCoordinate[NPOINTS];
-    
-    public EleVertex(EleCoordinate p1, EleCoordinate p2, EleCoordinate p3) {
-	points[0] = p1;
-	points[1] = p2;
-	points[2] = p3;
-	
-	// compute elevation
-	double z = 0D;
-	boolean eleValid = true;
-	for (EleCoordinate point : points) {
-	    if (ElevationHelper.isValidElevation(p1.getEle())) {
-		z += point.getEle();
-	    } else {
-		eleValid = false;
-		break;
-	    }
-	}
-	
-	if (eleValid) {	
-	    avrgEle = z / NPOINTS;
-	} else {
-	    avrgEle = ElevationHelper.NO_ELEVATION;
-	}
-	
-	// compute the (approx.!) area of the vertex using heron's formula
-	double a = p1.greatCircleDistance(p2);
-	double b = p2.greatCircleDistance(p3);
-	double c = p1.greatCircleDistance(p3);
-	
-	double s = (a + b + c) / 2D;
-	double sq = s * (s - a) * (s - b) * (s - c);
-	area = Math.sqrt(sq);
-    }
-    
-    public List<EleVertex> divide() {
-	TriangleEdge[] edges = new TriangleEdge[NPOINTS];
-	
-	int k = 0;
-	for (int i = 0; i < points.length; i++) {
-	    EleCoordinate c1 = points[i];
-	    
-	    for (int j = i + 1; j < points.length; j++) {
-		EleCoordinate c2 = points[j];
-		
-		edges[k++] = new TriangleEdge(i, j, c1.greatCircleDistance(c2));
-	    }
-	}
-
-	/*
-	for (int i = 0; i < edges.length; i++) {
-	    TriangleEdge triangleEdge = edges[i];
-	    System.out.println("#" + i + ": " +triangleEdge);
-	}*/
-	
-	// sort by distance
-	Arrays.sort(edges);
-	// pick the longest edge
-	TriangleEdge longest = edges[0];
-	
-	
-	//System.out.println("Longest " + longest);
-	EleCoordinate pI = points[longest.getI()];
-	EleCoordinate pJ = points[longest.getJ()];
-	EleCoordinate pK = points[longest.getK()];
-	EleCoordinate newP = getMid(pI, pJ);
-	/*
-	System.out.println(pI);
-	System.out.println(pJ);
-	System.out.println(pK);
-	System.out.println(newP);
-	*/
-	List<EleVertex> res = new ArrayList<EleVertex>();
-	res.add(new EleVertex(pI, pK, newP));
-	res.add(new EleVertex(pJ, pK, newP));
-	
-	return res;
-    }
-    
-    /**
-     * Checks if vertex requires further processing or is finished. Currently this
-     * method returns <code>true</code>, if the average deviation is < 5m 
-     *
-     * @return true, if is finished
-     */
-    public boolean isFinished() {
-	double z = 0D;
-	double avrgEle = getEle();
-	
-	for (EleCoordinate point : points) {
-	    z += (avrgEle - point.getEle()) * (avrgEle - point.getEle());
-	}
-	
-	// TODO: Check for proper limit
-	return /*z < 75 || */getArea() < (30 * 30); // = 3 * 25
-    }    
-    
-    /**
-     * Gets the approximate area of this vertex in square meters.
-     *
-     * @return the area
-     */
-    public double getArea() {
-        return area;
-    }
-
-    /**
-     * Gets the (linear interpolated) mid point of c1 and c2.
-     *
-     * @param c1 the first coordinate
-     * @param c2 the second coordinate
-     * @return the mid point
-     */
-    public EleCoordinate getMid(EleCoordinate c1, EleCoordinate c2) {
-	double x = (c1.getX() + c2.getX()) / 2.0;
-	double y = (c1.getY() + c2.getY()) / 2.0;
-	
-	double z = (c1.getEle() + c2.getEle()) / 2.0;
-	if (c1.greatCircleDistance(c2) > MIN_DIST) {
-	    double hgtZ = ElevationHelper.getElevation(new LatLon(y, x));
-	    
-	    if (ElevationHelper.isValidElevation(hgtZ)) {
-		z = hgtZ;
-	    }	    
-    	}
-	
-	return new EleCoordinate(y, x, z);
-    }
-    
-    /**
-     * Gets the coordinate for the given index.
-     *
-     * @param index the index between 0 and NPOINTS: 
-     * @return the elevation coordinate instance
-     * @throws IllegalArgumentException, if index is invalid
-     */
-    public EleCoordinate get(int index) {
-	if (index < 0 || index >= NPOINTS) throw new IllegalArgumentException("Invalid index: " + index);
-	
-	return points[index];
-    }
-    
-    /**
-     * Gets the average elevation of this vertex.
-     *
-     * @return the ele
-     */
-    public double getEle() {
-	
-	return avrgEle;
-    }
-    
-    @Override
-    public String toString() {
-	return "EleVertex [avrgEle=" + avrgEle + ", area=" + area + ", points="
-		+ Arrays.toString(points) + "]";
-    }
-
-
-
-
-    class TriangleEdge implements Comparable<TriangleEdge> {
-	private int i;
-	private int j;
-	private double dist;
-	
-	public TriangleEdge(int i, int j, double dist) {
-	    super();
-	    this.i = i;
-	    this.j = j;
-	    this.dist = dist;
-	}
-
-	public int getI() {
-	    return i;
-	}
-
-	public int getJ() {
-	    return j;
-	}
-	
-	public int getK() {
-	    if (i == 0) {
-		return j == 1 ? 2 : 1;
-	    } else if (i == 1) {
-		return j == 0 ? 2 : 0;
-	    } else {
-		return j == 0 ? 1 : 0;
-	    }
-	}
-
-	public double getDist() {
-	    return dist;
-	}
-
-	@Override
-	public int compareTo(TriangleEdge o) {
-	    return (int) (o.getDist() - dist);
-	}
-
-	@Override
-	public String toString() {
-	    return "TriangleEdge [i=" + i + ", j=" + j + ", dist=" + dist + "]";
-	}
-    }
-}
Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ElevationProfilePlugin.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ElevationProfilePlugin.java	(revision 29963)
+++ applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ElevationProfilePlugin.java	(revision 29964)
@@ -57,5 +57,5 @@
 	    
 	    // TODO: Disable this view as long as it is not stable
-	    MainMenu.add(Main.main.menu.viewMenu, action, false, 0);
+	    MainMenu.add(Main.main.menu.imagerySubMenu, action, false, 0);
 	} catch (Exception e1) {
 	    System.err.println("Init of ElevationProfilePlugin failed: " + e1);
Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/GridRenderer.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/GridRenderer.java	(revision 29963)
+++ 	(revision )
@@ -1,128 +1,0 @@
-package org.openstreetmap.josm.plugins.elevation;
-
-import static org.openstreetmap.josm.tools.I18n.tr;
-
-import java.awt.Component;
-import java.io.IOException;
-import java.util.List;
-import java.util.concurrent.BlockingDeque;
-import java.util.concurrent.LinkedBlockingDeque;
-
-import org.openstreetmap.josm.data.Bounds;
-import org.openstreetmap.josm.data.coor.LatLon;
-import org.openstreetmap.josm.gui.PleaseWaitRunnable;
-import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
-import org.openstreetmap.josm.gui.progress.ProgressMonitor;
-import org.openstreetmap.josm.io.OsmTransferException;
-import org.xml.sax.SAXException;
-
-public class GridRenderer extends PleaseWaitRunnable {
-    private Bounds box;
-    private IEleRenderingListener listener;
-    
-    private BlockingDeque<EleVertex> toDo = new LinkedBlockingDeque<EleVertex>();
-    private BlockingDeque<EleVertex> vertices = new LinkedBlockingDeque<EleVertex>();
-    
-    private volatile boolean stop = false;
-    
-    public GridRenderer(String title, Bounds box, IEleRenderingListener listener) {
-	this(title, NullProgressMonitor.INSTANCE, true, box, listener);
-    }
-
-    public GridRenderer(String title, boolean ignoreException, Bounds box, IEleRenderingListener listener) {
-	this(title, NullProgressMonitor.INSTANCE, ignoreException, box, listener);
-    }
-
-    public GridRenderer(Component parent, String title,
-	    boolean ignoreException, Bounds box) throws IllegalArgumentException {
-	super(parent, title, ignoreException);
-	
-	this.box = box;
-	initQueue();
-    }
-
-    public GridRenderer(String title, ProgressMonitor progressMonitor,
-	    boolean ignoreException, Bounds box, IEleRenderingListener listener) {
-	super(title, progressMonitor, ignoreException);
-
-	this.box = box;
-	this.listener = listener;
-	initQueue();
-    }
-    
-    /**
-     * Inits the 'todo' queue with the initial vertices.
-     */
-    private void initQueue() {
-	LatLon min = box.getMin();
-	LatLon max = box.getMax();
-	
-	// compute missing coordinates
-	LatLon h1 = new LatLon(min.lat(), max.lon()); 
-	LatLon h2 = new LatLon(max.lat(), min.lon());
-	
-	// compute elevation coords
-	EleCoordinate p0 = new EleCoordinate(min, ElevationHelper.getElevation(min));	
-	EleCoordinate p1 = new EleCoordinate(h1, ElevationHelper.getElevation(h1));
-	EleCoordinate p2 = new EleCoordinate(max, ElevationHelper.getElevation(max));
-	EleCoordinate p3 = new EleCoordinate(h2, ElevationHelper.getElevation(h2));
-		
-	// compute initial vertices
-	EleVertex v1 = new EleVertex(p0, p1, p2);
-	EleVertex v2 = new EleVertex(p2, p3, p0);
-	// enqueue vertices
-	toDo.add(v1);
-	toDo.add(v2);
-	
-	System.out.println("Inited queue");
-    }
-
-    public BlockingDeque<EleVertex> getVertices() {
-        return vertices;
-    }
-
-    @Override
-    protected void cancel() {
-	stop = true;
-    }
-
-    @Override
-    protected void realRun() throws SAXException, IOException,
-	    OsmTransferException {
-	
-	if (stop) return;
-	
-	super.getProgressMonitor().indeterminateSubTask(tr("Render vertices..."));
-	System.out.println("Queue size " + toDo.size());
-	// 
-	while (toDo.size() > 0) {
-	    if (stop) break;
-	    
-	    EleVertex vertex = toDo.poll();
-	    
-	    if (vertex.isFinished()) {		
-		vertices.add(vertex);
-		if (listener !=null) {
-		    listener.finished(vertex);
-		}
-	    } else {
-		List<EleVertex> newV = vertex.divide();
-		for (EleVertex eleVertex : newV) {
-		    System.out.print(".");
-		    toDo.add(eleVertex);
-		}
-	    }
-	}
-	
-	if (listener !=null) {
-	    listener.finishedAll();
-	}
-    }
-
-    @Override
-    protected void finish() {
-	// TODO Auto-generated method stub
-
-    }
-
-}
Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/HgtReader.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/HgtReader.java	(revision 29963)
+++ applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/HgtReader.java	(revision 29964)
@@ -1,2 +1,15 @@
+/**
+ * This program is free software: you can redistribute it and/or modify it under 
+ * the terms of the GNU 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 General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License along with this program. 
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
 package org.openstreetmap.josm.plugins.elevation;
 
@@ -16,5 +29,7 @@
 
 /**
- *  Class HgtReader reads data from SRTM HGT files. Currently this the routines are restricted to a resolution of 3 arc seconds.
+ *  Class HgtReader reads data from SRTM HGT files. Currently this class is restricted to a resolution of 3 arc seconds.
+ *  
+ *  SRTM data files are available at the <a href="http://dds.cr.usgs.gov/srtm/version2_1/SRTM3">NASA SRTM site</a>
  *  @author Oliver Wieland <oliver.wieland@online.de>
  */
Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/IEleRenderingListener.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/IEleRenderingListener.java	(revision 29963)
+++ applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/IEleRenderingListener.java	(revision 29964)
@@ -1,3 +1,18 @@
+/**
+ * This program is free software: you can redistribute it and/or modify it under 
+ * the terms of the GNU 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 General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License along with this program. 
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
 package org.openstreetmap.josm.plugins.elevation;
+
+import org.openstreetmap.josm.plugins.elevation.grid.EleVertex;
 
 public interface IEleRenderingListener {
Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/IVertexRenderer.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/IVertexRenderer.java	(revision 29963)
+++ applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/IVertexRenderer.java	(revision 29964)
@@ -1,5 +1,20 @@
+/**
+ * This program is free software: you can redistribute it and/or modify it under 
+ * the terms of the GNU 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 General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License along with this program. 
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
 package org.openstreetmap.josm.plugins.elevation;
 
 import java.awt.Color;
+
+import org.openstreetmap.josm.plugins.elevation.grid.EleVertex;
 
 /**
Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/SimpleVertexRenderer.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/SimpleVertexRenderer.java	(revision 29963)
+++ 	(revision )
@@ -1,45 +1,0 @@
-/*
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program.
- * If not, see <http://www.gnu.org/licenses/>.
- */
-
-package org.openstreetmap.josm.plugins.elevation;
-
-import java.awt.Color;
-
-/**
- * @author Olli
- *
- */
-public class SimpleVertexRenderer implements IVertexRenderer {
-    private ColorMap cMap = null;
-    
-    /**
-     * 
-     */
-    public SimpleVertexRenderer() {
-	cMap = ColorMap.getMap(ColorMap.getNames()[0]);
-    }
-
-    @Override
-    public Color getElevationColor(EleVertex vertex) {
-	return cMap.getColor((int) vertex.getEle());
-    }
-
-
-    @Override
-    public void selectColorMap(String name) {
-	// TODO Auto-generated method stub
-	
-    }
-    
-}
Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/actions/AddElevationLayerAction.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/actions/AddElevationLayerAction.java	(revision 29963)
+++ applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/actions/AddElevationLayerAction.java	(revision 29964)
@@ -1,2 +1,15 @@
+/**
+ * This program is free software: you can redistribute it and/or modify it under 
+ * the terms of the GNU 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 General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License along with this program. 
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
 package org.openstreetmap.josm.plugins.elevation.actions;
 
@@ -7,5 +20,6 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.JosmAction;
-import org.openstreetmap.josm.plugins.elevation.ColoredElevationLayer;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.plugins.elevation.grid.ElevationGridLayer;
 
 public class AddElevationLayerAction extends JosmAction {
@@ -15,8 +29,8 @@
      */
     private static final long serialVersionUID = -745642875640041385L;
-    private ColoredElevationLayer currentLayer;
+    private Layer currentLayer;
 
     public AddElevationLayerAction() {
-	super(tr("Elevation Map Layer"), "elevation", tr("Shows elevation layer"), null, true);
+	super(tr("Elevation Grid Layer"), "elevation", tr("Shows elevation grid layer"), null, true);
     }
 
@@ -24,5 +38,5 @@
     public void actionPerformed(ActionEvent arg0) {
 	if (currentLayer == null) {
-	    currentLayer = new ColoredElevationLayer(tr("Elevation Map")); // TODO: Better name
+	    currentLayer = new ElevationGridLayer(tr("Elevation Grid")); // TODO: Better name
 	    Main.main.addLayer(currentLayer);
 	}
Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx/ElevationModel.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx/ElevationModel.java	(revision 29963)
+++ applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx/ElevationModel.java	(revision 29964)
@@ -274,8 +274,8 @@
 	    String trackName = (String) trackOrRoute.get("name");
 	    
-	    // no name given, build artificial one
 	    if (trackName == null) {
 		trackName = (String) trackOrRoute.get(GpxData.META_NAME);
 		if (trackName == null) {
+		    // no name given, build artificial one
 		    trackName = name + "." + trackCounter;
 		}
Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/EleCoordinate.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/EleCoordinate.java	(revision 29964)
+++ applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/EleCoordinate.java	(revision 29964)
@@ -0,0 +1,51 @@
+/**
+ * This program is free software: you can redistribute it and/or modify it under 
+ * the terms of the GNU 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 General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License along with this program. 
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openstreetmap.josm.plugins.elevation.grid;
+
+import org.openstreetmap.josm.data.coor.LatLon;
+
+public class EleCoordinate extends LatLon {    
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 9121465585197496570L;
+    
+    private double ele = Double.NaN; 
+
+    public EleCoordinate() {
+	this(Double.NaN, Double.NaN, Double.NaN);
+    }
+    
+    public EleCoordinate(double lat, double lon, double ele) {
+	super(lat, lon);
+	this.ele = ele;
+    }
+    
+    public EleCoordinate(LatLon latLon, double ele) {
+	this(latLon.lat(), latLon.lon(), ele);	
+    }
+
+    /**
+     * Gets the elevation in meter.
+     *
+     * @return the ele
+     */
+    public double getEle() {
+        return ele;
+    }
+  
+    public String toString() {
+        return "EleCoordinate[" + lat() + ", " + lon() + ", " + getEle() + "]";
+    }
+}
Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/EleVertex.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/EleVertex.java	(revision 29964)
+++ applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/EleVertex.java	(revision 29964)
@@ -0,0 +1,234 @@
+/**
+ * This program is free software: you can redistribute it and/or modify it under 
+ * the terms of the GNU 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 General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License along with this program. 
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openstreetmap.josm.plugins.elevation.grid;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.plugins.elevation.ElevationHelper;
+
+public class EleVertex {
+    private static final int NPOINTS = 3;
+    private static final double MIN_DIST = 90;
+    
+    private double avrgEle = Double.NaN;
+    private double area = Double.NaN;
+    private EleCoordinate[] points = new EleCoordinate[NPOINTS];
+    
+    public EleVertex(EleCoordinate p1, EleCoordinate p2, EleCoordinate p3) {
+	points[0] = p1;
+	points[1] = p2;
+	points[2] = p3;
+	
+	// compute elevation
+	double z = 0D;
+	boolean eleValid = true;
+	for (EleCoordinate point : points) {
+	    if (ElevationHelper.isValidElevation(p1.getEle())) {
+		z += point.getEle();
+	    } else {
+		eleValid = false;
+		break;
+	    }
+	}
+	
+	if (eleValid) {	
+	    avrgEle = z / NPOINTS;
+	} else {
+	    avrgEle = ElevationHelper.NO_ELEVATION;
+	}
+	
+	// compute the (approx.!) area of the vertex using heron's formula
+	double a = p1.greatCircleDistance(p2);
+	double b = p2.greatCircleDistance(p3);
+	double c = p1.greatCircleDistance(p3);
+	
+	double s = (a + b + c) / 2D;
+	double sq = s * (s - a) * (s - b) * (s - c);
+	area = Math.sqrt(sq);
+    }
+    
+    public List<EleVertex> divide() {
+	TriangleEdge[] edges = new TriangleEdge[NPOINTS];
+	
+	int k = 0;
+	for (int i = 0; i < points.length; i++) {
+	    EleCoordinate c1 = points[i];
+	    
+	    for (int j = i + 1; j < points.length; j++) {
+		EleCoordinate c2 = points[j];
+		
+		edges[k++] = new TriangleEdge(i, j, c1.greatCircleDistance(c2));
+	    }
+	}
+
+	/*
+	for (int i = 0; i < edges.length; i++) {
+	    TriangleEdge triangleEdge = edges[i];
+	    System.out.println("#" + i + ": " +triangleEdge);
+	}*/
+	
+	// sort by distance
+	Arrays.sort(edges);
+	// pick the longest edge
+	TriangleEdge longest = edges[0];
+	
+	
+	//System.out.println("Longest " + longest);
+	EleCoordinate pI = points[longest.getI()];
+	EleCoordinate pJ = points[longest.getJ()];
+	EleCoordinate pK = points[longest.getK()];
+	EleCoordinate newP = getMid(pI, pJ);
+	/*
+	System.out.println(pI);
+	System.out.println(pJ);
+	System.out.println(pK);
+	System.out.println(newP);
+	*/
+	List<EleVertex> res = new ArrayList<EleVertex>();
+	res.add(new EleVertex(pI, pK, newP));
+	res.add(new EleVertex(pJ, pK, newP));
+	
+	return res;
+    }
+    
+    /**
+     * Checks if vertex requires further processing or is finished. Currently this
+     * method returns <code>true</code>, if the average deviation is < 5m 
+     *
+     * @return true, if is finished
+     */
+    public boolean isFinished() {
+	double z = 0D;
+	double avrgEle = getEle();
+	
+	for (EleCoordinate point : points) {
+	    z += (avrgEle - point.getEle()) * (avrgEle - point.getEle());
+	}
+	
+	// TODO: Check for proper limit
+	return /*z < 75 || */getArea() < (30 * 30); // = 3 * 25
+    }    
+    
+    /**
+     * Gets the approximate area of this vertex in square meters.
+     *
+     * @return the area
+     */
+    public double getArea() {
+        return area;
+    }
+
+    /**
+     * Gets the (linear interpolated) mid point of c1 and c2.
+     *
+     * @param c1 the first coordinate
+     * @param c2 the second coordinate
+     * @return the mid point
+     */
+    public EleCoordinate getMid(EleCoordinate c1, EleCoordinate c2) {
+	double x = (c1.getX() + c2.getX()) / 2.0;
+	double y = (c1.getY() + c2.getY()) / 2.0;
+	
+	double z = (c1.getEle() + c2.getEle()) / 2.0;
+	if (c1.greatCircleDistance(c2) > MIN_DIST) {
+	    double hgtZ = ElevationHelper.getElevation(new LatLon(y, x));
+	    
+	    if (ElevationHelper.isValidElevation(hgtZ)) {
+		z = hgtZ;
+	    }	    
+    	}
+	
+	return new EleCoordinate(y, x, z);
+    }
+    
+    /**
+     * Gets the coordinate for the given index.
+     *
+     * @param index the index between 0 and NPOINTS: 
+     * @return the elevation coordinate instance
+     * @throws IllegalArgumentException, if index is invalid
+     */
+    public EleCoordinate get(int index) {
+	if (index < 0 || index >= NPOINTS) throw new IllegalArgumentException("Invalid index: " + index);
+	
+	return points[index];
+    }
+    
+    /**
+     * Gets the average elevation of this vertex.
+     *
+     * @return the ele
+     */
+    public double getEle() {
+	
+	return avrgEle;
+    }
+    
+    @Override
+    public String toString() {
+	return "EleVertex [avrgEle=" + avrgEle + ", area=" + area + ", points="
+		+ Arrays.toString(points) + "]";
+    }
+
+
+
+
+    class TriangleEdge implements Comparable<TriangleEdge> {
+	private int i;
+	private int j;
+	private double dist;
+	
+	public TriangleEdge(int i, int j, double dist) {
+	    super();
+	    this.i = i;
+	    this.j = j;
+	    this.dist = dist;
+	}
+
+	public int getI() {
+	    return i;
+	}
+
+	public int getJ() {
+	    return j;
+	}
+	
+	public int getK() {
+	    if (i == 0) {
+		return j == 1 ? 2 : 1;
+	    } else if (i == 1) {
+		return j == 0 ? 2 : 0;
+	    } else {
+		return j == 0 ? 1 : 0;
+	    }
+	}
+
+	public double getDist() {
+	    return dist;
+	}
+
+	@Override
+	public int compareTo(TriangleEdge o) {
+	    return (int) (o.getDist() - dist);
+	}
+
+	@Override
+	public String toString() {
+	    return "TriangleEdge [i=" + i + ", j=" + j + ", dist=" + dist + "]";
+	}
+    }
+}
Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/ElevationGridLayer.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/ElevationGridLayer.java	(revision 29964)
+++ applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/ElevationGridLayer.java	(revision 29964)
@@ -0,0 +1,278 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program.
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.openstreetmap.josm.plugins.elevation.grid;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Point;
+
+import javax.swing.Action;
+import javax.swing.Icon;
+
+import org.openstreetmap.gui.jmapviewer.MemoryTileCache;
+import org.openstreetmap.gui.jmapviewer.Tile;
+import org.openstreetmap.gui.jmapviewer.TileController;
+import org.openstreetmap.gui.jmapviewer.interfaces.TileCache;
+import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener;
+import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.Bounds;
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
+import org.openstreetmap.josm.gui.MapView;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.plugins.elevation.IVertexRenderer;
+import org.openstreetmap.josm.tools.ImageProvider;
+
+/**
+ * @author Oliver Wieland <oliver.wieland@online.de>
+ *
+ */
+public class ElevationGridLayer extends Layer implements TileLoaderListener {
+    private static final int ELE_ZOOM_LEVEL = 13;
+    private IVertexRenderer vertexRenderer;    
+    private MemoryTileCache tileCache;
+    protected TileSource tileSource;
+    protected ElevationGridTileLoader tileLoader;
+    protected TileController tileController;
+    
+    private Bounds lastBounds;
+    private TileSet tileSet;
+
+    /**
+     * @param info
+     */
+    public ElevationGridLayer(String name) {
+	super(name);
+	
+	setOpacity(0.8);
+	setBackgroundLayer(true);
+	vertexRenderer = new SimpleVertexRenderer();
+	
+	tileCache = new MemoryTileCache();
+	tileCache.setCacheSize(500);
+	tileSource = new ElevationGridTileSource(name);
+	tileLoader = new ElevationGridTileLoader(this);
+	tileController = new ElevationGridTileController(tileSource, tileCache, this, tileLoader);
+    }
+
+    /* (non-Javadoc)
+     * @see org.openstreetmap.josm.gui.layer.Layer#paint(java.awt.Graphics2D, org.openstreetmap.josm.gui.MapView, org.openstreetmap.josm.data.Bounds)
+     */
+    @Override
+    public void paint(Graphics2D g, MapView mv, Bounds box) {
+	boolean needsNewTileSet = tileSet == null || (lastBounds == null || !lastBounds.equals(box)); 
+	
+	if (needsNewTileSet) {
+	    tileSet = new TileSet(box.getMin(), box.getMax(), ELE_ZOOM_LEVEL); // we use a vector format with constant zoom level
+	    lastBounds = box;
+	    System.out.println("paint " + tileSet);
+	}
+	
+	if (tileSet.insane()) {
+            myDrawString(g, tr("zoom in to load any tiles"), 120, 120);
+            return;
+        } else if (tileSet.tooLarge()) {
+            myDrawString(g, tr("zoom in to load more tiles"), 120, 120);
+            return;
+        } else if (tileSet.tooSmall()) {
+            myDrawString(g, tr("increase zoom level to see more detail"), 120, 120);
+            return;
+        }
+	
+	for(int x = tileSet.x0; x <= tileSet.x1; x++) {
+	    for(int y = tileSet.y0; y <= tileSet.y1; y++) {	
+		Tile t = tileController.getTile(x, y, ELE_ZOOM_LEVEL);
+		
+		if (t != null && t.isLoaded() && t instanceof ElevationGridTile) {
+		    ((ElevationGridTile)t).paintTile(g, mv, vertexRenderer);        		
+		} else {
+		    // give some consolation...
+		    Point topLeft = mv.getPoint(
+			    new LatLon(tileSource.tileYToLat(y, ELE_ZOOM_LEVEL),
+				       tileSource.tileXToLon(x, ELE_ZOOM_LEVEL)));
+		    t.paint(g, topLeft.x, topLeft.y);		    
+		}
+	    }
+	}
+    }
+    
+    
+    
+    /* (non-Javadoc)
+     * @see org.openstreetmap.josm.gui.layer.Layer#getToolTipText()
+     */
+    @Override
+    public String getToolTipText() {
+	// TODO Auto-generated method stub
+	return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.openstreetmap.josm.gui.layer.Layer#visitBoundingBox(org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor)
+     */
+    @Override
+    public void visitBoundingBox(BoundingXYVisitor v) {
+	// TODO Auto-generated method stub
+
+    }
+
+    /* (non-Javadoc)
+     * @see org.openstreetmap.josm.gui.layer.Layer#getMenuEntries()
+     */
+    @Override
+    public Action[] getMenuEntries() {
+	// TODO Auto-generated method stub
+	return null;
+    }
+   
+    @Override
+    public void tileLoadingFinished(Tile tile, boolean success) {
+	try {
+	    //System.out.println("tileLoadingFinished " + tile + ", success = " + success);
+	    if (Main.map != null) {
+		Main.map.repaint(100);
+	    }
+	} catch(Exception ex) {
+	    System.err.println(ex);
+	    ex.printStackTrace(System.err);
+	}
+    }
+
+    @Override
+    public TileCache getTileCache() {
+	// TODO Auto-generated method stub
+	return tileCache;
+    }
+
+    /* (non-Javadoc)
+     * @see org.openstreetmap.josm.gui.layer.Layer#getIcon()
+     */
+    @Override
+    public Icon getIcon() {	
+	return ImageProvider.get("layer", "elevation");
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.openstreetmap.josm.gui.layer.Layer#mergeFrom(org.openstreetmap.josm.gui.layer.Layer)
+     */
+    @Override
+    public void mergeFrom(Layer from) {
+	// TODO Auto-generated method stub
+	
+    }
+
+    /* (non-Javadoc)
+     * @see org.openstreetmap.josm.gui.layer.Layer#isMergable(org.openstreetmap.josm.gui.layer.Layer)
+     */
+    @Override
+    public boolean isMergable(Layer other) {
+	// TODO Auto-generated method stub
+	return false;
+    }
+
+    /* (non-Javadoc)
+     * @see org.openstreetmap.josm.gui.layer.Layer#getInfoComponent()
+     */
+    @Override
+    public Object getInfoComponent() {
+	// TODO Auto-generated method stub
+	return null;
+    }
+    
+    
+    // Stolen from TMSLayer...
+    void myDrawString(Graphics g, String text, int x, int y) {
+        Color oldColor = g.getColor();
+        g.setColor(Color.black);
+        g.drawString(text,x+1,y+1);
+        g.setColor(oldColor);
+        g.drawString(text,x,y);
+    }
+    
+    private class TileSet {
+        int x0, x1, y0, y1;
+        int tileMax = -1;
+
+        /**
+         * Create a TileSet by known LatLon bbox without layer shift correction
+         */
+        public TileSet(LatLon topLeft, LatLon botRight, int zoom) {
+            if (zoom == 0)
+                return;
+
+            x0 = (int)tileSource.lonToTileX(topLeft.lon(),  zoom);
+            y0 = (int)tileSource.latToTileY(topLeft.lat(),  zoom);
+            x1 = (int)tileSource.lonToTileX(botRight.lon(), zoom);
+            y1 = (int)tileSource.latToTileY(botRight.lat(), zoom);
+            if (x0 > x1) {
+                int tmp = x0;
+                x0 = x1;
+                x1 = tmp;
+            }
+            if (y0 > y1) {
+                int tmp = y0;
+                y0 = y1;
+                y1 = tmp;
+            }
+            tileMax = (int)Math.pow(2.0, zoom);
+            if (x0 < 0) {
+                x0 = 0;
+            }
+            if (y0 < 0) {
+                y0 = 0;
+            }
+            if (x1 > tileMax) {
+                x1 = tileMax;
+            }
+            if (y1 > tileMax) {
+                y1 = tileMax;
+            }
+        }
+        
+        int size() {
+            int x_span = x1 - x0 + 1;
+            int y_span = y1 - y0 + 1;
+            return x_span * y_span;
+        }
+
+	@Override
+	public String toString() {
+	    return "TileSet [x0=" + x0 + ", x1=" + x1 + ", y0=" + y0 + ", y1="
+		    + y1 + ", size()=" + size() + ", tilesSpanned()="
+		    + tilesSpanned() + "]";
+	}
+
+	double tilesSpanned() {
+	    return Math.sqrt(1.0 * this.size());
+	}
+
+	boolean tooSmall() {
+	    return this.tilesSpanned() < 1;
+	}
+
+	boolean tooLarge() {
+	    return this.tilesSpanned() > 50;
+	}
+
+	boolean insane() {
+	    return this.tilesSpanned() > 200;
+	}
+    }
+}
Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/ElevationGridTile.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/ElevationGridTile.java	(revision 29964)
+++ applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/ElevationGridTile.java	(revision 29964)
@@ -0,0 +1,155 @@
+package org.openstreetmap.josm.plugins.elevation.grid;
+
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Point;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.concurrent.BlockingDeque;
+import java.util.concurrent.LinkedBlockingDeque;
+
+import org.openstreetmap.gui.jmapviewer.Tile;
+import org.openstreetmap.gui.jmapviewer.interfaces.TileCache;
+import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
+import org.openstreetmap.josm.data.Bounds;
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.gui.MapView;
+import org.openstreetmap.josm.plugins.elevation.ElevationHelper;
+import org.openstreetmap.josm.plugins.elevation.IVertexRenderer;
+import org.openstreetmap.josm.plugins.elevation.gui.Triangle;
+
+public class ElevationGridTile extends Tile {
+    private BlockingDeque<EleVertex> toDo = new LinkedBlockingDeque<EleVertex>();
+    private BlockingDeque<EleVertex> vertices = new LinkedBlockingDeque<EleVertex>();
+
+    private Bounds box;
+    
+    public ElevationGridTile(TileSource source, int xtile, int ytile, int zoom) {
+	super(source, xtile, ytile, zoom);
+
+	box = tile2Bounds(xtile, ytile, zoom);
+	initQueue();
+    }
+
+    public ElevationGridTile(TileSource source, int xtile, int ytile, int zoom,
+	    BufferedImage image) {
+	super(source, xtile, ytile, zoom, image);
+	
+	
+    }
+
+    @Override
+    public void loadPlaceholderFromCache(TileCache cache) {
+	// TODO Auto-generated method stub
+	super.loadPlaceholderFromCache(cache);
+	
+	//System.out.println("loadPlaceholderFromCache");
+    }
+
+    @Override
+    public String getUrl() throws IOException {
+	// TODO Auto-generated method stub
+	return super.getUrl();
+    }
+
+    /**
+     * Use {@link ElevationGridTile#paintTile(Graphics2D, MapView, IVertexRenderer)} to render the tile as grid. This method just issues a debug text.
+     */
+    @Override
+    public void paint(Graphics g, int x, int y) {
+	super.paint(g, x, y);
+	
+	//g.drawString(String.format("EGT %d/%d ", getXtile(), getYtile()), x, y);
+	g.drawString(getStatus(), x, y);
+    }
+    
+    /**
+     * Paints the vertices of this tile.
+     *
+     * @param g the graphics context
+     * @param mv the map view
+     * @param vertexRenderer the vertex renderer
+     */
+    public void paintTile(Graphics2D g, MapView mv, IVertexRenderer vertexRenderer) {
+	BlockingDeque<EleVertex> list = getVertices();
+	for (EleVertex eleVertex : list) {
+	    Point p0 = mv.getPoint(eleVertex.get(0));
+	    Point p1 = mv.getPoint(eleVertex.get(1));
+	    Point p2 = mv.getPoint(eleVertex.get(2));
+	    Triangle shape = new Triangle(p0, p1, p2);
+
+	    // obtain vertex color
+	    g.setColor(vertexRenderer.getElevationColor(eleVertex));
+	    // TODO: Move to renderer
+	    g.fill(shape);
+	}
+    }
+
+    @Override
+    public void loadImage(InputStream input) throws IOException {
+	if (isLoaded()) return;	
+	
+	// We abuse the loadImage method to render the vertices...
+	// 
+	while (toDo.size() > 0) {
+	    EleVertex vertex = toDo.poll();
+	    
+	    if (vertex.isFinished()) {		
+		vertices.add(vertex);
+	    } else {
+		List<EleVertex> newV = vertex.divide();
+		for (EleVertex eleVertex : newV) {
+		    toDo.add(eleVertex);
+		}
+	    }
+	}
+	setLoaded(true);
+    }
+    
+    public BlockingDeque<EleVertex> getVertices() {
+        return vertices;
+    }
+
+    private Bounds tile2Bounds(final int x, final int y, final int zoom) {
+	Bounds bb = new Bounds(
+		new LatLon(source.tileYToLat(y, zoom), source.tileXToLon(x, zoom)),
+		new LatLon(source.tileYToLat(y + 1, zoom), source.tileXToLon(x + 1, zoom)));
+
+	return bb;
+    }
+
+    /**
+     * Inits the 'todo' queue with the initial vertices.
+     */
+    private void initQueue() {
+	LatLon min = box.getMin();
+	LatLon max = box.getMax();
+	
+	// compute missing coordinates
+	LatLon h1 = new LatLon(min.lat(), max.lon()); 
+	LatLon h2 = new LatLon(max.lat(), min.lon());
+	
+	// compute elevation coords
+	EleCoordinate p0 = new EleCoordinate(min, ElevationHelper.getElevation(min));	
+	EleCoordinate p1 = new EleCoordinate(h1, ElevationHelper.getElevation(h1));
+	EleCoordinate p2 = new EleCoordinate(max, ElevationHelper.getElevation(max));
+	EleCoordinate p3 = new EleCoordinate(h2, ElevationHelper.getElevation(h2));
+		
+	// compute initial vertices
+	EleVertex v1 = new EleVertex(p0, p1, p2);
+	EleVertex v2 = new EleVertex(p2, p3, p0);
+	// enqueue vertices
+	toDo.add(v1);
+	toDo.add(v2);
+    }
+
+    @Override
+    public String toString() {
+	return "ElevationGridTile [box=" + box + ", xtile=" + xtile
+		+ ", ytile=" + ytile + "]";
+    }
+    
+    
+}
Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/ElevationGridTileController.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/ElevationGridTileController.java	(revision 29964)
+++ applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/ElevationGridTileController.java	(revision 29964)
@@ -0,0 +1,77 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program.
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.openstreetmap.josm.plugins.elevation.grid;
+
+import org.openstreetmap.gui.jmapviewer.JobDispatcher;
+import org.openstreetmap.gui.jmapviewer.Tile;
+import org.openstreetmap.gui.jmapviewer.TileController;
+import org.openstreetmap.gui.jmapviewer.interfaces.TileCache;
+import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
+import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener;
+import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
+
+/**
+ * Subclass to apply some patches to TileController (see FIXME tags).
+ * @author Olli
+ *
+ */
+public class ElevationGridTileController extends TileController {
+    private JobDispatcher jobDispatcher; // is private and no getter
+    
+    /**
+     * @param source
+     * @param tileCache
+     * @param listener
+     */
+    public ElevationGridTileController(TileSource source, TileCache tileCache,
+	    TileLoaderListener listener, TileLoader loader) {
+	super(source, tileCache, listener);
+	
+	tileSource = source; // FIXME: hard-coded in base class (although parameter is given)!!   
+	tileLoader = loader; // FIXME: hard-coded in base class!
+	jobDispatcher = JobDispatcher.getInstance();
+    }
+    
+    /* (non-Javadoc)
+     * @see org.openstreetmap.gui.jmapviewer.TileController#getTile(int, int, int)
+     */
+    public Tile getTile(int tilex, int tiley, int zoom) {
+        int max = (1 << zoom);
+        if (tilex < 0 || tilex >= max || tiley < 0 || tiley >= max)
+            return null;
+        Tile tile = tileCache.getTile(tileSource, tilex, tiley, zoom);
+        if (tile == null) {
+            // FIXME: Provide/use a factory method here 
+            tile = new ElevationGridTile(tileSource, tilex, tiley, zoom);
+            tileCache.addTile(tile);
+            tile.loadPlaceholderFromCache(tileCache);
+        }
+        if (tile.hasError()) {
+            tile.loadPlaceholderFromCache(tileCache);
+        }
+        if (!tile.isLoaded()) {
+            jobDispatcher.addJob(tileLoader.createTileLoaderJob(tile));
+        }
+        return tile;
+    }
+    
+    /**
+    *
+    */
+   public void cancelOutstandingJobs() {       
+       super.cancelOutstandingJobs(); // should not make a difference but you never know...
+       jobDispatcher.cancelOutstandingJobs();
+   }
+}
Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/ElevationGridTileLoader.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/ElevationGridTileLoader.java	(revision 29964)
+++ applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/ElevationGridTileLoader.java	(revision 29964)
@@ -0,0 +1,68 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program.
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.openstreetmap.josm.plugins.elevation.grid;
+
+import org.openstreetmap.gui.jmapviewer.Tile;
+import org.openstreetmap.gui.jmapviewer.interfaces.TileJob;
+import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
+import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener;
+import org.openstreetmap.josm.tools.CheckParameterUtil;
+
+/**
+ * @author Olli
+ *
+ */
+public class ElevationGridTileLoader implements TileLoader {
+    protected TileLoaderListener listener;
+
+    public ElevationGridTileLoader(TileLoaderListener listener) {
+	CheckParameterUtil.ensureParameterNotNull(listener);
+        this.listener = listener;
+    }
+
+    /* (non-Javadoc)
+     * @see org.openstreetmap.gui.jmapviewer.interfaces.TileLoader#createTileLoaderJob(org.openstreetmap.gui.jmapviewer.Tile)
+     */
+    @Override
+    public TileJob createTileLoaderJob(final Tile tile) {
+	CheckParameterUtil.ensureParameterNotNull(tile);
+	
+	return new TileJob() {
+
+            public void run() {
+                synchronized (tile) {
+                    if ((tile.isLoaded() && !tile.hasError()) || tile.isLoading())
+                        return;
+                    tile.initLoading();
+                }
+                try {
+                    tile.loadImage(null);
+                    tile.setLoaded(true);
+                    listener.tileLoadingFinished(tile, true);
+                } catch (Exception e) {
+                    tile.setError(e.getMessage());
+                    listener.tileLoadingFinished(tile, false);                                        
+                } finally {
+                    tile.finishLoading();
+                }
+            }
+
+            public Tile getTile() {
+                return tile;
+            }
+        };
+    }
+   
+}
Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/ElevationGridTileSource.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/ElevationGridTileSource.java	(revision 29964)
+++ applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/ElevationGridTileSource.java	(revision 29964)
@@ -0,0 +1,77 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program.
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.openstreetmap.josm.plugins.elevation.grid;
+
+import java.io.IOException;
+
+import org.openstreetmap.gui.jmapviewer.tilesources.AbstractTMSTileSource;
+
+/**
+ * @author Olli
+ *
+ */
+public class ElevationGridTileSource extends AbstractTMSTileSource {
+    public ElevationGridTileSource(String name) {
+	super(name, "");
+	// TODO Auto-generated constructor stub
+    }
+
+    @Override
+    public TileUpdate getTileUpdate() {
+	return TileUpdate.None;
+    }
+
+    @Override
+    public String getName() {
+	return "eg";
+    }
+
+    public String getExtension() {
+        return "";
+    }
+
+    /**
+     * @throws IOException when subclass cannot return the tile URL
+     */
+    public String getTilePath(int zoom, int tilex, int tiley) throws IOException {
+        return "/" + zoom + "/" + tilex + "/" + tiley + "." + getExtension();
+    }
+
+    public String getBaseUrl() {
+        return "";
+    }
+
+    @Override
+    public String getTileUrl(int zoom, int tilex, int tiley) throws IOException {
+        return this.getBaseUrl() + getTilePath(zoom, tilex, tiley);
+    }
+
+    @Override
+    public String toString() {
+        return getName();
+    }
+
+    @Override
+    public String getTileType() {
+        return "";
+    }
+
+    @Override
+    public int getTileSize() {
+	// TODO
+        return 256;
+    }
+
+}
Index: applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/SimpleVertexRenderer.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/SimpleVertexRenderer.java	(revision 29964)
+++ applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/grid/SimpleVertexRenderer.java	(revision 29964)
@@ -0,0 +1,48 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program.
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.openstreetmap.josm.plugins.elevation.grid;
+
+import java.awt.Color;
+
+import org.openstreetmap.josm.plugins.elevation.ColorMap;
+import org.openstreetmap.josm.plugins.elevation.IVertexRenderer;
+
+/**
+ * @author Olli
+ *
+ */
+public class SimpleVertexRenderer implements IVertexRenderer {
+    private ColorMap cMap = null;
+    
+    /**
+     * 
+     */
+    public SimpleVertexRenderer() {
+	cMap = ColorMap.getMap(ColorMap.getNames()[0]);
+    }
+
+    @Override
+    public Color getElevationColor(EleVertex vertex) {
+	return cMap.getColor((int) vertex.getEle());
+    }
+
+
+    @Override
+    public void selectColorMap(String name) {
+	// TODO Auto-generated method stub
+	
+    }
+    
+}
Index: applications/editors/josm/plugins/ElevationProfile/test/org/openstreetmap/josm/plugins/elevation/tests/EleVertexTest.java
===================================================================
--- applications/editors/josm/plugins/ElevationProfile/test/org/openstreetmap/josm/plugins/elevation/tests/EleVertexTest.java	(revision 29963)
+++ applications/editors/josm/plugins/ElevationProfile/test/org/openstreetmap/josm/plugins/elevation/tests/EleVertexTest.java	(revision 29964)
@@ -7,11 +7,9 @@
 
 import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.data.Preferences;
 import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.plugins.elevation.ColorMap;
-import org.openstreetmap.josm.plugins.elevation.EleCoordinate;
-import org.openstreetmap.josm.plugins.elevation.EleVertex;
-import org.openstreetmap.josm.plugins.elevation.GridRenderer;
+import org.openstreetmap.josm.plugins.elevation.grid.EleCoordinate;
+import org.openstreetmap.josm.plugins.elevation.grid.EleVertex;
 
 public class EleVertexTest extends TestCase {
@@ -77,5 +75,5 @@
 	}
     }
-    
+    /*
     public void testRenderer() {
 	
@@ -87,5 +85,5 @@
 	
 	er.run();
-    }
+    }*/
     
     public void testColorMap() {
