Skip to content

Commit

Permalink
Enhanced interactivity layers -- doubleclick layer in layer list to t…
Browse files Browse the repository at this point in the history
…urn on wax info windows..
  • Loading branch information
jmalczyk committed Apr 13, 2012
1 parent c056faf commit 18ec317
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 7 deletions.
48 changes: 46 additions & 2 deletions app/js/lib/cartodb-gmapsv3.js
Expand Up @@ -432,7 +432,7 @@ var CartoDB = CartoDB || {};
if (this.params_.table_name == 'gbif_import') { if (this.params_.table_name == 'gbif_import') {
infowindow_sql = "SELECT " + infowindow_sql = "SELECT " +
"'Point' AS \"Type\", " + "'Point' AS \"Type\", " +
"'GBIF' AS \"Source\", " + "'GBIF' AS \"Provider\", " +
"scientificname AS \"Species name\", " + "scientificname AS \"Species name\", " +
"CollectionID AS \"Collection\", " + "CollectionID AS \"Collection\", " +
"CONCAT('<a target=\"_gbif\" onclick=\"window.open(this.href)\" href=\"http://data.gbif.org/occurrences/',identifier,'\">',identifier, '</a>') as \"Source ID\", " + "CONCAT('<a target=\"_gbif\" onclick=\"window.open(this.href)\" href=\"http://data.gbif.org/occurrences/',identifier,'\">',identifier, '</a>') as \"Source ID\", " +
Expand All @@ -442,7 +442,7 @@ var CartoDB = CartoDB || {};
if(this.params_.mol_layer.type == 'ecoregion') { if(this.params_.mol_layer.type == 'ecoregion') {
infowindow_sql = "SELECT " + infowindow_sql = "SELECT " +
"'Ecoregion' AS \"Type\", " + "'Ecoregion' AS \"Type\", " +
"upper(p.provider) AS \"Source\", " + "'<a href=\" http://www.worldwildlife.org/science/wildfinder/\">World Wildlife Fund' AS \"Provider\", " +
"p.scientificname AS \"Species name\", " + "p.scientificname AS \"Species name\", " +
"regionname AS \"Region\", " + "regionname AS \"Region\", " +
"e.ecoregion_code AS \"Ecoregion Code\", " + "e.ecoregion_code AS \"Ecoregion Code\", " +
Expand All @@ -451,6 +451,50 @@ var CartoDB = CartoDB || {};
"LEFT JOIN ecoregion_species e " + "LEFT JOIN ecoregion_species e " +
"ON p.ecoregion_list_id = e.id WHERE p.cartodb_id={0}".format(feature); "ON p.ecoregion_list_id = e.id WHERE p.cartodb_id={0}".format(feature);
} }
if(this.params_.mol_layer.type == 'protectedarea') {
infowindow_sql = "SELECT " +
"'Local inventory' AS \"Type\", " +
"'Scientist provided' AS \"Provider\", " +
"scientificname AS \"Species name\", " +
"regionname AS \"Region\", " +
"'ca. 1980-2005' as \"Date\", " +
"seasonality AS \"Seasonality\" " +
"FROM polygons " +
"WHERE cartodb_id={0}".format(feature);
}
if(this.params_.mol_layer.type == 'range' && this.params_.mol_layer.source == 'fishes') {
infowindow_sql = "SELECT " +
"'Expert range map' AS \"Type\", " +
"'Page & Burr 2011' AS \"Provider\", " +
"scientificname AS \"Species name\", " +
"'ca. 1980-2010' as \"Date\", " +
"seasonality as \"Seasonality\" " +
"FROM polygons " +
"WHERE cartodb_id={0}".format(feature);
}
if(this.params_.mol_layer.type == 'range' && this.params_.mol_layer.source.toLowerCase() == 'jetz') {
infowindow_sql = "SELECT " +
"'Expert range map' AS \"Type\", " +
"'Jetz et al 2012' AS \"Provider\", " +
"scientificname AS \"Species name\", " +
"'ca. 1980-2010' as \"Date\", " +
"seasonality as \"Seasonality\" " +
"FROM polygons " +
"WHERE cartodb_id={0}".format(feature);
}
if(this.params_.mol_layer.type == 'range' && this.params_.mol_layer.source.toLowerCase() == 'iucn') {
infowindow_sql = "SELECT " +
"'Expert range map' AS \"Type\", " +
"'IUCN' AS \"Provider\", " +
"scientificname AS \"Species name\", " +
"'ca. 1980-2010' as \"Date\", " +
"seasonality as \"Seasonality\", " +
"establishmentmeans as \"Origin\" " +
"FROM polygons " +
"WHERE cartodb_id={0}".format(feature);
}


} }


