No description or website provided.
JavaScript CSS HTML
Latest commit b514442 Nov 21, 2015 Ondrej Zvara Remove artificial files

README.md

L.MeasureAreaControl

Simple Leaflet control for measuring element's area. Check the demo.

Implements GeometryUtil.js by Leaflet.draw

Requirements

  • Leaflet 0.7.3
  • Font-awesome 4.1.0

Cross-browser compatibility

Tested on:

  • IE8, IE9, IE10
  • Mozilla 30 (linux)
  • Mozilla 29.0.1 (win)
  • Chrome 35.0.1916.153 (linux)
  • Chrome 35.0.1916.153 (Win)

API

Constructor

Constructor Description
L.Control.measureAreaControl(Object options, Array layers[]); Accepts options object and array of layers of different types
L.Control.measureAreaControl(Object options); Accepts options object
L.Control.measureAreaControl(); Uses default options

The constructor accepts options object, just like L.Control does. For more details about options see below. Second parameter is an array of layers of class L.Polygon/L.Rectangle and L.LayerGroup as well as all its children (L.FeatureGroup and L.GeoJson, consisting of L.Polygon or L.Rectangle. L.Circle and L.CircleMarker are NOT supported!

Options

Property Type Default Description
position String 'topright' The position of the control. More here.
geodesic Boolean true If true, returns value in square meters. Else, returns hectares

Methods

method Param Description
addLayer(layer) layers of different types (see note) accepts layers not in array
removeLayer(layer) layers of different types (see note) accepts layers not in array

Accepts same types of layers as constructor, but not as an array, but as single objects. L.Circle is NOT suported.

Usage

Initialize tool and pass layers to constructor:

   // adding test data
   var geojson1 = L.geoJson(JSON.parse(data1),opts1).addTo(map);
   var geojson2= L.geoJson(JSON.parse(data2),opts2).addTo(map);

   // setting options 
   var options = {geodesic: true};

   //input parameter is Array of layers
   var layers = [geojson1, geojson2];

   // initialize control
   var control = L.Control.measureAreaControl(options, layers).addTo(map);

You can add or remove layers also later:

   var polygon = L.polygon([
        [48.10804729138659, 17.106292247772217],
        [48.10853443729303, 17.106292247772217],
        [48.10853443729303, 17.1071720123291],
        [48.10804729138659, 17.1071720123291],
        [48.10804729138659, 17.106292247772217]
    ]).addTo(_map);
    control.addLayer(polygon);
   // control.removeLayer(polygon);

Package instruction

  1. download and unpack repo
  2. cd repo
  3. sudo npm install
  4. grunt install

...and you are up and running.

TODO

Feel free to propose, report or whatever.

Thanks

Thanks to guys from Leaflet.draw for inspiration.