defaulted layers to off in layer explorer
This commit is contained in:
parent
a33ce36ad4
commit
7aeedbd6ab
10
index.html
10
index.html
@ -16,7 +16,7 @@
|
|||||||
<script type="text/javascript" src="lib/backbone.js"></script>
|
<script type="text/javascript" src="lib/backbone.js"></script>
|
||||||
<script type="text/javascript" src="lib/class.js"></script>
|
<script type="text/javascript" src="lib/class.js"></script>
|
||||||
<script type="text/javascript" src="lib/backbone.cartodb.js"></script>
|
<script type="text/javascript" src="lib/backbone.cartodb.js"></script>
|
||||||
<script type="text/javascript" src="src/wri.js"></script>
|
<script type="text/javascript" src="src/gfw.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var gui;
|
var gui;
|
||||||
function initialize() {
|
function initialize() {
|
||||||
@ -32,14 +32,14 @@
|
|||||||
dat.GUI.DEFAULT_WIDTH = 300;
|
dat.GUI.DEFAULT_WIDTH = 300;
|
||||||
gui = new dat.GUI();
|
gui = new dat.GUI();
|
||||||
|
|
||||||
WRI(function(env) {
|
GFW(function(env) {
|
||||||
WRI.app = new env.app.Instance(map, {
|
GFW.app = new env.app.Instance(map, {
|
||||||
user : 'wri-01',
|
user : 'wri-01',
|
||||||
layerTable : 'layerinfo',
|
layerTable : 'layerinfo',
|
||||||
logging : true
|
logging : true
|
||||||
});
|
});
|
||||||
WRI.app.run();
|
GFW.app.run();
|
||||||
WRI.env = env;
|
GFW.env = env;
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,50 +1,50 @@
|
|||||||
function WRI() {
|
function GFW() {
|
||||||
var args = Array.prototype.slice.call(arguments),
|
var args = Array.prototype.slice.call(arguments),
|
||||||
callback = args.pop(),
|
callback = args.pop(),
|
||||||
modules = (args[0] && typeof args[0] === "string") ? args : args[0],
|
modules = (args[0] && typeof args[0] === "string") ? args : args[0],
|
||||||
config,
|
config,
|
||||||
i;
|
i;
|
||||||
|
|
||||||
if (!(this instanceof WRI)) {
|
if (!(this instanceof GFW)) {
|
||||||
return new WRI(modules, callback);
|
return new GFW(modules, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!modules || modules === '*') {
|
if (!modules || modules === '*') {
|
||||||
modules = [];
|
modules = [];
|
||||||
for (i in WRI.modules) {
|
for (i in GFW.modules) {
|
||||||
if (WRI.modules.hasOwnProperty(i)) {
|
if (GFW.modules.hasOwnProperty(i)) {
|
||||||
modules.push(i);
|
modules.push(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < modules.length; i += 1) {
|
for (i = 0; i < modules.length; i += 1) {
|
||||||
WRI.modules[modules[i]](this);
|
GFW.modules[modules[i]](this);
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(this);
|
callback(this);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
WRI.modules = {};
|
GFW.modules = {};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
WRI.modules.app = function(wri) {
|
GFW.modules.app = function(gfw) {
|
||||||
|
|
||||||
wri.app = {};
|
gfw.app = {};
|
||||||
|
|
||||||
wri.app.Instance = Class.extend(
|
gfw.app.Instance = Class.extend(
|
||||||
{
|
{
|
||||||
init: function(map, options) {
|
init: function(map, options) {
|
||||||
this.options = _.defaults(options, {
|
this.options = _.defaults(options, {
|
||||||
user : 'wri-01',
|
user : 'gfw-01',
|
||||||
layerTable : 'layerinfo',
|
layerTable : 'layerinfo',
|
||||||
});
|
});
|
||||||
|
|
||||||
this._precision = 2;
|
this._precision = 2;
|
||||||
|
|
||||||
wri.log.enabled = options ? options.logging: false;
|
gfw.log.enabled = options ? options.logging: false;
|
||||||
|
|
||||||
this._map = map;
|
this._map = map;
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ WRI.modules.app = function(wri) {
|
|||||||
|
|
||||||
this._cartodb = Backbone.CartoDB({user: this.options.user});
|
this._cartodb = Backbone.CartoDB({user: this.options.user});
|
||||||
|
|
||||||
this.datalayers = new wri.datalayers.Engine(this._cartodb, options.layerTable, this._map);
|
this.datalayers = new gfw.datalayers.Engine(this._cartodb, options.layerTable, this._map);
|
||||||
|
|
||||||
this._setHash();
|
this._setHash();
|
||||||
|
|
||||||
@ -63,13 +63,11 @@ WRI.modules.app = function(wri) {
|
|||||||
run: function() {
|
run: function() {
|
||||||
this._setupListeners();
|
this._setupListeners();
|
||||||
this.update();
|
this.update();
|
||||||
wri.log.info('App is now running!');
|
gfw.log.info('App is now running!');
|
||||||
},
|
},
|
||||||
_setHash: function(){
|
_setHash: function(){
|
||||||
if (location.hash.split("/").length != 3){
|
if (location.hash.split("/").length != 3){
|
||||||
var hash = "#5/0/110"
|
var hash = "#5/0/110"
|
||||||
console.log("HASH RESET");
|
|
||||||
console.log(location.hash);
|
|
||||||
location.replace(hash);
|
location.replace(hash);
|
||||||
this.lastHash = hash;
|
this.lastHash = hash;
|
||||||
}
|
}
|
||||||
@ -127,20 +125,20 @@ WRI.modules.app = function(wri) {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
WRI.modules.maplayer = function(wri) {
|
GFW.modules.maplayer = function(gfw) {
|
||||||
wri.maplayer = {};
|
gfw.maplayer = {};
|
||||||
wri.maplayer.Engine = Class.extend(
|
gfw.maplayer.Engine = Class.extend(
|
||||||
{
|
{
|
||||||
init: function(layer, map) {
|
init: function(layer, map) {
|
||||||
this.layer = layer;
|
this.layer = layer;
|
||||||
this._map = map;
|
this._map = map;
|
||||||
this._bindDisplay(new wri.maplayer.Display());
|
this._bindDisplay(new gfw.maplayer.Display());
|
||||||
this._options = this._display.getOptions(this.layer.get('tileurl'), this.layer.get('ispng'));
|
this._options = this._display.getOptions(this.layer.get('tileurl'), this.layer.get('ispng'));
|
||||||
// this._boundingbox = this.layer.get('the_geom');
|
// this._boundingbox = this.layer.get('the_geom');
|
||||||
var sw = new google.maps.LatLng(this.layer.get('ymin'), this.layer.get('xmin'));
|
var sw = new google.maps.LatLng(this.layer.get('ymin'), this.layer.get('xmin'));
|
||||||
var ne = new google.maps.LatLng(this.layer.get('ymax'),this.layer.get('xmax'));
|
var ne = new google.maps.LatLng(this.layer.get('ymax'),this.layer.get('xmax'));
|
||||||
this._bounds = new google.maps.LatLngBounds(sw, ne);
|
this._bounds = new google.maps.LatLngBounds(sw, ne);
|
||||||
wri.log.info(this._options.getTileUrl({x: 3, y: 4},3));
|
gfw.log.info(this._options.getTileUrl({x: 3, y: 4},3));
|
||||||
this._displayed = false;
|
this._displayed = false;
|
||||||
this._addControll();
|
this._addControll();
|
||||||
this._maptype = new google.maps.ImageMapType(this._options);
|
this._maptype = new google.maps.ImageMapType(this._options);
|
||||||
@ -150,6 +148,11 @@ WRI.modules.maplayer = function(wri) {
|
|||||||
this._setupListeners();
|
this._setupListeners();
|
||||||
|
|
||||||
this._handleLayer();
|
this._handleLayer();
|
||||||
|
|
||||||
|
if (this.layer.get('title') != 'FORMA'){
|
||||||
|
this.layer.attributes['visible'] = false;
|
||||||
|
this._toggleLayer();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_setupListeners: function(){
|
_setupListeners: function(){
|
||||||
var that = this;
|
var that = this;
|
||||||
@ -205,11 +208,11 @@ WRI.modules.maplayer = function(wri) {
|
|||||||
if(this.layer.get('visible') && !this._displayed && this._inView()){
|
if(this.layer.get('visible') && !this._displayed && this._inView()){
|
||||||
this._displayed = true;
|
this._displayed = true;
|
||||||
this._map.overlayMapTypes.setAt(this._tileindex, this._maptype);
|
this._map.overlayMapTypes.setAt(this._tileindex, this._maptype);
|
||||||
wri.log.info(this.layer.get('title')+ " added at "+this._tileindex)
|
gfw.log.info(this.layer.get('title')+ " added at "+this._tileindex)
|
||||||
} else if (this._displayed && !this._inView()){
|
} else if (this._displayed && !this._inView()){
|
||||||
this._displayed = false;
|
this._displayed = false;
|
||||||
this._map.overlayMapTypes.setAt(this._tileindex, null);
|
this._map.overlayMapTypes.setAt(this._tileindex, null);
|
||||||
wri.log.info(this.layer.get('title')+ " removed at "+this._tileindex)
|
gfw.log.info(this.layer.get('title')+ " removed at "+this._tileindex)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_addControll: function(){
|
_addControll: function(){
|
||||||
@ -220,7 +223,7 @@ WRI.modules.maplayer = function(wri) {
|
|||||||
this.toggle
|
this.toggle
|
||||||
.add(this.layer.attributes, 'visible')
|
.add(this.layer.attributes, 'visible')
|
||||||
.onChange(function(value) {
|
.onChange(function(value) {
|
||||||
wri.log.info(value);
|
gfw.log.info(value);
|
||||||
that._toggleLayer();
|
that._toggleLayer();
|
||||||
});
|
});
|
||||||
this.toggle
|
this.toggle
|
||||||
@ -248,11 +251,11 @@ WRI.modules.maplayer = function(wri) {
|
|||||||
_toggleLayer: function(){
|
_toggleLayer: function(){
|
||||||
var that = this;
|
var that = this;
|
||||||
if (this.layer.get('visible') == false){
|
if (this.layer.get('visible') == false){
|
||||||
wri.log.info('LAYER OFF');
|
gfw.log.info('LAYER OFF');
|
||||||
this._map.overlayMapTypes.setAt(this._tileindex, null);
|
this._map.overlayMapTypes.setAt(this._tileindex, null);
|
||||||
//this._map.overlayMapTypes.setAt(this._tileindex, null);
|
//this._map.overlayMapTypes.setAt(this._tileindex, null);
|
||||||
} else {
|
} else {
|
||||||
wri.log.info('LAYER ON');
|
gfw.log.info('LAYER ON');
|
||||||
if(this._inView()){
|
if(this._inView()){
|
||||||
this._displayed = true;
|
this._displayed = true;
|
||||||
this._map.overlayMapTypes.setAt(this._tileindex, this._maptype);
|
this._map.overlayMapTypes.setAt(this._tileindex, this._maptype);
|
||||||
@ -260,13 +263,13 @@ WRI.modules.maplayer = function(wri) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
wri.maplayer.Display = Class.extend(
|
gfw.maplayer.Display = Class.extend(
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructs a new Display with the given DOM element.
|
* Constructs a new Display with the given DOM element.
|
||||||
*/
|
*/
|
||||||
init: function() {
|
init: function() {
|
||||||
wri.log.info('displayed');
|
gfw.log.info('displayed');
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -302,9 +305,9 @@ WRI.modules.maplayer = function(wri) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
WRI.modules.datalayers = function(wri) {
|
GFW.modules.datalayers = function(gfw) {
|
||||||
wri.datalayers = {};
|
gfw.datalayers = {};
|
||||||
wri.datalayers.Engine = Class.extend(
|
gfw.datalayers.Engine = Class.extend(
|
||||||
{
|
{
|
||||||
init: function(CartoDB, layerTable, map) {
|
init: function(CartoDB, layerTable, map) {
|
||||||
this._map = map;
|
this._map = map;
|
||||||
@ -328,9 +331,9 @@ WRI.modules.datalayers = function(wri) {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
_addLayer: function(p){
|
_addLayer: function(p){
|
||||||
wri.log.warn('only showing baselayers for now');
|
gfw.log.warn('only showing baselayers for now');
|
||||||
//if (p.get('category')=='baselayer'){
|
//if (p.get('category')=='baselayer'){
|
||||||
var layer = new wri.maplayer.Engine(p, this._map);
|
var layer = new gfw.maplayer.Engine(p, this._map);
|
||||||
this._dataarray.push(layer);
|
this._dataarray.push(layer);
|
||||||
this._bycartodbid[p.get('cartodb_id')] = layer;
|
this._bycartodbid[p.get('cartodb_id')] = layer;
|
||||||
this._bytitle[p.get('title')] = layer;
|
this._bytitle[p.get('title')] = layer;
|
||||||
@ -340,33 +343,33 @@ WRI.modules.datalayers = function(wri) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logging module that writes log messages to the console and to the Speed
|
* Logging module that gfwtes log messages to the console and to the Speed
|
||||||
* Tracer API. It contains convenience methods for info(), warn(), error(),
|
* Tracer API. It contains convenience methods for info(), warn(), error(),
|
||||||
* and todo().
|
* and todo().
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
WRI.modules.log = function(wri) {
|
GFW.modules.log = function(gfw) {
|
||||||
wri.log = {};
|
gfw.log = {};
|
||||||
|
|
||||||
wri.log.info = function(msg) {
|
gfw.log.info = function(msg) {
|
||||||
wri.log._write('INFO: ' + msg);
|
gfw.log._gfwte('INFO: ' + msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
wri.log.warn = function(msg) {
|
gfw.log.warn = function(msg) {
|
||||||
wri.log._write('WARN: ' + msg);
|
gfw.log._gfwte('WARN: ' + msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
wri.log.error = function(msg) {
|
gfw.log.error = function(msg) {
|
||||||
wri.log._write('ERROR: ' + msg);
|
gfw.log._gfwte('ERROR: ' + msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
wri.log.todo = function(msg) {
|
gfw.log.todo = function(msg) {
|
||||||
wri.log._write('TODO: '+ msg);
|
gfw.log._gfwte('TODO: '+ msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
wri.log._write = function(msg) {
|
gfw.log._gfwte = function(msg) {
|
||||||
var logger = window.console;
|
var logger = window.console;
|
||||||
if (wri.log.enabled) {
|
if (gfw.log.enabled) {
|
||||||
if (logger && logger.markTimeline) {
|
if (logger && logger.markTimeline) {
|
||||||
logger.markTimeline(msg);
|
logger.markTimeline(msg);
|
||||||
}
|
}
|
128
src/mapdig.js
128
src/mapdig.js
@ -1,128 +0,0 @@
|
|||||||
var MAPDIG = {};
|
|
||||||
|
|
||||||
MAPDIG.create = function(carto_user, table_name, ignore, default_width) {
|
|
||||||
var me = {
|
|
||||||
generated_sql: 'SELECT * FROM ' + table_name,
|
|
||||||
SQL: 'SELECT * FROM ' + table_name,
|
|
||||||
table: table_name,
|
|
||||||
carto_user: carto_user,
|
|
||||||
ignore: ['cartodb_id', 'the_geom', 'the_geom_webmercator', 'updated_at', 'created_at'].concat(ignore),
|
|
||||||
numbers: {},
|
|
||||||
strings: {},
|
|
||||||
origin_numbers: {},
|
|
||||||
default_width: default_width
|
|
||||||
};
|
|
||||||
|
|
||||||
me.toSQL = function(){
|
|
||||||
var sql = this.SQL;
|
|
||||||
var filter_sql = [];
|
|
||||||
|
|
||||||
_.each(this.numbers, function(val,key){
|
|
||||||
if (this.origin_numbers[key] != val){
|
|
||||||
var root = key.split(' ')[0]
|
|
||||||
var cap = key.split(' ')[1]
|
|
||||||
if (cap == 'min'){
|
|
||||||
filter_sql.push(root + '>=' + val);
|
|
||||||
} else {
|
|
||||||
filter_sql.push(root + '<=' + val)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
_.each(this.strings, function(val,key){
|
|
||||||
if (val != '*'){
|
|
||||||
filter_sql.push(key + ' LIKE \'%25' + val + '%25\'');
|
|
||||||
}
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
return ((filter_sql.length < 1) ? sql : sql + ' WHERE ' + filter_sql.join(' AND '));
|
|
||||||
};
|
|
||||||
|
|
||||||
me.init = function(cartodb_layer){
|
|
||||||
var c, n1, s1, f1, tmp_dat; // holders for event handlers and reflected columns
|
|
||||||
var that = this;
|
|
||||||
that.layer = cartodb_layer;
|
|
||||||
dat.GUI.DEFAULT_WIDTH = that.default_width;
|
|
||||||
that.gui = new dat.GUI();
|
|
||||||
|
|
||||||
// Direct SQL input
|
|
||||||
c = that.gui.add(that, 'generated_sql').name('Map SQL');
|
|
||||||
c.onFinishChange(function(value) { that.executeSQL(value); });
|
|
||||||
|
|
||||||
// Attempt to reflect table structure and attach controls and events for all columns found
|
|
||||||
// Currently does this long hand as cannot access schema. dumb, but works
|
|
||||||
$.getJSON('http://'+that.carto_user+'.cartodb.com/api/v2/sql/?q=select%20*%20from%20' + that.table +'%20limit%201', function(data){
|
|
||||||
|
|
||||||
// grab the top value in each col, strip ignores
|
|
||||||
var cols = [];
|
|
||||||
_.each(data.rows[0],function(val,key){
|
|
||||||
if (!_.include(that.ignore, key)){
|
|
||||||
cols.push('max("'+key+'") as ' + key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// sample a value from each column to determine GUI element type
|
|
||||||
$.getJSON('http://'+that.carto_user+'.cartodb.com/api/v2/sql/?q=select%20'+cols.join(',') +'%20from%20' + that.table +'%20limit%201', function(data){
|
|
||||||
n1 = that.gui.addFolder('Numeric filter');
|
|
||||||
s1 = that.gui.addFolder('Text filter');
|
|
||||||
_.each(data.rows[0], function(val,key){
|
|
||||||
if(_.isNumber(val)){
|
|
||||||
$.getJSON('http://'+that.carto_user+'.cartodb.com/api/v2/sql/?q=select min("'+key+'"), max("'+key+'") from ' + that.table, function(data){
|
|
||||||
if (data.rows[0].max > data.rows[0].min){
|
|
||||||
//f1 = n1.addFolder(key);
|
|
||||||
|
|
||||||
that.numbers[key+' min'] = data.rows[0].min;
|
|
||||||
that.numbers[key+' max'] = data.rows[0].max;
|
|
||||||
that.origin_numbers[key+' min'] = data.rows[0].min;
|
|
||||||
that.origin_numbers[key+' max'] = data.rows[0].max;
|
|
||||||
|
|
||||||
c = n1.add(that.numbers, key+' min', data.rows[0].min, data.rows[0].max);
|
|
||||||
c.onFinishChange(function(value) { that.renderSQL(); });
|
|
||||||
c = n1.add(that.numbers, key+' max', data.rows[0].min, data.rows[0].max);
|
|
||||||
c.onFinishChange(function(value) { that.renderSQL(); });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// test if it's massive - if so, text box, else dropdown.
|
|
||||||
if(_.isString(val)){
|
|
||||||
$.getJSON('http://'+that.carto_user+'.cartodb.com/api/v2/sql/?q=select count(distinct("'+key+'")) from ' + that.table, function(data){
|
|
||||||
if (data.rows[0].count <= 1000 && data.rows[0].count > 0){
|
|
||||||
$.getJSON('http://'+that.carto_user+'.cartodb.com/api/v2/sql/?q=select distinct("'+key+'") as ele from ' + that.table + ' ORDER BY ELE ASC', function(data){
|
|
||||||
tmp_dat = _.map(data.rows, function(r){ return r.ele; });
|
|
||||||
tmp_dat.unshift('*');
|
|
||||||
that.strings[key] = '*';
|
|
||||||
c = s1.add(that.strings, key, tmp_dat );
|
|
||||||
c.onFinishChange(function(value) { that.renderSQL(); });
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
that.strings[key] = '*';
|
|
||||||
c = s1.add(that.strings,key);
|
|
||||||
c.onFinishChange(function(value) { that.renderSQL(); });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// disabled as buggy
|
|
||||||
//this.gui.remember(this);
|
|
||||||
};
|
|
||||||
|
|
||||||
me.executeSQL = function(sql){
|
|
||||||
this.layer.update(sql);
|
|
||||||
};
|
|
||||||
|
|
||||||
me.renderSQL = function(){
|
|
||||||
this.generated_sql = this.toSQL();
|
|
||||||
for (var i in this.gui.__controllers) {
|
|
||||||
this.gui.__controllers[i].updateDisplay();
|
|
||||||
}
|
|
||||||
this.layer.update(this.generated_sql);
|
|
||||||
};
|
|
||||||
|
|
||||||
return me;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user