Permalink
Browse files

first commit

  • Loading branch information...
1 parent 0e25ae5 commit 10d74d2e5db8e94c4e7c42b0123bae7699be4aee @ericspry ericspry committed Nov 29, 2012
View
@@ -0,0 +1,44 @@
+/*other stuff*/
+/*Marker infowindow*/
+div.cartodb_infowindow {position:absolute; display:block; width:214px; padding:0; visibility:hidden;}
+div.cartodb_infowindow a.close {position:absolute; right:3px; top:3px; width:22px; height:15px; padding:4px 0 3px 0; text-align:center; font:bold 15px "Helvetica",Arial; color:#666666; text-decoration:none; line-height:15px}
+div.cartodb_infowindow a.close:hover {color:#333333}
+div.cartodb_infowindow div.outer_top {width:186px; padding:25px 18px 5px 10px; background:url('sprite.png') 0 top;}
+div.cartodb_infowindow div.top {width:186px; max-height:200px; overflow-y:auto; overflow-x:hidden}
+div.cartodb_infowindow div.top .jspTrack {background: #dddddd;}
+div.cartodb_infowindow div.top .jspDrag {background: #999999;}
+div.cartodb_infowindow div.top .jspHover, div.cartodb_infowindow div.top .jspActive {background:#666666}
+div.cartodb_infowindow div.top label {display:block; width:auto; padding:0 0 0 5px; font:normal 11px Arial; color:#B3B3B3; text-shadow:0 1px white}
+div.cartodb_infowindow div.top p {display:block; width:170px; max-height:20px; padding:2px 4px; margin:2px 0 7px; font:bold 11px 'Helvetica',Arial; color:#666666; border:none; background:none; text-shadow:0 1px white;
+ text-overflow:ellipsis; overflow:hidden; white-space:nowrap;}
+div.cartodb_infowindow div.top p.empty {font-weight:normal; font-style:italic; color:#b7b7b7;}
+/*div.cartodb_infowindow div.top p:focus {border:1px solid #666666; border-radius:5px; -webkit-border-radius:5px; -moz-border-radius:5px;}*/
+div.cartodb_infowindow div.bottom {width:180px; height:36px; padding:11px 16px 10px 10px; background:url('sprite.png') no-repeat right top;}
+div.cartodb_infowindow div.bottom label {float:left; margin:5px 0 0 3px; font:normal 11px Arial; color:#B3B3B3; text-shadow:0 1px white}
+div.cartodb_infowindow div.bottom label strong {font:bold 11px 'Helvetica',Arial; color:#666666; text-shadow:0 1px white;}
+div.cartodb_infowindow div.bottom a {float:right; height:12px; margin:0 5px 0 0; padding:4px 7px; border:1px solid #999; font:bold 11px "Helvetica",Arial; color:#333333; text-align:center;
+ text-decoration:none; -webkit-border-radius:3px; -moz-border-radius:3px; border-radius:3px; text-shadow:0 1px white; background:linear-gradient(-90deg, #FFFFFF, #CACBCE); background:-webkit-gradient(linear, 50% 0%, 50% 100%, from(#FFFFFF), to(#CACBCE));
+ background:-moz-linear-gradient(-90deg, #FFFFFF, #CACBCE); background: -o-linear-gradient(#FFFFFF,#CACBCE); filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#FFFFFF', endColorstr='#CACBCE');}
+div.cartodb_infowindow div.bottom a:hover {background:linear-gradient(-90deg, #CACBCE, #FFFFFF); background:-webkit-gradient(linear, 50% 0%, 50% 100%, from(#CACBCE), to(#FFFFFF));
+ background:-moz-linear-gradient(-90deg, #CACBCE, #FFFFFF); background: -o-linear-gradient(#CACBCE,#FFFFFF); filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#CACBCE', endColorstr='#FFFFFF'); cursor:pointer;}
+a.cartodb_logo {position:absolute; bottom:8px; left:175px; display:block; width:69px; height:27px; background:url('http://cartodb.s3.amazonaws.com/embed/embed_sprite.png') no-repeat -61px 0;
+ text-indent:-9999px; line-height:0; font-size:0;}
+div.torque_time {position:absolute; top:130px; left:103px; display:block; width:300px; height:27px;color:white;font-size:32px}
+div.torque_subs {position:absolute; top:165px; left:106px; display:block; height:60px;color:white;font-size:24px;}
+
+.torque_subs dl { overflow: hidden; }
+.torque_subs dt, .torque_subs dd { display: block; float: left; margin: 0; padding: 0; }
+.torque_subs dt { clear: left; color: #FFF; margin: 0 0 15px 0; text-align: left; width: 175px; }
+.torque_subs dd { margin: 0 0 15px 0; width: 400px; }
+
+#hd-pgTitle { color: #fff; font-size: 42px; position: absolute; left: 165px; top: 30px; z-index: 999; }
+#hd-pgSubTitle { color: #fff; font-family: Arial, sans-serif; font-size: 13px; position: absolute; left: 165px; top: 30px; z-index: 999; }
+
+#map_canvas a div>img { left: 103px !important; }
+
+.dg.ac {display:none}
+
+.btn { height: 64px; left: 90px; position: absolute; top: 40px; width: 64px; z-index: 999; }
+.btn.play { background: url('../img/icon-play.png') no-repeat 0 0 transparent; }
+.btn.pause { background: url('../img/icon-pause.png') no-repeat 0 0 transparent; }
+.btn span { display: none; }
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,210 @@
+
+/**
+ *
+ * backbone cartodb adapter
+ *
+ * this is a small library that allows to use Backbone with models
+ * to work with data stored in CartoDB (a geospatial database on
+ * the cloud, see more info at http://cartodb.com).
+ *
+ * it does NOT overrride Backbone.sync
+ *
+ */
+
+Backbone.CartoDB = function(options, query, cache) {
+
+ options = _.defaults(options, {
+ USE_PROXY: false,
+ user: ''
+ });
+
+ function _SQL(sql) {
+ this.sql = sql;
+ }
+ function SQL(sql) {
+ return new _SQL(sql);
+ }
+
+ // SQL("{0} is {1}").format("CartoDB", "epic!");
+ _SQL.prototype.format = function() {
+ var str = this.sql,
+ len = arguments.length+1;
+ var safe, arg;
+ for (i=0; i < len; arg = arguments[i++]) {
+ safe = typeof arg === 'object' ? JSON.stringify(arg) : arg;
+ str = str.replace(RegExp('\\{'+(i-1)+'\\}', 'g'), safe);
+ }
+ return str;
+ };
+
+
+ var resource_path= options.user + '.cartodb.com/api/v2/sql';
+ var resource_url = 'https://' + resource_path;
+
+ /**
+ * fetch sql from the server
+ *
+ * this function should be changed if you're working on node
+ *
+ */
+ query = query || function(sql, callback, proxy) {
+ var url = resource_url;
+ var crossDomain = true;
+ if(proxy) {
+ url = 'api/v0/proxy/' + resource_url;
+ crossDomain = false;
+ }
+ if(sql.length > 1500) {
+ $.ajax({
+ url: url,
+ crossDomain: crossDomain,
+ type: 'POST',
+ dataType: 'json',
+ data: 'q=' + encodeURIComponent(sql),
+ success: callback,
+ error: function(){
+ if(proxy) {
+ callback();
+ } else {
+ //try fallback
+ if(USE_PROXY) {
+ query(sql, callback, true);
+ }
+ }
+ }
+ });
+ } else {
+ // TODO: add timeout
+ $.getJSON(resource_url + '?q=' + encodeURIComponent(sql) + '&callback=?')
+ .success(callback)
+ .fail(function(){
+ callback();
+ }).complete(function() {
+ });
+ }
+ };
+
+ var dummy_cache = {
+ setItem: function(key, value) { },
+ getItem: function(key) { return null; },
+ removeItem: function(key) { }
+ };
+
+ cache = cache && dummy_cache;
+
+
+ var CartoDBModel = Backbone.Model.extend({
+
+ _create_sql: function() {
+ var where = SQL(" where {0} = '{1}'").format(
+ this.columns[this.what],
+ this.get(this.what).replace("'", "''")
+ );
+ var select = this._sql_select();
+ var sql = 'select ' + select.join(',') + ' from ' + this.table + where;
+ return sql;
+ },
+
+ _sql_select: function() {
+ var select = [];
+ for(var k in this.columns) {
+ var w = this.columns[k];
+ if(w.indexOf('ST_') !== -1 || w === "the_geom") {
+ select.push(SQL('ST_AsGeoJSON({1}) as {0}').format(k,w));
+ } else {
+ select.push(SQL('{1} as {0}').format(k, w));
+ }
+ }
+ return select;
+ },
+
+ _parse_columns: function(row) {
+ var parsed = {};
+ for(var k in row) {
+ var v = row[k];
+ var c = this.columns[k];
+ if (c.indexOf('ST_') !== -1 || c === "the_geom") {
+ parsed[k] = JSON.parse(v);
+ } else {
+ parsed[k] = row[k];
+ }
+ }
+ return parsed;
+ },
+
+ fetch: function() {
+ var self = this;
+ query(this._create_sql(), function(data) {
+ self.set(self._parse_columns(data.rows[0]));
+ });
+ }
+ });
+
+
+ /**
+ * cartodb collection created from a sql composed using 'columns' and
+ * 'table' attributes defined in a child class
+ *
+ * var C = CartoDBCollection.extend({
+ * table: 'table',
+ * columns: ['c1', 'c2']
+ * });
+ * var c = new C();
+ * c.fetch();
+ */
+ var CartoDBCollection = Backbone.Collection.extend({
+
+ _create_sql: function() {
+ var tables = this.table;
+ if(!_.isArray(this.table)) {
+ tables = [this.table];
+ }
+ tables = tables.join(',');
+ var select = CartoDBModel.prototype._sql_select.call(this);
+ var sql = 'select ' + select.join(',') + ' from ' + this.table;
+ if (this.where) {
+ sql += " WHERE " + this.where;
+ }
+ return sql;
+ },
+
+ fetch: function() {
+ var self = this;
+ var sql = this.sql || this._create_sql();
+ if(typeof(sql) === "function") {
+ sql = sql.call(this);
+ }
+ var item = this.cache ? cache.getItem(sql): false;
+ if(!item) {
+ query(sql, function(data) {
+ if(this.cache) {
+ try {
+ cache.setItem(sql, JSON.stringify(data.rows));
+ } catch(e) {}
+ }
+ var rows;
+ if(!self.sql) {
+ rows = _.map(data.rows, function(r) {
+ return CartoDBModel.prototype._parse_columns.call(self, r);
+ });
+ } else {
+ rows = data.rows;
+ }
+ self.reset(rows);
+ });
+ } else {
+ self.reset(JSON.parse(item));
+ }
+ }
+
+ });
+
+
+ return {
+ query: query,
+ CartoDBCollection: CartoDBCollection,
+ CartoDBModel: CartoDBModel,
+ SQL: SQL
+ };
+
+};
Oops, something went wrong.

0 comments on commit 10d74d2

Please sign in to comment.