• Stars
    star
    224
  • Rank 176,815 (Top 4 %)
  • Language
    JavaScript
  • Created almost 12 years ago
  • Updated over 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Easily create interactive maps from data in Google Spreadsheets. Supports Google Maps, Leaflet, Mapbox, MapQuest, etc.

Mapsheet.js

Mapsheet.js makes an interactive map out of a Google Spreadsheet. It depends on Tabletop.js and whatever map provider you're using (supports Leaflet, Google Maps, Mapbox (which is basically Leaflet!), and MapQuest).

It is also dead simple.

Optional but fun: Mapsheet supports Handlebars for info window templates.

So how do I do this?

First, you make a published Google Spreadsheet. You can find out how to do this in the Tabletop docs. The only columns you actually need are latitude and longitude. We're also friendly enough to allow lat, lng, long, any probably anything else you can think of.

A pretty full-fledged example might be: let's say you have some restaurants you'd like to map, and you want some info to show up in a popup when you click on the marker. Here goes nothing:

<html>
  <body>
    <!-- We'll need to include Google Maps, Handlebars for templating, and jQuery for general futzing about -->
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

    <!-- Tabletop.js for accessing Google Spreadsheets and Mapsheet.js for mapping, of course -->
    <script type="text/javascript" src="tabletop.js"></script>
    <script type="text/javascript" src="mapsheet.js"></script>

    <!-- This is where the map will go -->
    <div id="map"></div>

    <!-- Let's make the map not too big -->
    <style>
      #map {
        width: 600px;
        height: 500px;
      }
    </style>

    <!-- This is the popup you'll get when you click a marker. 
         {{these}} are columns in your spreadsheet -->
    <script id="popup-template" type="text/x-handlebars-template">
      <img src="{{image}}">
      <h3>{{name}}</h3>
      <p>{{location}} in {{neighborhood}}</p>
    </script>

    <!-- Okay, time to do this! -->
    <script type="text/javascript">
      $(document).ready( function() {       
        // Make sure the spreadsheet is published!
        var published_spreadsheet_url = 'https://docs.google.com/spreadsheet/pub?key=0AmYzu_s7QHsmdGNzMnkwbXRyVmdyZGdrWVRoMWRKVGc&output=html'; 

        // Let's get the popup template and compile it using Handlebars
        var source   = $("#popup-template").html();
        var template = Handlebars.compile(source);

        // OK, now let's make the map
        var map = Mapsheet({
          key: published_spreadsheet_url,
          element: "map",
          popupTemplate: template
        });
      });
    </script>
  </body>
</html>

Most of the code is just including libraries! And if you'd like to map pet stores or murder scenes instead? Just make a different spreadsheet, change the URL, and edit the popup template. Voila: a brand new map.

Details

The Moving Parts

Mapsheet itself

Initialization options

When you initialize Mapsheet you have plenty of options to pick through. key and element are the only two required parameters, though! I've tried to note the ones that are provider-specific.

key is the URL to the published Google Spreadsheet you're dealing with

element is the id of the element that's going to become the map. You can also pass in an element.

click is a callback for when a marker is clicked. this is the default this, the first parameter is the event and the second is the Mapsheet.Point (check the examples!)

fields is an array of columns to display in the info window if you don't feel like using a template. Check the examples!

map is the map, if you feel like rendering it without using a Mapsheet provider.

popupContent is a function that returns content for the info window popup. It's passed the Tabletop model for the given row. It overrides both fields and popupTemplate.

popupTemplate is the id of a Handlebars template that will be used for the info window that pops up when you click the marker on the map. You can also provider the compiled template instead.

provider is the provider of the map service. I detail the providers a bit more below, but your options are

	Mapsheet.Providers.Leaflet
	Mapsheet.Providers.Google
	Mapsheet.Providers.MapBox
	Mapsheet.Providers.MapQuest

markerOptions are passed through to the marker, and are used for things like specifying marker shadows and other very-specific-to-the-provider details.

titleColumn is the column that you'd like to use as the title of the point (e.g., the name of the place). This is only important if using fields, or if you want hover effects for MapQuest or Google.

