Skip to content

Commit

Permalink
only adding taxon place and range layers when available; polygon tile…
Browse files Browse the repository at this point in the history
…s using different tileserver
  • Loading branch information
pleary committed Aug 28, 2015
1 parent 02bd273 commit 33e6531
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
21 changes: 15 additions & 6 deletions app/assets/javascripts/inaturalist/map3.js.erb
Expand Up @@ -878,17 +878,17 @@ var appendValidParamsToURL = function( url, options ) {

google.maps.Map.prototype.addPlaceLayer = function( options ) {
_.defaults( options, { validParams: [ 'color' ] });
return this.addElasticLayerByEndpoint( "places", options.place.id, options );
return this.addPostgisLayerByEndpoint( "places", options.place.id, options );
};

google.maps.Map.prototype.addTaxonRangeLayer = function( options ) {
_.defaults( options, { validParams: [ 'color' ] });
return this.addElasticLayerByEndpoint( "taxon_ranges", options.taxon.id, options );
return this.addPostgisLayerByEndpoint( "taxon_ranges", options.taxon.id, options );
};

google.maps.Map.prototype.addTaxonPlacesLayer = function( options ) {
_.defaults( options, { validParams: [ 'confirmed_color', 'unconfirmed_color' ] });
return this.addElasticLayerByEndpoint( "taxon_places", options.taxon.id, options );
return this.addPostgisLayerByEndpoint( "taxon_places", options.taxon.id, options );
};

var cachedGBIFColors;
Expand Down Expand Up @@ -916,10 +916,10 @@ google.maps.Map.prototype.addGBIFLayer = function( options ) {
return this.addLayerAndControl( { tiles: [ layerTileURL ] }, _.extend( options, { endpoint: "gbif" } ));
};

google.maps.Map.prototype.addElasticLayerByEndpoint = function( endpoint, endpointID, options ) {
google.maps.Map.prototype.addPostgisLayerByEndpoint = function( endpoint, endpointID, options ) {
// prevent the tilt feature, which cannot overlay tiles at higher zooms
this.setTilt(0);
var tileservers = elasticsearchTileservers( );
var tileservers = postgisTileservers( );
var options = options || { };
var tileURLs = _.map( tileservers , function( base ) {
return appendValidParamsToURL(
Expand Down Expand Up @@ -966,7 +966,16 @@ function elasticsearchTileservers( ) {
function intereactionsServer( ) {
var interactionTileURL = "<%= CONFIG.tile_servers.interactions %>";
if( interactionTileURL ) { return "//" + interactionTileURL; }
return elasticsearchTileservers()[0];
return elasticsearchTileservers( )[0];
}

// node_api_host and tile_servers.elasticsearch refer to two
// different clusters running the same code. node_api_host will
// be faster for DB/postgis queries
function postgisTileservers( ) {
var nodeApiHost = "<%= CONFIG.node_api_host %>";
if( nodeApiHost ) { return [ "//" + nodeApiHost ]; }
return elasticsearchTileservers( );
}

google.maps.Map.prototype.addObservationsLayer = function(options) {
Expand Down
2 changes: 1 addition & 1 deletion app/models/observation.rb
Expand Up @@ -2173,7 +2173,7 @@ def share_on_facebook(options = {})
observations_to_share.each do |o|
fb_api.put_connections("me", "#{CONFIG.facebook.namespace}:record", :observation => FakeView.observation_url(o))
end
rescue OAuthException => e
rescue Exception => e
Rails.logger.error "[ERROR #{Time.now}] Failed to share Observation #{id} on Facebook: #{e}"
end

Expand Down
4 changes: 2 additions & 2 deletions app/views/taxa/_show_map.html.haml
Expand Up @@ -4,8 +4,8 @@
min_zoom: 1,
taxon_layers: [ {
taxon: @taxon,
places: true,
ranges: true,
places: @taxon.listed_taxa.joins(place: :place_geometry).any?,
ranges: @taxon.taxon_ranges.any?,
observations: true,
gbif: { disabled: true },
} ]
Expand Down
5 changes: 3 additions & 2 deletions app/views/taxa/map.html.haml
Expand Up @@ -22,8 +22,9 @@
taxon_layers: @taxa.map{ |t|
{
taxon: t,
ranges: { color: colors[t.id].paint.lighten.to_hex },
places: @taxa.size == 1,
ranges: t.taxon_ranges.any? ?
{ color: colors[t.id].paint.lighten.to_hex } : false,
places: (@taxa.size == 1 && t.listed_taxa.joins(place: :place_geometry).any?),
observations: { color: colors[t.id] },
gbif: { disabled: true }
}
Expand Down
6 changes: 5 additions & 1 deletion config/config.yml.example
Expand Up @@ -153,7 +153,7 @@ base: &base
# See http://bitbucket.org/springmeyer/tilelite/
observations: 'http://localhost:8000'
tilestache: 'http://localhost:8080'
windshaft: http://localhost:4000
elasticsearch: http://localhost:4000

google_webmaster:
verification: abiglongkey
Expand Down Expand Up @@ -233,6 +233,10 @@ base: &base
# for more details
elasticsearch_host: 127.0.0.1:9200

# An instance of https://github.com/inaturalist/iNaturalistAPI, the
# same code running at CONFIG.tile_servers.elasticsearch
node_api_host: localhost:4000

development:
<<: *base

Expand Down

0 comments on commit 33e6531

Please sign in to comment.