// If the table is private, you can't run any api methods // If the table is private, you can't run any api methods
Expand Down
21 changes: 21 additions & 0 deletions app/js/mol.map.layers.js
Expand Up @@ -202,6 +202,14 @@ mol.modules.map.layers = function(mol) {
break; break;
} }


//disable interactivity to start
self.map.overlayMapTypes.forEach(
function(mt) {
mt.interaction.remove();
mt.interaction.clickAction = "";
}
);

// Hack so that at the end we can fire opacity event with all layers. // Hack so that at the end we can fire opacity event with all layers.
all.push({layer:layer, l:l, opacity:opacity}); all.push({layer:layer, l:l, opacity:opacity});


Expand Down Expand Up @@ -244,13 +252,26 @@ mol.modules.map.layers = function(mol) {
); );
l.layer.dblclick( l.layer.dblclick(
function(event) { function(event) {

if($(this).hasClass('selected')) { if($(this).hasClass('selected')) {
$(this).removeClass('selected'); $(this).removeClass('selected');
} else { } else {
$(self.display).find('.selected').removeClass('selected'); $(self.display).find('.selected').removeClass('selected');
$(this).addClass('selected'); $(this).addClass('selected');
} }


self.map.overlayMapTypes.forEach(
function(mt) {
if(mt.name == layer.id && $(l.layer).hasClass('selected')) {
mt.interaction.add();
mt.interaction.clickAction = "full"
} else {
mt.interaction.remove();
mt.interaction.clickAction = "";
}
}
)

} }
) )
// Click handler for info button fires 'layer-info' // Click handler for info button fires 'layer-info'
Expand Down
10 changes: 6 additions & 4 deletions app/js/mol.map.tiles.js
Expand Up @@ -49,9 +49,10 @@ mol.modules.map.tiles = function(mol) {
}; };
e = new mol.bus.Event('layer-opacity', params); e = new mol.bus.Event('layer-opacity', params);
self.bus.fireEvent(e); self.bus.fireEvent(e);
if(maptype.interaction != undefined) { //if(maptype.interaction != undefined) {
maptype.interaction.add(); // maptype.interaction.add();
} // maptype.interaction.clickAction="full"
//}
return; return;
} }
} }
Expand All @@ -69,6 +70,7 @@ mol.modules.map.tiles = function(mol) {
self.bus.fireEvent(e); self.bus.fireEvent(e);
if(maptype.interaction != undefined) { if(maptype.interaction != undefined) {
maptype.interaction.remove(); maptype.interaction.remove();
maptype.interaction.clickAction="";
} }
//self.map.overlayMapTypes.removeAt(index); //self.map.overlayMapTypes.removeAt(index);
} }
Expand Down Expand Up @@ -302,7 +304,7 @@ mol.modules.map.tiles = function(mol) {
mol.map.tiles.CartoDbTile = Class.extend( mol.map.tiles.CartoDbTile = Class.extend(
{ {
init: function(layer, table, map) { init: function(layer, table, map) {
var sql = "SELECT * FROM {0} where scientificname='{1}' and type='{2}' and provider ='{3}'", var sql = "SELECT * FROM {0} where scientificname = '{1}' and type = '{2}' and provider = '{3}'",
opacity = layer.opacity && table !== 'points' ? layer.opacity : null, opacity = layer.opacity && table !== 'points' ? layer.opacity : null,
tile_style = opacity ? "#{0}{polygon-fill:#99cc00;}".format(table, opacity) : null, tile_style = opacity ? "#{0}{polygon-fill:#99cc00;}".format(table, opacity) : null,
hostname = window.location.hostname, hostname = window.location.hostname,
Expand Down
1 change: 0 additions & 1 deletion app/templates/map-index-template.html
Expand Up @@ -25,7 +25,6 @@


<script type="text/javascript" src="../../../js/lib/cartodb-gmapsv3.js?v=1"></script> <script type="text/javascript" src="../../../js/lib/cartodb-gmapsv3.js?v=1"></script>
<script type="text/javascript" src="../../../js/lib/wax.g.js"></script> <script type="text/javascript" src="../../../js/lib/wax.g.js"></script>
<script type="text/javascript" src="../../../js/lib/customcheck.js"></script>


{% if prod %} {% if prod %}
<script type="text/javascript" src="../../../static/js/mol.js?r={{ r }}"></script> <script type="text/javascript" src="../../../static/js/mol.js?r={{ r }}"></script>
Expand Down

0 comments on commit 18ec317

Please sign in to comment.