Code Monkey home page Code Monkey logo

jekyll-mapping's Introduction

Jekyll Mapping

Jekyll mapping is a plugin for Jekyll that lets you easily embed Google and OpenStreetMap maps on your content, and then easily add markers and/or KML overlays to those maps.

Supported providers

Google static image

mapping:
  provider: google_static

https://developers.google.com/maps/documentation/staticmaps/

Embeds a static image, centered on the specificed location, with a marker at the specified location

Google JS API

mapping:
  provider: google_js

https://developers.google.com/maps/documentation/javascript/

Embeds an interactive map using the V3 JS API. Using this requires an API key to be specified within _config.yml

OpenStreetMap

mapping:
  provider: openstreetmap

Uses OpenStreetMap and OpenLayers to provide interactive maps. Doesn't require an API key.

Configuration

To use, include configuration information in _config.yml. At minimum, specify a provider:

mapping:
  provider: google_static

If desired, set default dimensions for maps and a custom zoom level (the default zoom level is 10):

mapping:
  provider   : openstreetmap
  zoom       : 8
  dimensions :
    width  : 600
    height : 400

If using Google JS API, include an API key:

mapping:
  provider   : google_js
  api_key    : 123456
  zoom       : 10
  dimensions :
    width  : 600
    height : 400

Put the contents of '_includes' in your '_includes' directory and the contents of '_plugins' in your '_plugins' directory (or just copy the directories if you don't have those directories yet).

Set the relevant values in the YAML front matter of pages and posts:

mapping:
  latitude  : 51.101
  longitude : 0.1

Include the render_maps tag in your templates where you'd like the map to appear:

{% render_maps %}

Optionally, specify the dimensions for the map here:

{% render_maps width: 500, height: 500 %}

Include the required JavaScript at the foot of your templates:

{% include jekyll_mapping.html %}
</body>

You don't need to wrap the above in any if statements - jekyll-mapping won't output anything if the page doesn't have both a latitude and longitude set.

Enjoy!

Further usage

At its most basic, you can just set a latitude and longitude for a piece of content. In this case, it'll just plot that location on a map. However, you can do some other exciting things too!

If you set multiple locations, they'll all be mapped and the map will be zoomed and panned to fit them. Do it like so:

mapping:
  locations:
    - title     : foo
      latitude  : 10
      longitude : 10
    - title     : bar
      latitude  : -10
      longitude : -10

For google_js maps, you can designate one of the locations as the main one, and it'll show up with a blue marker:

mapping:
  locations:
    - title     : foo
      latitude  : 10
      longitude : 10
      main      : true
    - title     : bar
      latitude  : -10
      longitude : -10

If you'd like to use KML, you can do that too. Just add 'layers' in a similar fashion:

mapping:
  layers:
    - http://api.flickr.com/services/feeds/geo/?g=322338@N20&lang=en-us&format=feed-georss
    - http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml

Right now, multiple locations works for both google_js and openstreetmap. KML definitely works for google_js and should work for openstreetmap, but needs more testing.

Finally, you can display multiple maps:

mapping:
  - title     : meh
    latitude  : 12
    longitude : 12
  - title     : foo
    locations :
      - title     : bar
        latitude  : 10
        longitude : 10
        main      : true
      - title     : baz
        latitude  : -10
        longitude : -10

Future things to do

  • Allow for custom markers to be set (both for the site as a whole and for specific pieces of content)
  • More mapping providers (Bing?)
  • More flexibility (allow specific zoom levels to be set for individual content items, if desired)
  • Any more ideas? Please suggest them.

License and copyright

Copyright 2012 Matthew Owen

Distributed under the terms of the GNU General Public License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

jekyll-mapping's People

Contributors

matthewowen avatar throughnothing avatar ravasthi avatar

Watchers

James Cloos avatar  avatar

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.