Coder Social home page Coder Social logo

data-map's Introduction

data-map: easily create geojson-driven maps in HTML pages by using data-* attributes, no coding required. data-map only supports using point features as placemarks, but can show customized popups. Pull requests for additional functionality welcome.

Documentation

You create a map simply by adding a div to your page with class `data-map', and setting the following attributes.

  • data-geojson: the URL of a GeoJSON file which contains your GeoJSON data (only points are supported for now)
  • data-popup: the popup text for the placemarks. You can reference the fields in the GeoJSON using sprintf-style format strings, e.g. %(name)s would insert the field name
  • data-lat, data-lon and data-zoom: the initial latitude, longitude and zoom level for the map.
  • data-basemap: (optional, advanced) the URL of custom tiles to use; defaults to MapQuest OSM.
  • data-attribution: (optional) any attribution you would like to display. If data-basemap is set, this will be used as the attribution; otherwise, the attribution for MapQuest tiles will be appended.

Additionally, you will need to set the map to be a particular size, for instance by specifying style="width: 600px; height: 600px". Bear in mind also that if you specify any HTML in the popup or the attribution, double quotes will need to be written as ".

To use data-map, just include its JavaScript file in your page. You'll need to have already loaded jQuery. On my blog, I load the script on every page; it shouldn't hurt anything else.

Here is a working example, which you can see in action.

<div class="data-map" style="width: 700px; height: 400px" data-lat="38" data-lon="-97" data-zoom="4" data-geojson="demo.geojson" data-popup="<h2>%(name)s</h2>%(desc)s"></div>

Portions from sprintf.js by Alexandru Marasteanu.

data-map's People

Watchers

 avatar  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.