-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
google-map: implement google map tag
- Loading branch information
Showing
9 changed files
with
218 additions
and
2 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,58 @@ | ||
<div id='google-map'></div> | ||
|
||
<script type='text/javascript'> | ||
var jekyllMaps = (function () { | ||
'use strict'; | ||
|
||
return { | ||
loadScript: function (url) { | ||
var script = document.createElement('script'); | ||
script.type = 'text/javascript'; | ||
script.src = url; | ||
document.body.appendChild(script); | ||
}, | ||
initialize: function () { | ||
this.options = { | ||
center: new google.maps.LatLng(0, 0), | ||
mapTypeId: google.maps.MapTypeId.ROADMAP, | ||
zoom: 3 | ||
} | ||
this.map = new google.maps.Map(document.getElementById('google-map'), this.options); | ||
this.showMarkers({{ locations }}); | ||
}, | ||
showMarkers: function (locations) { | ||
var map = this.map, | ||
bounds = new google.maps.LatLngBounds(), | ||
markers = locations.map(function (location) { | ||
var position = new google.maps.LatLng(location.latitude, location.longitude); | ||
var marker = new google.maps.Marker({ | ||
position: position, | ||
map: map, | ||
title: location.title, | ||
url: location.url | ||
}); | ||
|
||
marker.addListener('click', function () { | ||
if (this.url) { | ||
window.location.href = this.url; | ||
} | ||
}); | ||
bounds.extend(position); | ||
|
||
return marker; | ||
}); | ||
|
||
new MarkerClusterer(map, markers, { | ||
gridSize: 25, | ||
imagePath: 'https://raw.githubusercontent.com/googlemaps/js-marker-clusterer/gh-pages/images/m' | ||
}); | ||
map.fitBounds(bounds); | ||
}, | ||
}; | ||
}()); | ||
|
||
window.onload = function () { | ||
jekyllMaps.loadScript('https://googlemaps.github.io/js-marker-clusterer/src/markerclusterer.js'); | ||
jekyllMaps.loadScript('http://maps.googleapis.com/maps/api/js?callback=jekyllMaps.initialize'); | ||
}; | ||
</script> |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: London | ||
country: gb | ||
location: | ||
latitude: 51.5285582 | ||
longitude: -0.2416807 | ||
--- | ||
|
||
London is a capital of Great Britain. |
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 @@ | ||
--- | ||
title: Berlin | ||
country: de | ||
location: | ||
latitude: 52.5072111 | ||
longitude: 13.1449604 | ||
--- | ||
|
||
Berlin is in Germany. |
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,5 @@ | ||
--- | ||
title: post without location | ||
--- | ||
|
||
Nothing to see here. |
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,7 @@ | ||
--- | ||
title: Only include posts with matching attribute | ||
--- | ||
|
||
**With Filters** | ||
|
||
{% google_map country:de %} |
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,7 @@ | ||
--- | ||
title: Simple map without options | ||
--- | ||
|
||
**Jekyll Google Maps Plugin** | ||
|
||
{% google_map %} |
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,35 @@ | ||
require "spec_helper" | ||
|
||
describe Jekyll::Maps::GoogleMapTag do | ||
let(:site) { make_site } | ||
|
||
before do | ||
site.process | ||
end | ||
|
||
context "tag without options" do | ||
let(:content) { File.read(dest_dir("page_no_options.html")) } | ||
|
||
it "builds javascript" do | ||
expect(content).to match(%r!jekyllMaps!) | ||
end | ||
|
||
it "finds posts with location" do | ||
expect(content).to match(%r!Berlin!) | ||
expect(content).to match(%r!London!) | ||
end | ||
|
||
it "skips posts without location" do | ||
expect(content).not_to match(%r!post without location!) | ||
end | ||
end | ||
|
||
context "tag with attribute filter" do | ||
let(:content) { File.read(dest_dir("page_filter_attribute.html")) } | ||
|
||
it "finds only post with matching attribute" do | ||
expect(content).to match(%r!Berlin!) | ||
expect(content).not_to match(%r!London!) | ||
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) | ||
require "jekyll" | ||
require "jekyll-maps" | ||
|
||
Jekyll.logger.log_level = :error | ||
|
||
RSpec.configure do |config| | ||
config.run_all_when_everything_filtered = true | ||
config.filter_run :focus | ||
config.order = "random" | ||
|
||
SOURCE_DIR = File.expand_path("../fixtures", __FILE__) | ||
DEST_DIR = File.expand_path("../dest", __FILE__) | ||
|
||
def source_dir(*files) | ||
File.join(SOURCE_DIR, *files) | ||
end | ||
|
||
def dest_dir(*files) | ||
File.join(DEST_DIR, *files) | ||
end | ||
|
||
CONFIG_DEFAULTS = { | ||
"source" => source_dir, | ||
"destination" => dest_dir, | ||
"gems" => ["jekyll-maps"] | ||
}.freeze | ||
|
||
def make_site(options = {}) | ||
site_config = Jekyll.configuration CONFIG_DEFAULTS.merge(options) | ||
Jekyll::Site.new(site_config) | ||
end | ||
end |