Leaflet.Antimeridian
A plugin to allow polygons and polylines to naturally draw across the Antimeridian (or the Internation Date Line) instead of always wrapping across the Greenwich meridian.
Useful when displaying lines that might cross or partially cross the Antimeridian.
Simple polygons/polylines without using Leaflet.Antimeridian |
---|
Using Leaflet.Antimeridian |
---|
Demo
Installation
Requires leaflet@1.0.0.
Usage
This plugin may be downloaded as a single Javascript file and directly included in the project. It may also be downloaded as an NPM project, complete with tests and examples.
Javascript Download
To download the source file and include in the the project, run:
git clone https://github.com/briannaAndCo/Leaflet.Antimeridian.git
cd Leaflet.Antimeridian
git checkout v1.0.0
A folder named dist
will appear, with the file leaflet.antimeridian-src.js
inside it. Include that folder in your index.html file using the paths below.
Download Source and Compile
If you would like to download and compile the source, clone the repository as above. Then checkout master
instead of v1.0.0
.
Then follow the steps below to build the source.
npm install \\Will install the npm dependancies including leafletjake test \\Run the testsnpm run rollup \\This will generate the leafletantimeridian-srcjs file
Include the generated file the same way as the above method.
Examples
To run the examples, first download and compile the source.
Then open the example files in your browser. They should be in the form:
file:///path/to/examples/Leaflet.Antimeridian/examples/Wrapped.Polygon.html
Usage
To create a L.Wrapped.Polyline or L.Wrapped.Polygon, simply pass an array of latlngs to the factory function or the constructor as the first argument. The second optional argument is options object.
var mymap = L;L; var pointList = 2000 1400 L L; //Create and display a wrapping polygon.pointList color: 'red' weight: 3 opacity: 05 smoothFactor: 1 noWrap:true ; //Create and display a wrapping polyline over the same set of points. pointList color: 'blue' weight: 3 opacity: 05 smoothFactor: 1 noWrap:true ;});
API reference
Factories
Factory | Description |
---|---|
L.Wrapped.Polyline(LatLng[] latlngs, options options?) |
Create a automatically wrapping polyline that will take all the usual polyline options. |
L.wrappedPolyline(LatLng[] latlngs, options options?) |
Factory method that wraps the L.Wrapped.Polyline constructor. |
L.Wrapped.Polygon(LatLng[] latlngs, options options?) |
Create a automatically wrapping polygon that will take all the usual polygon options. |
L.wrappedPolygon(LatLng[] latlngs, options options?) |
Factory method that wraps the L.Wrapped.Polygon constructor. |
Utility Methods
Method | Returns | Description |
---|---|---|
L.Wrapped.sign(Number number) |
Number |
Returns NaN for non-numbers, 0 for 0, -1 for negative numbers, 1 for positive numbers |
L.Wrapped.calculateAntimeridianLat(LatLng latLngA, LatLng latLngB) |
Number |
Calculates the latitude at which the two points will cross the Antimeridian. Returns the latitude. |
L.Wrapped.isCrossMeridian(LatLng latLngA, LatLng latLngB) |
boolean |
Returns true if the line between the two LatLngs crosses either meridian. |
L.Wrapped.isBreakRing(LatLng latLngA, LatLng latLngB) |
boolean |
Returns true if the line between the two LatLngs should be broken across the meridian. |