callback is the callback for when the map has been successfully drawn. It will be passed two objects: the mapsheet object and the tabletop object. See the Tabletop.js docs if you'd like more info on that part.

callbackContext provides the context of the callback, if necessary.

proxy passes right through to Tabletop.

markerLayer is the layer that you'd like to render your markers on (not supported by Google)

layerOptions are options passed passed to the marker layer if you want a custom backing map, or specify attribution, etc (Leaflet only)

Methods/Properties

.map() is the rendered map

.points is an array of Mapsheet.Point objects

Mapsheet.Point

Methods/Properties

.model is the Tabletop model of the row the marker is associated with

.longitude() is the longitude, pulled from a column named lng, long or longitude

.latitude() is the latitude, pulled from a column named lat or latitude

.title() gets the title of the marker - this column is set through titleColumn

.coords() gives you the marker's [ lat, lng ]

.get(name) returns the value of the given column. Not that it matters to you, but: Multi-word and capitalized things, like 'Web URL' are fixed up in an attempt to successfully read from tabletop, i.e. converted into lowercase with spaces removed (Web URL turns into weburl).

.content() uses popupContent, popupTemplate, or titleColumn and fields to create content for the info window popup

.isValid() returns true if latitude() and longitude() both return valid floats

.marker returns the raw marker (from Google or MapQuest etc)

Mapsheet.Provider.Whatever

Must respond to .initialize(id) and .drawPoints(pointsArray).

Their constructor sets up the options, initialize draws the map, and drawPoints puts the points on it and auto-fits the zoom and bounds.

Providers

Google Maps as Mapsheet.Providers.Google (default)

Leaflet (using MapQuest tiles by default, but supports CloudMade, etc) as Mapsheet.Providers.Leaflet (be sure to include the CSS)

MapBox as Mapsheet.Providers.MapBox

MapQuest as Mapsheet.Providers.MapQuest

Customizing Your Map

Styling info windows

All of the info boxes live inside of a <div class='mapsheet-popup'></div>, so feel free to apply styles to .mapsheet-popup h3, etc

Customizing the map itself (roads, water, etc)

You'll need to pick a provider that allows map customization

CloudMade has a billion styles over at their map style editor, you'll just have to check out the cloudmade.html example. You need an API key, but it ain't tough beyond that.

MapBox could also work for you, especially if you have a lot of stuff going on.

Custom Markers

I think it's really stupid that, generally speaking, providers make it so tough to have custom-colored markers. So I tried to make it easy!

Custom markers are supported for Google Maps, Leaflet, and MapBox (to varying degrees).

Possibilities

Custom color: Add a hex color column in your spreadsheet to customize the color of each marker.

Custom icon: If you want to an specify icon for each point, add an icon url column in your spreadsheet. You'll probably want to make it the full path, i.e. http://blahblah.com/images/icons/blah.png

Custom default icon: If want every point to have the same marker, just not the default, you can pass a default icon URL through markerOptions, typically as iconUrl

Custom icon + shadows: Check the examples/leaflet-with-marker-customization.html example, it's complicated.

Provider support

Google Maps: custom colors, custom icons, custom default icon

MapBox: custom icons

Leaflet: custom icons, custom icons + shadows, custom default icon

General notes on using colored/custom icons

If you're unsure of what hex colors are, pop on over to http://www.colorpicker.com or Wikipedia - they're just strings of numbers/letters like FF36A2 that end up as colors.*

When you customize your icons using Leaflet, you'll probably want to pass some markerOptions as well to make sure everything lines up nicely. markerOptions: { iconSize: [32, 37], iconAnchor: [16, 37] } works for the icons from the Map Icons Collection. Read more on the Leaflet site.

Using other Leaflet tile providers

Leaflet defaults to serving tiles from MapQuest, because it's free, and doesn't require an API key. If you'd like to use CloudMade or something instead, you'll need to make some changes. You'll need to pass in a mapOptions along the lines of the following

	mapOptions: {
		subdomains: 'abc',
		tilePath: 'http://{s}.tile.cloudmade.com/{apikey}/{styleId}/256/{z}/{x}/{y}.png',
		styleId: 1930,
		apikey: 'Your CloudMade API Key',
		attribution: 'An appropriate credit line without MapQuest'
	}

