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,255,128] The color of the polygon as an array [R,G,B,A], with values between 0 and 255.
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 identifier of the indoor map floor on which the Polygon should be displayed. In the WRLD Indoor Map Format, this corresponds to the ‘z_order’ field of the Level object.

Methods

polygon.addTo(map)

Adds the polygon to the map.

Argument Type Description
map L.Wrld.Map The map which the polygon will be added to.

polygon.remove()

Removes the polygon from the map.

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 and 255.

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