Git Product home page Git Product logo

sheetsee-maps's Introduction

Standard - JavaScript Style Guide

sheetsee-maps

Sheetsee uses this module to handle maps in your projects. This module uses (and includes) Leaflet.js to make maps of your points, polygons, lines or multipolygons (all coordinate based). Details on what that actually looks like here. It uses (and includes) Mustache.js templates for marker popups.

You'll need to include Leaflet's map CSS in your HTML's head:

<head>
  <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
</head>

Maps: Polygons and Lines

Sheetsee-maps supports polygons and lines; so long as you have the correct coordinate structure in your cells. More details for coordinates of lines and polygons in geoJSON are here, but briefly:

Must use lowercase spreadsheet column headers: 'linestring', 'polygon', 'multipolygon' and then have cell content like so:

A linestring:

[-122.41722106933594, 37.7663045891584], [-122.40477561950684, 37.77695634643178]

A polygon:

[-122.41790771484375, 37.740381166384914], [-122.41790771484375, 37.74520008134973], [-122.40966796874999, 37.74520008134973],[-122.40966796874999, 37.740381166384914], [-122.41790771484375, 37.740381166384914]

A Multipolygon:

[[-122.431640625, 37.79106586542567], [-122.431640625, 37.797441398913286], [-122.42666244506835, 37.797441398913286],[-122.42666244506835, 37.79106586542567], [-122.431640625, 37.79106586542567]],
[[-122.43352890014648, 37.78197638783258], [-122.43352890014648, 37.789031004883654], [-122.42443084716797, 37.789031004883654], [-122.42443084716797, 37.78197638783258], [-122.43352890014648, 37.78197638783258]]

To Use

This module is used as a part of Sheetsee.js. You can download the full version or build your own with a command line tool.

You'll create a little bit of HTML and then some JavaScript in your HTML to use this. You can customize marker color, popup content and enable/disable clustering in your map.

Methods

Here are the functions you can use!

Sheetsee.createGeoJSON(data, optionsJSON)

  • data JSON array of data
  • optionsJSON array of strings, spreadsheet column title

If you'd like to just generate geoJSON from a spreadsheet you can use this method.

This takes in your spreadsheet data in JSON format (which you can get with Tabletop.js)and the parts of your data, optionsJSON, that you plan on including in your map's popups. These will be column headers in your spreadsheet in an array of strings.

If you're not going to have popups on your markers, don't worry about it then and just pass in your data (by default it will use all the row's information).

var optionsJSON = ['name', 'breed', 'cuddlability']
var geoJSON = Sheetsee.createGeoJSON(data, optionsJSON)

It will return an array in the special geoJSON format that map making things love.

Sheetsee.loadMap(options)

This method will generate a map for you on the page (it also generates the geoJSON for the map).

  • options object required
    • data your spreadsheet data array required
    • mapDiv the id of the div in your HTML to contain the map required
    • geoJSONincludes array of strings of column headers to include in popups
    • template HTML/Mustache template for popups
    • cluster a true/false boolean, do you want your markers clustered
    • hexcolor pick one color for your markers
var mapOptions = {
  data: data, // required
  mapDiv: 'map', //required
  geoJSONincludes: ['Name', 'Animal', 'Rating'], // optional
  template: '<p>{{Name}}—{{Animal}}—{{Rating}}</p>', // optional
  cluster: true, // optional
  hexcolor: '#e91e63' // optional
}
Sheetsee.loadMap(mapOptions)

Breaking Changes The latest version of Sheetsee replaces three methods ('loadMap', 'addTileLayer', 'addMarkerLayer') with one loadMap which takes in an object of map options.

Marker colors

If you create a column title hexcolor in your spreadsheet and fill each cell with hex color codes, those will be used to color your markers. If you define a color for hexcolor in the options you pass to your map it will override colors in the spreadsheet data.

View Demo Visit Site

sheetsee-maps's People

Contributors

crokinolemaster avatar jlord avatar tomkeays avatar ughitsaaron 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

Watchers

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

sheetsee-maps's Issues

Remove dependency on Mapbox.js in favour of native Leaflet.js

This (splendid-looking) plugin would have much wider applicability if it wasn't tied to Mapbox.js but could be used with native Leaflet.js (which Mapbox.js uses internally). Not everyone wants to be tied into Mapbox's infrastructure.

Is there actually much of Mapbox.js being used that isn't in Leaflet.js? I find it hard to believe that showing GeoJSON on a map really needs Mapbox.js significantly.

Mapbox styles

How to use Mapbox styles in the maps. I can use the tile layers (Like: Sheetsee.addTileLayer(map, 'volt.XXXX'), but not the styles through Mapbox's sharing options.

What I am missing?

PS: love sheetsee

Update to latest Mapbox.js

Seems like the Mapbox.js version is out of date. I'd be happy to do some work on this later this weekend/next week?

Maybe can't have two maps on one page?

module.exports.addMarkerLayer = function(geoJSON, map, template) {
  if (!template) {
    template = makePopupTemplate(geoJSON)
    ich.addTemplate(template.name, template.template)
  }
  else {
   var template = {"template": template}
   template.name = "popup"
   ich.addTemplate(template.name, template.template)
  }

Think template.name needs to be a randomly generated thing so that you don't have two templates with the same name.

How to handle Polygons

Map-section of Sheetsee.js looks very promising for a project I'm trying. Thanks for that work.

It's easily understandable, how lat & long of point markers must be prepared in spreadsheet for letting sheetsee work with it - one column lat plus one column long. Docs are saying, that polygon features are supported. But how to fill in a (varying) number of coordinates to show a polygon? Couldn't find this information in the samples.

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.