Skip to content

Commit

Permalink
Merge pull request #43 from sul-dlss/use-leaflet-methods-instead
Browse files Browse the repository at this point in the history
use leaflet methods rather than our own
  • Loading branch information
cbeer committed Feb 13, 2017
2 parents b865799 + 6b7d137 commit 7d4397c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/blacklight_heatmaps/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
//= require leaflet_solr_heatmap
//= require blacklight_heatmaps/blacklight_heatmaps
//= require blacklight_heatmaps/basemaps
//= require blacklight_heatmaps/icons
//= require_tree ./viewers
7 changes: 7 additions & 0 deletions app/assets/javascripts/blacklight_heatmaps/icons.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BlacklightHeatmaps.Icons = {
default: new L.Icon({
iconUrl: '<%= asset_path 'marker-icon.png'%>',
iconRetinaUrl: '<%= asset_path 'marker-icon-2x.png'%>',
shadowUrl: '<%= asset_path 'marker-shadow.png'%>'
})
};
8 changes: 7 additions & 1 deletion app/assets/javascripts/blacklight_heatmaps/viewers/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ Blacklight.onLoad(function () {
$el.data().basemapProvider
).addTo(map);

var features = L.geoJson(features).addTo(map);
var features = L.geoJson(features, {
pointToLayer: function(feature, latlng) {
return L.marker(latlng, {
icon: BlacklightHeatmaps.Icons.default
})
}
}).addTo(map);

map.fitBounds(features.getBounds());
},
Expand Down
22 changes: 9 additions & 13 deletions vendor/assets/javascripts/leaflet_solr_heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ L.SolrHeatmap = L.GeoJSON.extend({
}

var bounds = this._map.getBounds();
return [bounds.getWest(), bounds.getSouth(), bounds.getEast(), bounds.getNorth()].join(',');
var wrappedSw = bounds.getSouthWest().wrap();
var wrappedNe = bounds.getNorthEast().wrap();
return [wrappedSw.lng, bounds.getSouth(), wrappedNe.lng, bounds.getNorth()].join(',');
},

_mapViewToEnvelope: function () {
Expand All @@ -343,7 +345,9 @@ L.SolrHeatmap = L.GeoJSON.extend({
}

var bounds = this._map.getBounds();
return ':"Intersects(ENVELOPE(' + bounds.getWest() + ', ' + bounds.getEast() + ', ' + bounds.getNorth() + ', ' + bounds.getSouth() + '))"';
var wrappedSw = bounds.getSouthWest().wrap();
var wrappedNe = bounds.getNorthEast().wrap();
return ':"Intersects(ENVELOPE(' + wrappedSw.lng + ', ' + wrappedNe.lng + ', ' + bounds.getNorth() + ', ' + bounds.getSouth() + '))"';
},

_mapViewToWkt: function () {
Expand All @@ -352,7 +356,9 @@ L.SolrHeatmap = L.GeoJSON.extend({
}

var bounds = this._map.getBounds();
return '["' + bounds.getWest() + ' ' + bounds.getSouth() + '" TO "' + bounds.getEast() + ' ' + bounds.getNorth() + '"]';
var wrappedSw = bounds.getSouthWest().wrap();
var wrappedNe = bounds.getNorthEast().wrap();
return '["' + wrappedSw.lng + ' ' + bounds.getSouth() + '" TO "' + wrappedNe.lng + ' ' + bounds.getNorth() + '"]';
},

_solrQuery: function () {
Expand All @@ -364,16 +370,6 @@ L.solrHeatmap = function (url, options) {
return new L.SolrHeatmap(url, options);
};

L.LatLngBounds.prototype.getWest = function () {
var west = this._southWest.lng;
return west < -180 ? -180 : west;
};

L.LatLngBounds.prototype.getEast = function () {
var east = this._northEast.lng;
return east > 180 ? 180 : east;
};

// Check if L.MarkerCluster is included
if (typeof L.MarkerCluster !== 'undefined') {
L.MarkerCluster.prototype.initialize = function (group, zoom, a, b) {
Expand Down

0 comments on commit 7d4397c

Please sign in to comment.