And then you should be all set!

Examples

There are a lot of examples in /examples, check them out!

If you're looking for the least complicated one, check out fields.html. It isn't too customizable but it gets the job done. leaflet-with-marker-customization.html is the zaniest of the bunch.

Etc

Credits

Hi, I'm Jonathan Soma. I run the Brooklyn Brainery, and make all sorts of nonsense.

Todo

Fix up the docs to actually be nice and pleasant

Don't show popups if there's no content in the popup

Replace the sample map with some quality, dedicated sample maps

Callbacks callbacks everywhere

Notes about styling your infoboxes

More Repositories

1

tabletop

Tabletop.js gives spreadsheets legs
JavaScript
3,770
star
2

flatware

S3 caching of Google Spreadsheets for Tabletop.js
Ruby
91
star
3

persine

Persine is an automated tool to study and reverse-engineer algorithmic recommendation systems.
Python
89
star
4

selenium-github-actions

Python
85
star
5

fuzzy_pandas

Fuzzy matches and merging of datasets in pandas using csvmatch
Python
71
star
6

kull

A tool to interactively select text regions of PDFs and images. Mostly for use with PDFQuery or tesseract (UZN/OCR zone files)
Vue
51
star
7

spotify-langchain-gpt

Building Spotify playlists based on vibes using LangChain and GPT
Jupyter Notebook
50
star
8

gs-spreadsheet-manager

A slightly more object-oriented, ORM-y, and altogether pleasant way of dealing with Google Spreadsheets when using Google Apps Script.
JavaScript
45
star
9

hexagon-grids-for-adobe-illustrator

A simple script to automatically build hexagon grids in Illustrator, for things like D3 hex cartogram visualizations
JavaScript
18
star
10

tesseract-uzn

Simplify using uzn files with tesseract for OCR
Jupyter Notebook
17
star
11

ai2html-walkthroughs

Code samples for ai2html walkthroughs
HTML
15
star
12

designingviz

A step-by-step design guide for data visualizations
JavaScript
15
star
13

storytelling-2015

HTML
15
star
14

NICAR20-geocoding-apis

Geocoding APIs repo for NICAR20 session
Jupyter Notebook
14
star
15

nicar23-huggingface

Jupyter Notebook
13
star
16

python-disease-modeling

A walkthrough of how SIR infectious disease modeling works, along with a do-it-yourself Python COVID model that you can use to simulate a lockdown.
Jupyter Notebook
13
star
17

data-studio-projects

12
star
18

simplified-scrollama-scrollytelling

Non-d3, barebones version of scrollama.js scrollytelling examples
HTML
11
star
19

autoscraper-changes

Tiny template that uses GitHub Actions and Python to automatically scrape the BBC's homepage every four hours.
Python
11
star
20

clipped-and-georeferenced-images-from-google-earth-in-qgis-3

Georeference images from Google Earth in QGIS 3, then clip them so they aren't shaped all weird.
11
star
21

d3-topojson-data-guide

How to wrangle your data into a useable TopoJSON format for making D3 visualizations
10
star
22

NICAR20-intro-d3

Base for an introductory walkthrough of D3's features for NICAR 2020
HTML
8
star
23

abraji24-ai-audio-video

HTML
8
star
24

nicar23-building-ai-editors

Conceptual framework for building AI editors to help with journalism workflows
Jupyter Notebook
8
star
25

hardboiled

A node.js detective kit for investigating how web sites are built.
JavaScript
8
star
26

mediaparty-folktales

Notes and code for learning Hungarian folktales through semantic search and GPT: Media Party 2023 lightning talk
Jupyter Notebook
8
star
27

nicar24-beyond-chatgpt

Jupyter Notebook
7
star
28

ire24-scraping

Tutorials for IRE 2024 about using Playwright to scrape state-level license and violations data
Jupyter Notebook
7
star
29

2023-abraji-ai-workshop

Journalism in AI workshop for Abraji 2023
6
star
30

interactives-class-content

6
star
31

lede-notes

Notes from Summer 2015's Lede Python class
6
star
32

playfair-projects

Common repository of projects for Playfair
Jupyter Notebook
6
star
33

