// Path: src/com/nutiteq/utils/UtfGridHelper.java
// public static class MBTileUTFGrid {
//     public String[] grid = null;
//     public String[] keys = null;
//     public JSONObject data = null;
// 
//   }


import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import com.nutiteq.components.MapTile;
import com.nutiteq.components.MutableMapPos;
import com.nutiteq.utils.UtfGridHelper.MBTileUTFGrid;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
        .rawQuery("SELECT name,value FROM metadata",null);
    while(c.moveToNext()){
      metadata.put(c.getString(0), c.getString(1));
    } while (c.moveToNext());

    c.close();
    return metadata;
  }
  
/**
 * Query UTFGrid tooltip values from database for given hover/clicked location
 * 
 * @param p position on map, in EPSG3857
 * @param zoom current map zoom
 * @return KV map with data from JSON. If template is given then templated_teaser and templated_full values are added with HTML
 */
public Map<String, String> getUtfGridTooltips(MapTile clickedTile, MutableMapPos tilePos) {
      
    Map<String, String> data = new HashMap<String, String>();

      // what is current tile in clicked location, and specific pixel of this
      int tileSize = 256;
      int zoom = clickedTile.zoom;
      
      int clickedX = (int) (tilePos.x * 256);
      int clickedY = 256 - (int) (tilePos.y * 256);
      
      //Log.debug("clicked on tile "+zoom+"/"+clickedTile.x+"/"+clickedTile.y+" point:"+clickedX+":"+clickedY);

      // get UTFGrid data for the tile
// Path: src/com/nutiteq/utils/UtfGridHelper.java
// public static class MBTileUTFGrid {
//     public String[] grid = null;
//     public String[] keys = null;
//     public JSONObject data = null;
// 
//   }


// Path: src/com/nutiteq/utils/MbTilesDatabaseHelper.java
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import com.nutiteq.components.MapTile;
import com.nutiteq.components.MutableMapPos;
import com.nutiteq.utils.UtfGridHelper.MBTileUTFGrid;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;

        .rawQuery("SELECT name,value FROM metadata",null);
    while(c.moveToNext()){
      metadata.put(c.getString(0), c.getString(1));
    } while (c.moveToNext());

    c.close();
    return metadata;
  }
  
/**
 * Query UTFGrid tooltip values from database for given hover/clicked location
 * 
 * @param p position on map, in EPSG3857
 * @param zoom current map zoom
 * @return KV map with data from JSON. If template is given then templated_teaser and templated_full values are added with HTML
 */
public Map<String, String> getUtfGridTooltips(MapTile clickedTile, MutableMapPos tilePos) {
      
    Map<String, String> data = new HashMap<String, String>();

      // what is current tile in clicked location, and specific pixel of this
      int tileSize = 256;
      int zoom = clickedTile.zoom;
      
      int clickedX = (int) (tilePos.x * 256);
      int clickedY = 256 - (int) (tilePos.y * 256);
      
      //Log.debug("clicked on tile "+zoom+"/"+clickedTile.x+"/"+clickedTile.y+" point:"+clickedX+":"+clickedY);

      // get UTFGrid data for the tile
      MBTileUTFGrid grid = getUTFGrid((int)zoom, clickedTile.x, (1 << (zoom)) - 1 - clickedTile.y);