wrld.js

L.Wrld.polygon(latLngs, options)

Note: For most use cases, L.polygon should be used instead of this type.

L.Wrld.Polygon creates natively rendered polygons, which should improve performance. However, it cannot be styled as easily as L.polygon.

// Create a polygon covering downtown San Francisco.
L.Wrld.polygon([
    [37.786617, -122.404654],
    [37.797843, -122.407057],
    [37.798962, -122.398260],
    [37.794299, -122.395234]
]).addTo(map);
// Create a polygon with holes
var polygonPoints = [
  [[37.786617, -122.404654], //outer ring
  [37.797843, -122.407057],
  [37.798962, -122.398260],
  [37.794299, -122.395234]],

  [[37.795168, -122.402665], //hole
  [37.792300, -122.403781],
  [37.792656, -122.400420]],

  [[37.790979, -122.403028], //another hole
  [37.790404, -122.401272],
  [37.788705, -122.402579],
  [37.789706, -122.403516]]];

var poly = L.Wrld.polygon(polygonPoints).addTo(map);

Argument Type Description
latLngs number[] An array of points that define the perimeter and optionally holes of the polygon.
options object Accepts all of the options to L.polygon, plus additional wrld.js entries.

Options

Options Type Default Description
color number[] [0,0,1,0.5] The color of the polygon as an array [R,G,B,A], with values between 0.0 and 1.0
elevation number 0.0 Altitude of the polygon above ground or sea level in meters.
elevationMode string ‘heightAboveGround’ Whether altitude is measured above ground level (“heightAboveGround”) or sea level (“heightAboveSeaLevel”).
indoorMapId string ’’ The id of the indoor map with which the Polygon will be associated.
indoorMapFloorId number 0 The id of the indoor map floor with which the Polygon will be associated.

Methods

polygon.getColor()

Get the color of the polygon.

polygon.setColor(color)

Set the color of the polygon.

Argument Type Description
color number[] The color of the polygon as an array [R,G,B,A], with values between 0.0 and 1.0

polygon.getPoints()

Get the points that define the perimeter of the polygon.

polygon.addHole(points)

Add an interior ring to the polygon.

Argument Type Description
points number[] An array of points that define the perimeter of the hole.

polygon.getHoles()

Gets an array of the holes in this polygon. Empty array returned if no holes in polygon.

v0.1.1335