chatgpt-for-educators

Slides for a talk about the use and abuse of ChatGPT in the classroom
HTML
6
star
34

data-studio-projects-2022

Projects for Columbia J School's Data Studio 2022
Python
6
star
35

nb2jekyll

Use nbconvert to convert IPython/Jupyter Notebooks into Jekyll-compatible Markdown + Front Matter
Python
5
star
36

NICAR20-apis

Jupyter Notebook
5
star
37

final_final_v2_truefinal

JavaScript
4
star
38

quarto-tutorial

Quarto framework tutorial for C+J/European Data Journalism Conf 2023
HTML
4
star
39

how-to-host-on-github-pages

4
star
40

lede-projects-2023

Projects for Lede Program 2023
Python
3
star
41

page-templates

HTML
3
star
42

data-studio-projects-2024

Python
3
star
43

excel-tutorials

3
star
44

data-studio-projects-2023

Projects for Columbia Journalism School's Data Studio course, Spring 2023
Python
3
star
45

2023-ona-before-beyond-chatgpt

Slides and links for AI Tools from Before (and Beyond!) ChatGPT (ONA 2023)
3
star
46

lede-projects-2022

Projects for Lede Program 2022
Python
3
star
47

walkthrough-github

this is a walkthrough about how to use git and github desktop
Jupyter Notebook
3
star
48

dotenv-example

Python
2
star
49

automatic-scraper

Python
2
star
50

autoscraper-history

Python
2
star
51

auto-scraper

an automatic scraper?????
Python
2
star
52

sample-d3-project

HTML
2
star
53

lede-2023-auto-scraper

Jupyter Notebook
2
star
54

2023-journalismai

Jupyter Notebook
2
star
55

example-svelte-viz-page

JavaScript
2
star
56

lede-websites

Thousands of websites for various classes I've taught over the years, primarily for Columbia's Lede Program
Jupyter Notebook
2
star
57

jupyter-notebook-site-autobuild

Lil' baby static site builder that creates a website from Jupyter notebooks and markdown files
CSS
2
star
58

words

Jupyter Notebook
1
star
59

pandas-question-factory

a question factory. for pandas.
Python
1
star
60

fanciframe

Let's embed iframes with grace and beauty
JavaScript
1
star
61

2024-abraji-ai-docs

Jupyter Notebook
1
star
62

foundations

Code for Lede Program 2017 Foundations class I guess????
1
star
63

slack-files

List your large slack files so you can search for and delete them
Ruby
1
star
64

normal-ai

HTML
1
star
65

bottlejack

JavaScript
1
star
66

automatic-scraper-bbc

Python
1
star
67

data-buddies

It's little datas!!!
1
star
68

track_url

A Sublime Text 2 plugin for following along with the ever-changing contents of a URL. I use it so students can follow along.
Python
1
star
69

typing-of-the-dead

Code to extract phrases from the impossilby incredible Dreamcast game The Typing of the Dead
Python
1
star
70

sample-story

HTML
1
star
71

charset-downloader

7-bit ASCII ought to be enough for ะฐะฟัƒะฑะพะดัƒ
HTML
1
star
72

advanced-scraping-with-playwright

Notes for the Advanced Scraping with Playwright session in February 2024
HTML
1
star
73

demodemo

JavaScript
1
star
74

fancy-github-guide

A guide to a fancy github experience https://jonathansoma.com/fancy-github/
1
star
75

miscellaneous-data

Miscellaneous and most probably useless data sets that I've used for this or that
1
star
76

autoscraper-mailer

Scrapes on a schedule, emailing out whatever it finds.
Python
1
star
77

tiny-spider

Convert spreadsheets into network-friendly formats, a.k.a. from ๐Ÿ“ˆ to ๐Ÿ•ธ, using ๐Ÿ•ท
JavaScript
1
star
78

altair-reference

HTML
1
star
79

transliteration_project

GLSL
1
star
80

2023-ona-trusting-ai

Slides and links for Trusting AI in the newsroom: Hallucinations, bias, security and labor (ONA 2023)
1
star
81

nyc-schools

Jupyter Notebook
1
star
82

data-studio

HTML
1
star