GithubHelp home page GithubHelp logo

ayastreb / jekyll-maps Goto Github PK

View Code? Open in Web Editor NEW
134.0 8.0 41.0 266 KB

:earth_americas: Embed maps with filterable locations in Jekyll

Home Page: https://ayastreb.me/jekyll-maps/

License: MIT License

Ruby 86.74% Shell 0.28% JavaScript 12.98%
jekyll-plugin ruby google-maps marker-clustering

jekyll-maps's Introduction

Jekyll Maps

Gem Version Build Status Code Climate Test Coverage Dependency Status

Jekyll Maps is a plugin that allows you to easily create different maps on your Jekyll site pages. It allows you to select which points to display on the map with different filters.

GoogleMaps Marker Clusterer can be used if you have many points within close proximity.

Installation

  1. Add the following to your site's Gemfile:
gem 'jekyll-maps'
  1. Add the following to your site's _config.yml:
plugins:
  - jekyll-maps

Usage

Configure Google API Key

To be able to use Google Maps you need to obtain API Key.

Once you have your API Key you need to add it to Jekyll's _config.yml:

maps:
  google:
    api_key: <YOUR_KEY>

Data Source

First, add location information to your posts YAML front-matter:

location:
  latitude: 51.5285582
  longitude: -0.2416807

You can specify multiple locations per post:

location:
  - latitude: 51.5285582
    longitude: -0.2416807
  - latitude: 52.5285582
    longitude: -2.2416807
  - title: custom marker title
    image: custom marker image
    url: custom marker url
    latitude: 51.5285582
    longitude: -0.2416807

Alternatively, you can add location info to your custom collection's documents or even in data files:

- title: Paris
  url: http://google.fr
  location:
    latitude: 48.8587741
    longitude: 2.2074741

- title: Madrid
  url: http://google.es
  location:
    latitude: 40.4378698
    longitude: -3.8196204

By default this plugin will display location from the page it's placed on:

{% google_map %}

But you can use src attribute to load locations from other places, like posts, collections or data files!

For example, this map will show locations from all posts from 2016:

{% google_map src="_posts/2016" %}

This map will show locations from a collection called 'my_collection':

{% google_map src="_collections/my_collection" %}

This map will show locations from all data files located in 'my_points' sub-folder:

{% google_map src="_data/my_points" %}

You can configure map's dimensions and assign custom CSS class to the element:

{% google_map width="100%" height="400" class="my-map" %}

You can also just set marker coordinates directly in tag attributes:

{% google_map latitude="48.8587741" longitude="2.2074741" marker_title="My Location" marker_img="/img.jpg" marker_url="/my-location.html" %}

This will create a map with single marker in given location. marker_title, marker_img and marker_url attributes are optional and current page's data will be used by default.

Filters

You can also filter which locations to display on the map!
For instance, following tag will only display locations from documents which have lang: en in their front-matter data.

{% google_map src="_posts" lang="en" %}

Marker Cluster

By default Marker Clusterer is enabled. If you have many markers on the map, it will group them and show icon with the count of markers in each cluster - see example.

If you don't want to use marker cluster, you can disable it globally in _config.yml:

maps:
  google:
    marker_cluster:
      enabled: false

Or you can disable it per single map tag:

{% google_map no_cluster %}

If you have any questions or proposals - open up an issue!

Examples

Want to see it in action? Check out Demo Page!

Contributing

  1. Fork it (https://github.com/ayastreb/jekyll-maps/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

MIT. Feel free to use, copy or distribute it.

jekyll-maps's People

Contributors

ayastreb avatar dhoppe avatar lpelypenko avatar oliverevans96 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jekyll-maps's Issues

Option to hide marker

I want to configure my map to show a region without any marker instead of a exact address, it is possible?
At moment I'm using this code (I'm still need to set the coordinates, but there is no marker):

