/* * 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 . */ package org.oscim.renderer.layers; // TODO // 1. rewrite :) // 1.1 test if label is actually visible // 2. compare previous to current state // 2.1 test for new labels to be placed // 2.2 handle collisions // 2.3 try to place labels along a way // 2.4 use 4 point labeling // 3 join segments that belong to one feature // 4 handle zoom-level changes // 5 R-Tree might be handy // import org.oscim.core.MapPosition; import org.oscim.core.Tile; import org.oscim.graphics.Color; import org.oscim.layers.tile.MapTile; import org.oscim.layers.tile.TileRenderLayer; import org.oscim.layers.tile.TileSet; import org.oscim.renderer.GLRenderer.Matrices; import org.oscim.renderer.GLState; import org.oscim.renderer.sublayers.Layer; import org.oscim.renderer.sublayers.Layers; import org.oscim.renderer.sublayers.LineLayer; import org.oscim.renderer.sublayers.LineRenderer; import org.oscim.renderer.sublayers.PolygonRenderer; import org.oscim.renderer.sublayers.TextItem; import org.oscim.renderer.sublayers.TextLayer; import org.oscim.renderer.sublayers.TextureRenderer; import org.oscim.theme.renderinstruction.Line; import org.oscim.utils.FastMath; import org.oscim.utils.OBB2D; import org.oscim.utils.pool.LList; import org.oscim.utils.pool.Pool; import org.oscim.view.MapView; import org.oscim.view.MapViewPosition; import android.opengl.GLES20; import android.os.AsyncTask; import android.os.Handler; import android.os.Looper; public class TextRenderLayer extends BasicRenderLayer { private final static String TAG = TextRenderLayer.class.getName(); private final static float MIN_CAPTION_DIST = 5; private final static float MIN_WAY_DIST = 3; private final static long MAX_RELABEL_DELAY = 200; private final MapViewPosition mMapViewPosition; private final TileSet mTileSet; private MapPosition mTmpPos; // TextLayer that is updating private TextLayer mTmpLayer; // TextLayer that is ready to be added to 'layers' private TextLayer mNextLayer; // thread local pool class LabelPool extends Pool { Label releaseAndGetNext(Label l) { if (l.item != null) TextItem.pool.release(l.item); // drop references l.item = null; l.tile = null; l.string = null; Label ret = (Label) l.next; super.release(l); return ret; } @Override protected TextItem createItem() { return new Label(); } } private final LabelPool mPool = new LabelPool(); // list of previous labels private Label mPrevLabels; // list of current labels private Label mLabels; //private final float[] mTmpCoords = new float[8]; //private final HashMap mActiveTiles; class LabelTile { Tile tile; LList