Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add initial version of the Gallicarte Chrome plugin to display Gallic…
…a's search results on a Leaflet map
- Loading branch information
Showing
17 changed files
with
4,751 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.leaflet-cluster-anim .leaflet-marker-icon, .leaflet-cluster-anim .leaflet-marker-shadow { | ||
-webkit-transition: -webkit-transform 0.3s ease-out, opacity 0.3s ease-in; | ||
-moz-transition: -moz-transform 0.3s ease-out, opacity 0.3s ease-in; | ||
-o-transition: -o-transform 0.3s ease-out, opacity 0.3s ease-in; | ||
transition: transform 0.3s ease-out, opacity 0.3s ease-in; | ||
} | ||
|
||
.leaflet-cluster-spider-leg { | ||
/* stroke-dashoffset (duration and function) should match with leaflet-marker-icon transform in order to track it exactly */ | ||
-webkit-transition: -webkit-stroke-dashoffset 0.3s ease-out, -webkit-stroke-opacity 0.3s ease-in; | ||
-moz-transition: -moz-stroke-dashoffset 0.3s ease-out, -moz-stroke-opacity 0.3s ease-in; | ||
-o-transition: -o-stroke-dashoffset 0.3s ease-out, -o-stroke-opacity 0.3s ease-in; | ||
transition: stroke-dashoffset 0.3s ease-out, stroke-opacity 0.3s ease-in; | ||
} |
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,3 @@ | ||
chrome.webNavigation.onHistoryStateUpdated.addListener(function(details) { | ||
chrome.tabs.executeScript(null,{file:"leaflet.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,79 @@ | ||
console.log('Hello Gallicarte'); | ||
var mapButtonAdded = false; | ||
var mapDisplayed = false; | ||
var oldResults; | ||
var markersToAdd = []; | ||
|
||
function addDisplayEvent(){ | ||
$('#button-type-affichage').click(function(){ | ||
|
||
setTimeout(function(){ | ||
getCurrentPageResults(); | ||
}, 200); | ||
|
||
addMapButton(); | ||
}); | ||
} | ||
|
||
function addMapButton(){ | ||
console.log("add button"); | ||
if($('#topPaginationBarArea').find('.dropdown-menu').length >= 3){ | ||
return; | ||
} else { | ||
mapButtonAdded = true; | ||
} | ||
setTimeout(function() { | ||
console.log('Add Map Button'); | ||
$('#topPaginationBarArea').find('.dropdown-menu').append('<li> <a href="#" class="display-map"><span class="pictos current-mode-affichage icon-carte"></span><span class="desc-mode">carte</span></a></li>'); | ||
displayMap(); | ||
}, 50); | ||
|
||
} | ||
|
||
function getCurrentPageResults(map){ | ||
console.log("get current page results"); | ||
var urls = $('.main-infos > h2 > a'); | ||
bnfLinks = []; | ||
urls.each(function(key, link){ | ||
var parsedLink = $(link).attr('href').split('.'); | ||
var parsedName = $(link).html(); | ||
var bnfLink = parsedLink[0] +'.'+ parsedLink[1] +'.'+ parsedLink[2]; | ||
bnfLinks.push([parsedName, bnfLink]); | ||
}); | ||
createSparqlQuery(bnfLinks, function(name, coord){ | ||
if(coord.length > 0){ | ||
markersToAdd.push([coord, name]); | ||
} | ||
}); | ||
} | ||
|
||
|
||
function displayMap(){ | ||
$('.display-map').click(function(){ | ||
oldResults = $('#searchResultsArea').html(); | ||
$('#searchResultsArea').html('<div id="map" style="height: 450px; "></div>'); | ||
|
||
var map = L.map('map').setView([51.505, -0.09], 13); | ||
|
||
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=', { | ||
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>', | ||
maxZoom: 18, | ||
id: '', | ||
accessToken: '', | ||
}).addTo(map); | ||
|
||
map.addLayer(markers); | ||
|
||
setTimeout(function(){ | ||
markersToAdd.forEach(function(data){ | ||
addMaker(data[0], data[1], map); | ||
}); | ||
}, 100); | ||
|
||
}); | ||
} | ||
|
||
|
||
$( document ).ready(function(){ | ||
addDisplayEvent(); | ||
}); |
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,51 @@ | ||
function createSparqlQuery(bnfResults, done){ | ||
bnfResults.forEach(function(bnfResults){ | ||
var arkLink = bnfResults[1]; | ||
var name = bnfResults[0]; | ||
// arkLink = "http://gallica.bnf.fr/ark:/12148/bpt6k5657596m"; | ||
var req= 'http://data.bnf.fr/sparql?default-graph-uri=&query=' + encodeURIComponent('PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>\ | ||
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>\ | ||
PREFIX dcterms: <http://purl.org/dc/terms/>\ | ||
PREFIX foaf: <http://xmlns.com/foaf/0.1/>\ | ||
PREFIX rdarelationships: <http://rdvocab.info/RDARelationshipsWEMI/>\ | ||
PREFIX dc: <http://purl.org/dc/elements/1.1/>\ | ||
PREFIX marcrel: <http://id.loc.gov/vocabulary/relators/>\ | ||
PREFIX bnfroles: <http://data.bnf.fr/vocabulary/roles/>\ | ||
SELECT DISTINCT ?docnum ?lieu ?lat ?long ?label \ | ||
WHERE\ | ||
{\ | ||
?conceptLieu foaf:focus ?lieu ;\ | ||
skos:prefLabel ?label .\ | ||
?lieu a geo:SpatialThing;\ | ||
geo:lat ?lat ;\ | ||
geo:long ?long.\ | ||
\ | ||
\ | ||
?conceptLieu skos:closeMatch ?sujet.\ | ||
?edition dcterms:subject ?sujet ;\ | ||
rdarelationships:expressionManifested ?exp.\ | ||
?exp ?s ?p .\ | ||
?edition rdarelationships:electronicReproduction ?docnum .\ | ||
FILTER regex(?docnum, "'+ arkLink +'") \ | ||
}\ | ||
LIMIT 1') + '&format=application%2Fsparql-results%2Bjson&timeout=0&should-sponge=&debug=on'; | ||
|
||
$.get(req, function(data) { | ||
var coord = extractCoordinates(data); | ||
done(name, coord); | ||
}); | ||
|
||
}); | ||
} | ||
|
||
function extractCoordinates(data){ | ||
if(data.results != undefined && data.results.bindings != undefined && data.results.bindings.length > 0){ | ||
console.log(data.results.bindings[0]); | ||
var lat = data.results.bindings[0].lat.value; | ||
var long = data.results.bindings[0].long.value; | ||
return [lat, long]; | ||
// return [parseFloat(lat), parseFloat(long)]; | ||
} else { | ||
return []; | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
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,47 @@ | ||
// var firstMarker = L.icon({ iconUrl: 'https://unpkg.com/leaflet@1.0.1/dist/images/marker-icon.png' }); | ||
|
||
var markers = L.markerClusterGroup({ | ||
iconCreateFunction: function(cluster) { | ||
var markersTmp = cluster.getAllChildMarkers(); | ||
n = 0; | ||
//console.log(markersTmp); | ||
if(markersTmp.length > 0){ | ||
for (var i = 0; i < markersTmp.length; i++) { | ||
//console.log(markersTmp[i]._popup._content); | ||
n += (markersTmp[i]._popup._content.match(/<tr>/g) || []).length; | ||
} | ||
} | ||
//console.log(n); | ||
var c = ' marker-cluster-'; | ||
if (n < 10) { | ||
c += 'small'; | ||
} else if (n < 100) { | ||
c += 'medium'; | ||
} else { | ||
c += 'large'; | ||
} | ||
return new L.DivIcon({ html: '<div><span>' + n + '</span></div>', className: 'marker-cluster' + c, iconSize: new L.Point(40, 40) }); | ||
} | ||
}); | ||
|
||
var controlSearch = new L.Control.Search({ | ||
position:'topleft', | ||
layer: markers, | ||
initial: false, | ||
zoom: 16 | ||
}); | ||
|
||
|
||
|
||
function addMaker(coords, title, map){ | ||
var LeafIcon = L.Icon.extend({ | ||
options: {} | ||
}); | ||
|
||
var blueIcon = new LeafIcon({iconUrl: 'https://unpkg.com/leaflet@1.0.1/dist/images/marker-icon.png'}); | ||
|
||
|
||
L.marker(coords, {icon: blueIcon }).addTo(map) | ||
.bindPopup(title) | ||
.openPopup(); | ||
} |
Oops, something went wrong.