<script` src="https://maps.googleapis.com/maps/api/js?key={{ site.gmaps_APIKEY }}&amp;sensor=false"></script>


<script type="text/javascript">
var styles = [
	{
		featureType: 'landscape',
		elementType: 'geometry',
		stylers: [
			{ hue: '#dddddd' },
			{ saturation: -100 },
			{ lightness: -3 },
			{ visibility: 'simplified' }
		]
	},{
		featureType: 'water',
		elementType: 'all',
		stylers: [
		]
	}
];
var options = {
	mapTypeControlOptions: {
		mapTypeIds: [ 'Styled']
	},
	center: new google.maps.LatLng({{ site.gmaps_coordinates }}),
	zoom: 11,
	mapTypeId: 'Styled'
};
var div = document.getElementById('map');
var map = new google.maps.Map(div, options);
var styledMapType = new google.maps.StyledMapType(styles, { name: 'Styled' });
map.mapTypes.set('Styled', styledMapType);
</script>

How to: named locations from _data/...

First of all, nice plugin! I really like it.

I have a data file with a few commonly used locations like:

# _data/places.yml
- title: "Office"
  location:
    latitude: ...
    longitude: ...
- title: "Home"
  location:
    latitude: ...
    longitude: ...

Instead of putting coordinates into my front matter, I would like to use these named locations like such:

_posts/2022-05-23-Named-Locations.md:

---
title: Post with named location
location: "Office"
---
Here is where I worked today:
{% google_map src="_data/places.yml" title={{ page.location }} %}

When I do that now, just get a map with markers for both my office and my home.

I suspect this is already possible, I'm just not sure how to apply the correct incantation to make it work.

A question

I'm using your plugin but why I can't pass zoom parameter from page front matter?
I tried everything I know.

Thank you!

Category filter

As a user I should be able to filter locations by document category.
Multiple categories should be supported with the following syntax:
{% google_map category:apples,oranges %} - matches documents in apples AND oranges categories.
{% google_map category:apples|oranges %} - matches documents in apples OR oranges categories.

Configurable width, height and class of map element

As a user I should be able to set map element width, height and class from tag, e.g.:
{% google_map width:600 height:400 class:custom-class %}
which should produce following HTML:

<div id="google-map" style="width:600px;height:400px;" class="custom-class"></div>

Liquid Exception: undefined method `each' for nil:NilClass

Trying to follow the instructions here:

I can get one marker working with the map displaying fine, however if I attempt to load from the described places.yml file, then I get an error as seen in the title

{% google_map src="_data/places.yml" %}
# _data/places.yaml
  - title: "Paris"
    url: "http://google.fr"
    location:
      latitude: 48.8587741
      longitude: 2.2074741

  - title: "Madrid"
    url: "http://google.es"
    location:
      latitude: 40.4378698
      longitude: -3.8196204

stack trace:

C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/jekyll-maps-2.0.2/lib/jekyll-maps/location_finder.rb:14:in `find': undefined method `each' for nil:NilClass (NoMethodError)
from C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/jekyll-maps-2.0.2/lib/jekyll-maps/google_map_tag.rb:15:in `render' from C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/block.rb:151:in `render_token'
        from C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/profiler/hooks.rb:5:in `block in render_token_with_profiling'
        from C:/tools/ruby23/lib/ruby/gems/2.3.0/gems/liquid-3.0.6/lib/liquid/profiler.rb:80:in `profile_token_render'
....
....

Integrate GoogleMaps geocoding

As a user I should be able to use GoogleMaps geocoding
For example, following post:

---
title: Paris is cool
location: Paris, France
--- 

France is nice!
{% google_map on_page %}

should geocode "Paris, France" to latitude/longitude coordinates and display it on the map.

Filter doesn't work if string has spaces

For some reason the filter function doesn't work if there are spaces. For example, foo="bar baz" would not filter a collection whose front matter had foo: bar baz.

Error on Jekyll Serve

Hi all -

I have been trying to get the following tags to render after running the gemfiles. Jekyll doesn't seem to recognize the google map tag, and I'm confused as to why? I'm new to Jekyll and feel like I'm missing something obvious. Is there anywhere I need to add a definition for the google_map tag to get it to work?

{% google_map src="_data/places.yml" %}
{% google_map %}
Liquid Exception: Liquid syntax error (line 31): Unknown tag 'google_map' in map/index.html

Thank you in advance!
Mark Milutinovic

