Reputation: 25
I tried to save data using SqLite-WebSql and JavaScript to save polygon geometry in wkt format. So far I have managed to save data with the following script:
var db = openDatabase("spatial", "1.0", "local spatial data", 32678);
// Create geodata table if required
db.transaction(function(transaction){
transaction.executeSql("CREATE TABLE IF NOT EXISTS geodata (" +
"fid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT," +
"geom TEXT NOT NULL, type TEXT NOT NULL);");
});
var wkt = 'POLYGON((120.102539 -2.471157,121.003418 -1.878326,121.92627 -2.822346,120.563965 -3.787522,120.102539 -2.471157))';
var type = 'POLYGON';
saveDb(wkt,type);
var saveDb = function(geom, type, successCallback){
db.transaction(function(transaction){
transaction.executeSql(("INSERT INTO geodata (geom, type) VALUES (?, ?);"),
[geom, type]);
});
};
Then I save one more row of additional data and the results are as follows:
id | fid | geom | type
1 | 1 | POLYGON((120.102539 -2.471157,121.003418 -1.878326,121.92627 -2.822346,120.563965 -3.787522,120.102539 -2.471157)) | POLYGON
2 | 2 | POLYGON((121.311035 -2.975956,122.145996 -2.537012,122.651369 -3.655964,121.750488 -4.247814,121.311035 -2.975956)) | POLYGON
The question is how do I select table and generate geojson, then add them to leaflet map as the geojson layer.
Upvotes: 1
Views: 492