Using an URL to read SQLite database in Processing/Unfolding Maps
in
Contributed Library Questions
•
1 year ago
I'm stuck in the final stage of a project I've been working for the last weeks. I'm trying to get Processing to display a map I've made with TileMill, which is stored in a .mbtiles SQLite database. So far it has worked pretty fine running the app in the IDE, but when deploying the Applet in my website the DB isn't found. I believe it's because I'm trying to use a URL to get the DB.
I'm using Unfolding Maps. One of its classes uses the sqlitejdbc driver to get the DB. This is my code. If you take a look at the strings JDBC_CONN_STRING_TABLE and JDBC_CONN_STRING_TABLE, those are the ideal paths to connect to the DB. The local one works. The URL doesn't.
Which do you think would be the best way to access the database? Thanks!!
- import de.fhpotsdam.unfolding.mapdisplay.*;
- import de.fhpotsdam.unfolding.utils.*;
- import de.fhpotsdam.unfolding.marker.*;
- import de.fhpotsdam.unfolding.tiles.*;
- import de.fhpotsdam.unfolding.interactions.*;
- import de.fhpotsdam.unfolding.*;
- import de.fhpotsdam.unfolding.core.*;
- import de.fhpotsdam.unfolding.geo.*;
- import de.fhpotsdam.unfolding.events.*;
- import de.fhpotsdam.utils.*;
- import de.fhpotsdam.unfolding.providers.*;
- import processing.opengl.*;
- import codeanticode.glgraphics.GLConstants;
- import java.util.Map;
- de.fhpotsdam.unfolding.Map map;
- public static final String JDBC_CONN_STRING_TABLE = "jdbc:sqlite:http://dansd.com/sflive/SF.mbtiles";
- // Connection to SQLite/MBTiles in dev environment (link to the project)http://dansd.com/sflive/SF.mbtiles
- public static final String JDBC_CONN_STRING_MAC = "jdbc:sqlite:/SF.mbtiles";
- ArrayList coordinates,copyc;
- float[] mightymarblesx, mightymarblesy, rem;
- int timestart, elapsed;
- String[] stations, code,seconds;
- PImage mapa, tram;
- boolean refresh=true;
- PFont fonti;
- void setup() {
- size(1126, 481);
- mapa=loadImage("map.png");
- tram=loadImage("tram.png");
- timestart=second()+minute()*60;
- ArrayList preds=predictionsurl();
- HashMap lista=(HashMap)preds.get(1);
- HashMap thelist=(HashMap)preds.get(0);
- HashMap fleet=listofservices(preds);
- smooth();
- coordinates=coords(lista, fleet);
- mightymarblesx=new float[coordinates.size()];
- mightymarblesy=new float[coordinates.size()];
- seconds=new String[coordinates.size()];
- fonti=loadFont("helb.vlw");
- map = new de.fhpotsdam.unfolding.Map(this, new de.fhpotsdam.unfolding.providers.MBTilesMapProvider(JDBC_CONN_STRING_MAC));
- map.zoomAndPanTo(new Location(37.7664,-122.446),13);
- MapUtils.createDefaultEventDispatcher(this, map);
- map.setZoomRange(12, 16);
- }
- void draw(){
- map.draw();
- elapsed=(second()+minute()*60)-timestart;
- if (elapsed>5) {
- refresh=true;
- }
- updateposition();
- for (int i=0;i<mightymarblesx.length;i++) {
- Location vehloc=new Location(mightymarblesx[i],mightymarblesy[i]);
- float xy[]=map.getScreenPositionFromLocation(vehloc);
- fill(255);
- if (dist(xy[0],xy[1],mouseX,mouseY)<=5){
- fill(255,0,0);
- int longi=-220;
- ellipse(xy[0],xy[1],5,5);
- fill(234,232,232);
- rect(xy[0]-3,xy[1]-3,longi,-70);
- PImage linem=loadImage(seconds[i].split(",")[2].substring(0,1)+".png");
- image(linem,xy[0]+longi+10,xy[1]-60,50,50);
- fill(0);
- text("Will arrive in "+seconds[i].split(",")[0].substring(0,seconds[i].split(",")[0].indexOf("."))+" seconds \nto "+seconds[i].split(",")[1],xy[0]+longi+65,xy[1]-50);
- textFont(fonti,10);
- text("Will arrive in "+seconds[i].split(",")[0].substring(0,seconds[i].split(",")[0].indexOf("."))+" seconds \nto "+seconds[i].split(",")[1],xy[0]+longi+65,xy[1]-50);
- }
- else{
- ellipse(xy[0],xy[1],5,5);
- }
- }
- }
- void updateposition(){
- if (refresh) {
- try{
- if (code[0].equals(loadStrings("ID.csv")[0])==false) {
- code=loadStrings("ID.csv");
- try {
- timestart=second()+minute()*60;
- mightymarblesx=new float[coordinates.size()];
- mightymarblesy=new float[coordinates.size()];
- seconds=new String[coordinates.size()];
- ArrayList preds=predictionsurl();
- HashMap lista=(HashMap)preds.get(1);
- HashMap thelist=(HashMap)preds.get(0);
- HashMap fleet=listofservices(preds);
- coordinates=coords(lista, fleet);
- println("now");
- }
- catch (Exception e) {
- coordinates=copyc;
- }
- }
- }catch (Exception e) {}
- copyc=coordinates;
- refresh=false;
- }
- for(int i=0;i<coordinates.size();i++){
- ArrayList thislist=(ArrayList)coordinates.get(i);
- for(int t=0;t<thislist.size();t++){
- String timestamp=(String)thislist.get(7);
- String[] hour= split(timestamp," ");
- float timebefore= float(hour[0])*60+float(hour[1]);
- float timenow= minute()*60+second();
- float actual=timenow-timebefore;
- String stationcode=(String)thislist.get(0);
- Integer secondas=(Integer)thislist.get(1);
- int secs=secondas.intValue();
- Integer totsecondas=(Integer)thislist.get(2);
- int totseconds=totsecondas.intValue();
- String lat=(String)thislist.get(3);
- String lon=(String)thislist.get(4);
- String lat2=(String)thislist.get(5);
- String lon2=(String)thislist.get(6);
- String name=(String)thislist.get(8);
- String linea=(String)thislist.get(9);
- float cartesianlat=map(secs-actual, totseconds, 0, float(lat), float(lat2));
- float cartesianlon=map(secs-actual, totseconds, 0, float(lon), float(lon2));
- mightymarblesx[i]=cartesianlat;
- mightymarblesy[i]=cartesianlon;
- seconds[i]=str(secs-actual)+","+name+","+linea;
- }
- }
- }
1