Liquid Exception: no implicit conversion of String into Integer

I am trying out this plugin which looks great but I run in a bit of trouble. I followed the installation
instructions but when I try to generate a map I get the following error:

jekyll 3.2.1 | Error:  no implicit conversion of String into Integer

Here is an example

#contact.md

---
location:
  latitude: 48.8587741
  longitude: 2.2074741

---

{% google_map %}

Any thoughts ? I am new to jekyll.

Configurable Google Maps options with defaults

As a user I should be able to configure map options

Options can be set globally via _config.yml:

maps:
  google:
    options:
      disableDefaultUI: false
      scrollwheel: false

or it can be set from tag:

{% google_map on_page zoom:10 %}

On-page map

As a user I should be able to embed a map into page with this page's location only on the map.
E.g. I have a post with location => Madrid and I want to display a map with a marker centered in Madrid on this post page with following tag:
{% google_map on_page %}

When on_page flag is present in the tag the map should load location from current document and log error if there is no location found in current document.

Configurable Google Maps API key

As a user I should be able to set Google Maps API key from Jekyl config, e.g.

maps:
  google:
    api_key: <-- MY_API_KEY_HERE -->

The API key from the config should be inserted in the script load tag.

On-page map range filter

As a user I should be able to filter points on the map by distance from the current page.
For example:
{% google_map on_page range:100 %}
should produce a map centered on current page location and also include all other posts within 100 kilometers from the current page's location.

Multiple locations per document

As a user I should be able to provide multiple locations per single document.
For example:

location:
  - title: point A
    latitude:  43.988223
    longitude: 13.223221
  - title: point B
    latitude:  45.987348
    longitude: 5.4424479
    url: /somewhere-else

should produce two points on the map with this document.
If no URL provided for specifi point, document's main URL is used.

Generated links don't respect baseurl in _config.yml

I have used this plugin in a GitHub pages project repository, but the links generated from the map don't include the subfolder that my site is served in, it always reference the root.

I feel the plugin should be pulling this automatically from the main _config.yml configuration file, but is there is plugin-specific configuration setting I should be setting instead? - or is this indeed not supported at the moment?

Uncaught ReferenceError: jekyllMaps is not defined

With the latest version I'm receiving Uncaught ReferenceError: jekyllMaps is not defined.

bundle exec jekyll -v
jekyll 4.3.1

Usage/definition:
index.md

{% google_map src="_data/places.yaml" %}

After the page refreshing the map shows as expected.

Error: undefined method `each_value'.. Did you mean? each_slice

I have installed in this using the process set out in the readme.

I have confirmed that I can generate a map directly, using e.g.,

{% google_map latitude="48.8587741" longitude="2.2074741" marker_title="My Location" marker_img="/img.jpg" marker_url="/my-location.html" %}

I'm now trying to read in files in a yml or JSON file. Using the example in the readme, I create a data file (_data/map.yml) with this content:

- title: Paris
  url: http://google.fr
  location:
    latitude: 48.8587741
    longitude: 2.2074741

- title: Madrid
  url: http://google.es
  location:
    latitude: 40.4378698
    longitude: -3.8196204

I then try to call it from a post, map.md following the example given in the Readme:

    {% google_map src="_data/map.yml" %}

Which unfortunately gives me this error:

Liquid Exception: undefined method `each_value' for [{"title"=>"Paris", "url"=>"http://google.fr", "location"=>{"latitude"=>48.8587741, "longitude"=>2.2074741}}, {"title"=>"Madrid", "url"=>"http://google.es", "location"=>{"latitude"=>40.4378698, "longitude"=>-3.8196204}}]:Array Did you mean? each_slice in /blah/blah/map.md

All suggestions welcome!

Multiple maps per page

As a user should be able to add multiple maps to one page.
It should be possible to set map element ID from tag.
External API JS files should be loaded only once per page.

Resizing the map // applying colour filters

Thank you very much for a wonderful Google maps plugin! I would like to ask a few questions:

a) Is it possible to resize the map shown on the page? I didn't find this option in the examples. I would like to make a square map, instead of a standard rectangle.

