GithubHelp home page GithubHelp logo

imclab / leaflet.widget Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tnightingale/leaflet.widget

1.0 2.0 1.0 345 KB

Leaflet vector management widget.

Home Page: http://tnightingale.github.com/Leaflet.widget

License: Other

leaflet.widget's Introduction

Leaflet.widget

Provides a handler which binds a Leaflet map to a HTML element. GeoJSON data stored as text in the element will be parsed and added to the map. New features added to the map (via Leaflet.draw, Leaflet.paste, etc...) along with existing features can be encoded to GeoJSON and inserted into the bound HTML element with map.widget.write().

Includes Leaflet.select; a control extension for Leaflet.draw. Leaflet.select.js provides a 'selector' tool allowing one or many features to be selected. Actions can then be performed on selected features. Currently only a 'remove' action has been implemented.

Try the demo.

Usage

To use:

  1. Include an options object under a 'widget' property in your Leaflet map's options. The object must contain a 'attach' property with its value being an HTML element (or the id of one) to bind to.
  2. Enable widget with widget.enable()
  3. When you're ready, write widget features to attached HTML element with widget.write.

E.g:

// *.html
<form id='leaflet-widget-form'>
  <textarea id='leaflet-widget-input'> ... GeoJSON here ... </textarea>
  <input type='submit' />
</form>

// *.js
var form = L.DomUtil.get('leaflet-widget-form'),
    layer = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'),
    map = L.map('map', {
            layers: [layer]
            widget: { attach: 'leaflet-widget-input' },
            cardinality: 4
          });

// It's important to enable the widget to ensure layers are added to the map.
map.widget.enable();

// Write widget features when form is submitted.
L.DomEvent.on(form, 'submit', map.widget.write, map.widget);

The widget will center on any features loaded into the map from the attached element. To disable this set the option: autoCenter = false.

By default an unlimited number of features can be added to the widget. To allow only one, set the option: multiple = false. You can limit to X number of features by setting cardiniality = X.

Requires

leaflet.widget's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

web5design

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.