I've got a small Processing sketch that uses Unfolding to implement an interactive .mbtiles map. The sketch works fine within Processing, but when I export it and load up the applet I just get a white screen in the applet box. Any ideas how to fix this? I have a hunch it might have to do with the sqlite database that Unfolding uses. Code is below. Thanks!
- import toxi.math.conversion.*;
- import toxi.geom.*;
- import toxi.math.*;
- import toxi.geom.mesh2d.*;
- import toxi.util.datatypes.*;
- import toxi.util.events.*;
- import toxi.geom.mesh.subdiv.*;
- import toxi.geom.mesh.*;
- import toxi.math.waves.*;
- import toxi.util.*;
- import toxi.math.noise.*;
- import processing.opengl.*;
- import codeanticode.glgraphics.*;
- import de.fhpotsdam.unfolding.*;
- import de.fhpotsdam.unfolding.core.*;
- import de.fhpotsdam.unfolding.geo.*;
- import de.fhpotsdam.unfolding.utils.*;
- import de.fhpotsdam.unfolding.providers.*;
- import de.fhpotsdam.unfolding.tiles.MBTilesLoaderUtils;
- import de.fhpotsdam.unfolding.mapdisplay.AbstractMapDisplay;
- import controlP5.*;
- import org.json.*;
- public ArrayList<Polygon2D> polygonListProv = new ArrayList<Polygon2D>();
- public ArrayList<ArrayList<Polygon2D>> polygonListAll = new ArrayList<ArrayList<Polygon2D>>();
- public JSONArray coordinates5;
- public int idpoly;
- public de.fhpotsdam.unfolding.Map map;
- public void setup() {
- size(800, 600, GLConstants.GLGRAPHICS);
- smooth();
- frameRate(240);
- try {
- JSONObject json = new JSONObject(join(loadStrings("bts_prov_ms2.json"), ""));
- JSONArray provinces = json.getJSONArray("features");
- JSONObject pObject = provinces.getJSONObject(0);
- JSONObject geometry = pObject.getJSONObject("geometry");
- JSONArray coordinates1 = geometry.getJSONArray("coordinates");
- ArrayList<Polygon2D> province = new ArrayList<Polygon2D>();
- JSONArray vertex;
- Polygon2D poly;
- JSONArray coordinates2;
- // start the loop over provinces here
- for (int k = 0; k < 33; k++) {
- int idpoly = k;
- //println(polygonListAll.size());
- //println(idpoly);
- pObject = provinces.getJSONObject(idpoly);
- geometry = pObject.getJSONObject("geometry");
- //println(geometry);
- coordinates1 = geometry.getJSONArray("coordinates");
- province = new ArrayList<Polygon2D>();
- // Collect all the polygons for each province
- for (int i = 0; i < coordinates1.length(); i++) {
- //make a new Polygon2D for this province //pyk add
- poly = new Polygon2D(); //pyk add
- //Multi-polygon
- if (coordinates1.length()>1) {
- coordinates2 = coordinates1.getJSONArray(i);
- coordinates5 = coordinates2.getJSONArray(0);
- //Single polygon
- } else {
- coordinates5 = coordinates1.getJSONArray(i);
- }
- // Collect all the vectors for each polygon
- for (int j = 0; j < coordinates5.length(); j++) {
- vertex = coordinates5.getJSONArray(j); //can move this outside all of the loops if needed
- poly.add(new Vec2D((float) vertex.getDouble(1), (float) vertex.getDouble(0))); //pyk add
- }
- //println(poly.getNumPoints());
- province.add(poly);
- //println(poly.getNumPoints());
- }
- polygonListAll.add(province); //pyk add
- int verticesCount = 0;
- for(int i = 0; i<province.size();i++) {
- verticesCount = verticesCount + province.get(i).getNumPoints();
- }
- println("In province " + k + " there are "+province.size()+ " polygons and "+verticesCount+" vertices.");
- }
- }
- catch (JSONException e) {
- println(e.toString());
- println(idpoly);
- }
- //println(idpoly);
- map = new de.fhpotsdam.unfolding.Map(this, new MBTilesMapProvider("jdbc:sqlite:" + dataPath("C:/Users/Eric/Documents/Processing/mapDemo2/data/indonesia_cf4fb2.mbtiles") + ""));
- MapUtils.createDefaultEventDispatcher(this, map);
- //map.setZoomRange(4, 8);
- //map.setTweening(true);
- map.zoomAndPanTo(new Location(-5.0,120.0), 5);
- //map.setBackgroundColor(color(60, 70, 10));
- }
- public void draw() {
- map.draw();
- Location mouseLocation = map.getLocationFromScreenPosition(mouseX, mouseY);
- float mouseLat = mouseLocation.getLat();
- float mouseLon = mouseLocation.getLon();
- Vec2D pnow = new Vec2D(mouseLat, mouseLon);
- fill(0);
- //text(mouseLat + "," + mouseLon, mouseX, mouseY);
- for(ArrayList<Polygon2D> p:polygonListAll) {
- for(Polygon2D q:p) {
- if (q.containsPoint(pnow)) {
- text(polygonListAll.indexOf(p),mouseX,mouseY);
- }
- }
- }
- /*
- if (hover on province) {
- highlight in white?;
- }
- if (single-click on province) {
- map.zoomAndPanTo(new Location(provincePoly.centroid),6);
- }
- */
- }
2