-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from sul-dlss/setup
Initial commits of blacklight-maps gem 0.0.1
- Loading branch information
Showing
25 changed files
with
483 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,5 @@ test/tmp | |
test/version_tmp | ||
tmp | ||
spec/internal | ||
jetty | ||
jetty | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,4 +40,4 @@ namespace :blacklight_maps do | |
cp("#{f}", 'jetty/solr/blacklight-core/conf/', :verbose => true) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
// for Blacklight.onLoad: | ||
//= require blacklight/core | ||
|
||
//= require leaflet | ||
//= require leaflet.markercluster | ||
//= require L.Control.Sidebar | ||
//= require L.Control.Sidebar | ||
|
||
//= require_tree './blacklight-maps' |
141 changes: 141 additions & 0 deletions
141
app/assets/javascripts/blacklight-maps/blacklight-maps-browse.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
var map, sidebar; | ||
|
||
Blacklight.onLoad(function() { | ||
|
||
// Stop doing stuff if the map div isn't there | ||
if ($("#blacklight-map").length === 0){ | ||
return; | ||
} | ||
|
||
// Get the configuration options from the data-attributes | ||
$.extend(Blacklight.mapOptions, $("#blacklight-map").data()); | ||
|
||
map = L.map('blacklight-map').setView([0,0], 2); | ||
L.tileLayer(Blacklight.mapOptions.tileurl, { | ||
attribution: Blacklight.mapOptions.mapattribution, | ||
maxZoom: Blacklight.mapOptions.maxzoom | ||
}).addTo(map); | ||
|
||
// Sets up leaflet-sidebar | ||
sidebar = L.control.sidebar('blacklight-map-sidebar', { | ||
position: 'right', | ||
autoPan: false | ||
}); | ||
|
||
// Adds leaflet-sidebar control to map (object) | ||
map.addControl(sidebar); | ||
|
||
// Create a marker cluster object and set options | ||
markers = new L.MarkerClusterGroup({ | ||
showCoverageOnHover: false, | ||
spiderfyOnMaxZoom: false, | ||
singleMarkerMode: true, | ||
animateAddingMarkers: true | ||
}); | ||
|
||
geoJsonLayer = L.geoJson(geojson_docs, { | ||
onEachFeature: function(feature, layer){ | ||
layer.defaultOptions.title = feature.properties.placename; | ||
layer.on('click', function(e){ | ||
if (sidebar.isVisible()){ | ||
sidebar.hide(); | ||
} | ||
var placenames = {}; | ||
placenames[feature.properties.placename] = [feature.properties.html]; | ||
offsetMap(e); | ||
$('#blacklight-map-sidebar').html(buildList(placenames)); | ||
sidebar.show(); | ||
}); | ||
} | ||
}); | ||
|
||
// Add GeoJSON layer to marker cluster object | ||
markers.addLayer(geoJsonLayer); | ||
|
||
// Add marker cluster object to map | ||
map.addLayer(markers); | ||
|
||
// Listeners for marker cluster clicks | ||
markers.on('clusterclick', function(e){ | ||
|
||
//hide sidebar if it is visible | ||
if (sidebar.isVisible()){ | ||
sidebar.hide(); | ||
} | ||
|
||
//if map is at the lowest zoom level | ||
if (map.getZoom() === Blacklight.mapOptions.maxzoom){ | ||
|
||
var placenames = generatePlacenamesObject(e.layer._markers); | ||
|
||
|
||
offsetMap(e); | ||
|
||
//Update sidebar div with new html | ||
$('#blacklight-map-sidebar').html(buildList(placenames)); | ||
|
||
//Show the sidebar! | ||
sidebar.show(); | ||
} | ||
}); | ||
|
||
//Add click listener to map | ||
map.on('click', function(e){ | ||
|
||
//hide the sidebar if it is visible | ||
if (sidebar.isVisible()){ | ||
sidebar.hide(); | ||
} | ||
}); | ||
|
||
//drag listener on map | ||
map.on('drag', function(e){ | ||
|
||
//hide the sidebar if it is visible | ||
if (sidebar.isVisible()){ | ||
sidebar.hide(); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
Blacklight.mapOptions = { | ||
tileurl : 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', | ||
mapattribution : 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>' | ||
}; | ||
|
||
function buildList(placenames){ | ||
var html = ""; | ||
$.each(placenames, function(i,val){ | ||
html += "<h2>" + i + "</h2>"; | ||
html += "<ul class='sidebar-list'>"; | ||
$.each(val, function(j, val2){ | ||
html += val2; | ||
}); | ||
html += "</ul>"; | ||
}); | ||
return html; | ||
} | ||
|
||
// Generates placenames object | ||
function generatePlacenamesObject(markers){ | ||
var placenames = {}; | ||
$.each(markers, function(i,val){ | ||
if (!(val.feature.properties.placename in placenames)){ | ||
placenames[val.feature.properties.placename] = []; | ||
} | ||
placenames[val.feature.properties.placename].push(val.feature.properties.html); | ||
}); | ||
return placenames; | ||
} | ||
|
||
// Move the map so that it centers the clicked cluster TODO account for various size screens | ||
function offsetMap(e){ | ||
mapWidth = $('#blacklight-map').width(); | ||
mapHeight = $('#blacklight-map').height(); | ||
if (!e.latlng.equals(map.getCenter())){ | ||
map.panBy([(e.originalEvent.layerX - (mapWidth/4)), (e.originalEvent.layerY - (mapHeight/2))]); | ||
}else{ | ||
map.panBy([(mapWidth/4), 0]); | ||
} | ||
} |
4 changes: 0 additions & 4 deletions
4
app/assets/stylesheets/blacklight_maps/blacklight-maps.css.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
/* Master manifest file for engine, so local app can require | ||
* this one file, but get all our files -- and local app | ||
* require does not need to change if we change file list. | ||
* | ||
*= require 'leaflet.markercluster' | ||
*= require 'leaflet.markercluster.default' | ||
*= require 'L.Control.Sidebar' | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
#documents.map { | ||
/* | ||
*= require leaflet | ||
*= require leaflet.markercluster | ||
*= require leaflet.markercluster.default | ||
*= require L.Control.Sidebar.css | ||
*/ | ||
|
||
.view-icon-maps { | ||
&:before { content: "\e135"; } | ||
} | ||
|
||
.view-icon-maps { | ||
&:before { content: "\e062"; } | ||
#blacklight-map{ | ||
height: 550px; | ||
} | ||
|
||
.sidebar-thumb{ | ||
height: 64px; | ||
width: 64px; | ||
} | ||
|
||
.sidebar-list{ | ||
padding-left: 0; | ||
list-style: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module BlacklightMapsHelper | ||
|
||
def show_map_div | ||
data_attributes = { | ||
:maxzoom => blacklight_config.view.maps.maxzoom, | ||
:tileurl => blacklight_config.view.maps.tileurl | ||
|
||
} | ||
|
||
content_tag(:div, "", id: "blacklight-map", | ||
data: data_attributes | ||
) | ||
end | ||
|
||
def serialize_geojson | ||
geojson_docs = {type: "FeatureCollection", features: []} | ||
@response.docs.each_with_index do |doc, counter| | ||
if doc[blacklight_config.view.maps.placename_coord_field] | ||
doc[blacklight_config.view.maps.placename_coord_field].each do |loc| | ||
values = loc.split('|') | ||
feature = {type: "Feature", geometry: {type: "Point", | ||
coordinates: [values[2].to_f, values[1].to_f]}, | ||
properties: {placename: values[0], | ||
html: render_leaflet_sidebar_partial(doc)}} | ||
geojson_docs[:features].push feature | ||
end | ||
end | ||
end | ||
return geojson_docs.to_json | ||
end | ||
|
||
def render_leaflet_sidebar_partial(doc) | ||
render partial: 'catalog/index_maps', locals: {document: SolrDocument.new(doc)} | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<% # container for all documents in index view -%> | ||
<% # container for all documents in map view -%> | ||
<div id="documents" class="map"> | ||
<!-- map goes here --> | ||
<%= show_map_div() %> | ||
<div id="blacklight-map-sidebar"></div> | ||
<%= javascript_tag "var geojson_docs = #{serialize_geojson}" %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<% # the way each document will be viewed in the sidebar list -%> | ||
<li class='media'> | ||
<%= render_thumbnail_tag document, {class: 'sidebar-thumb media-object'}, {class: 'pull-left'} %> | ||
<div class='media-body'> | ||
<h4 class='media-heading'> | ||
<%= link_to_document document, :label=>document_show_link_field(document) %> | ||
</h4> | ||
</div> | ||
</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.