b) I would like to apply a black-and-white colour filter onto the map, i.e. show a greyscale version of the map.

Map load speed

Is there any way to enable lazy loading of the maps used? The map plugin seems to be the cause of speed issues in the chrome audit.
image

Uknown tag error

Hi,

I've tried to install your plugin to my site, I followed instructions in README (add gem into Gemfile and also _config), but when building I get error Liquid syntax error unknown tag google_maps.

Thanks for your help.

Zoom is not working

I am trying to set the zoom on a map, but having no luck. Seems like it should be straight forward, but I've tried the following three iterations (separately, not all at once) without any success:

{% google_map src="_data/google-maps" zoom="10" %}

   url: "http://google.fr"
   zoom: 10
   location:
     latitude: 48.8587741
     longitude: 2.2074741
   url: "http://google.fr"
   location:
     latitude: 48.8587741
     longitude: 2.2074741
     zoom: 10

Provide detailed readme

Main repo readme file should describe installation, usage and contribution documentation.

Breaks pages with <header> tag

If map is embeded to a page which has a <header> tag, JS code is inserted between <head> and <header> and breaks the body of the page.

Accessing initialised Google Maps Instance from own script

Is there a way to access the initialized google maps instance, which I launched in my template with {% google_map src="_data/places.yml" width="100%" zoom="10" %}, to then make dynamic changes on the marker or other configurations, like using methods from the google.maps.Map-Object?

Inline location

As a user I need to be able to provide location coordinates directly within google_map tag, e.g.

{% google_map latitude="51.5073896" longitude="-0.1276717" %}

this tag should render a map with single marker on given location.

Help please

I am trying to use your plugin on a jekyll site using a yml data file that also serves other purposes. Anyway, I can't get the gem to pull in the title field. It just pulls in a "null". even though one of the fields is named "title" (ideally I would be able to remap the names of the fields). I have tried adding a "location:" to the beginning of the record and indenting everything else by two spaces. It does pull in the lat, long and url just fine. Also is there a way to use advanced logic for the marker image (i.e., if type=sweet then use marker one if type=savory then use marker 2)? Ideally, I would love to see live use cases out there including sample yml files beyond what you have in ayastreb.me/jekyll-maps/ If anyone can lead me in the right direction.... Thanks!

Setup demo page

A demo site should be created highlighting usage examples and plugin features.

Jekyll 4.x - Map tag included in layout issue

Hello,
I noticed an strange issue occurring only on Jekyll 4+ and if the map tag is included directly in a layout file: the map is showing the location of the current post + the posts before.
Map of first post will be correct, map of second post will display map from first post and second post, etc.
image
image

The issue is not occurring when inserting the tag directly in the post content or using jekyll 3.x. Is this something about the new jekyll cache feature?

I created a repository to reproduce the issue easily: https://github.com/Gerfaut/jekyll-maps-issue
Is there anything we can do on the jekyll-maps gem to fix that or is this meant to work like that?

Thanks a lot for your help,
Gerfaut

Ability to change the default url text

When you supply a URL, the text shows up in the dialog as "View". It's be cool to have an extra param in the data like, url_text to be able to customize the popup.

So like:

- title: Place Name
  url: http://www.place.net
  url_text: View place name
  latitude: 6.206731
  longitude: -75.5677747

Liquid syntax error: unknown tag 'google_map'

Hi, I was trying to put map in my site. I was following your steps. But it keeps saying Liquid Exception: Liquid syntax error (line 44): Unknown tag 'google_map'.
Does anyone encounter this before?

jekyllMaps is not defined

When I add {% google_map %} to my page, the following is output in the final HTML:

<div id="1fc4ca6d-5e80-4134-8472-5516b81a3d40" style="width:600px;height:400px;"></div>
<script `type="text/javascript">
jekyllMaps.register('1fc4ca6d-5e80-4134-8472-5516b81a3d40', [{ "latitude": 32.7661546, "longitude": -61.9589893, "title": "Current Location", "url": "/current-location/", "image": "" }], { "baseUrl": "/", "useCluster": true, "showMarker": true, "showMarkerPopup": true });
</script>

This ends up throwing the console error "jekyllMaps is not defined".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.