Other Layers
DG.LayerGroup
Used to group several layers and handle them as one. If you add it to the map,
any layers added or removed from the group will be added/removed on the map as
well. Extends DG.Layer
.
DG.layerGroup([marker1, marker2]).addLayer(polyline).addTo(map);
Creation
Factory | Description |
---|---|
DG.layerGroup(
|
Create a layer group, optionally given an initial set of layers. |
Options
Options inherited from Layer
Events
Events inherited from Layer
Methods
Method | Returns | Description |
---|---|---|
toGeoJSON() |
Object |
Returns a
GeoJSON representation of the layer group (as a GeoJSON GeometryCollection ). |
addLayer(
|
this |
Adds the given layer to the group. |
removeLayer(
|
this |
Removes the given layer from the group. |
removeLayer(
|
this |
Removes the layer with the given internal ID from the group. |
hasLayer(
|
Boolean |
Returns true if the given layer is currently added to the group. |
clearLayers() |
this |
Removes all the layers from the group. |
invoke(
|
this |
Calls methodName on every layer contained in this group, passing any
additional parameters. Has no effect if the layers contained do not
implement methodName . |
eachLayer(
|
this |
Iterates over the layers of the group, optionally specifying context of the iterator function.
group.eachLayer(function (layer) {
layer.bindPopup('Hello');
}); |
getLayer(
|
Layer |
Returns the layer with the given internal ID. |
getLayers() |
Layer[] |
Returns an array of all the layers added to the group. |
setZIndex(
|
this |
Calls setZIndex on every layer contained in this group, passing the z-index. |
getLayerId(
|
Number |
Returns the internal ID for a layer |
Methods inherited from Layer
Methods inherited from Evented
DG.FeatureGroup
Extended DG.LayerGroup
that also has mouse events
(propagated from members of the group) and a shared bindPopup method.
DG.featureGroup([marker1, marker2, polyline])
.bindPopup('Hello world!')
.on('click', function () {
alert('Clicked on a group!');
})
.addTo(map);
Creation
Factory | Description |
---|---|
DG.featureGroup(
|
Create a feature group, optionally given an initial set of layers. |
Options
Options inherited from Layer
Events
Events inherited from Layer
Methods
Method | Returns | Description |
---|---|---|
setStyle(
|
this |
Sets the given path options to each layer of the group that has a setStyle method. |
bringToFront() |
this |
Brings the layer group to the top of all other layers |
bringToBack() |
this |
Brings the layer group to the top of all other layers |
getBounds() |
LatLngBounds |
Returns the LatLngBounds of the Feature Group (created from bounds and coordinates of its children). |
Methods inherited from LayerGroup
Methods inherited from Layer
Methods inherited from Evented
DG.GeoJSON
Represents a GeoJSON object or an array of GeoJSON objects. Allows you to parse
GeoJSON data and display it on the map. Extends DG.FeatureGroup
.
DG.geoJson(data, {
style: function (feature) {
return { color: feature.properties.color };
},
})
.bindPopup(function (layer) {
return layer.feature.properties.description;
})
.addTo(map);
Creation
Factory | Description |
---|---|
DG.geoJSON(
|
Creates a GeoJSON layer. Optionally accepts an object in
GeoJSON format to display on the map
(you can alternatively add it later with addData method) and an options object. |
Options
Option | Type | Default | Description |
---|---|---|---|
pointToLayer |
Function |
* |
A Function defining how GeoJSON points spawn maps API layers. It is internally
called when data is added, passing the GeoJSON point feature and its
LatLng .
The default is to spawn a default Marker :
function(geoJsonPoint, latlng) {
return DG.marker(latlng);
}
|
style |
Function |
* |
A Function defining the
Path options
for styling GeoJSON lines and polygons, called internally when data is added.
The default value is to not override any defaults:
function (geoJsonFeature) {
return {}
}
|
onEachFeature |
Function |
* |
A Function that will be called once for each created
Layer ,
after it has been created and styled. Useful for attaching events and popups to features.
The default is to do nothing with the newly created layers:
function (layer) {}
|
filter |
Function |
* |
A Function that will be used to decide whether to show a feature or not.
The default is to show all features:
function (geoJsonFeature) {
return true;
}
|
coordsToLatLng |
Function |
* |
A Function that will be used for converting GeoJSON coordinates to
LatLng s.
The default is the coordsToLatLng static method. |
Options inherited from Layer
Events
Events inherited from Layer
Methods
Methods inherited from FeatureGroup
Methods inherited from LayerGroup
Methods inherited from Layer
Methods inherited from Evented
Functions
There are several static functions which can be called without instantiating DG.GeoJSON:
Function | Returns | Description |
---|---|---|
geometryToLayer(
|
Layer |
Creates a Layer from a given
GeoJSON feature. Can use a custom pointToLayer and/or
coordsToLatLng functions if provided as options. |
coordsToLatLng(
|
LatLng |
Creates a LatLng object from an array
of 2 numbers (longitude, latitude) or 3 numbers (longitude, latitude, altitude) used in GeoJSON for points. |
coordsToLatLngs(
|
Array |
Creates a multidimensional array of LatLng s
from a GeoJSON coordinates array. levelsDeep specifies the nesting level (0 is for an array
of points, 1 for an array of arrays of points, etc., 0 by default). Can use a custom
coordsToLatLng function. |
latLngToCoords(
|
Array |
Reverse of coordsToLatLng |
latLngsToCoords(
|
Array |
Reverse of coordsToLatLngs
closed determines whether the first point should be appended to the end of
the array to close the feature, only used when levelsDeep is 0. False by default. |
asFeature(
|
Object |
Normalize GeoJSON geometries/features into GeoJSON features. |
DG.GridLayer
Generic class for handling a tiled grid of HTML elements. This is the base class for all tile layers and
replaces TileLayer.Canvas
. GridLayer can be extended to create a tiled grid of HTML Elements
like <canvas>
, <img>
or <div>
. GridLayer will
handle creating and animating these DOM elements for you.
Synchronous usage
To create a custom layer, extend GridLayer and impliment the createTile()
method,
which will be passed a Point
object with the x
,
y
, and z
(zoom level) coordinates to draw your tile.
var CanvasLayer = DG.GridLayer.extend({
createTile: function (coords) {
// create a <canvas> element for drawing
var tile = DG.DomUtil.create('canvas', 'leaflet-tile');
// setup tile width and height according to the options
var size = this.getTileSize();
tile.width = size.x;
tile.height = size.y;
// get a canvas context and draw something on it using coords.x, coords.y and coords.z
var ctx = canvas.getContext('2d');
// return the tile so it can be rendered on screen
return tile;
},
});
Asynchrohous usage
Tile creation can also be asyncronous, this is useful when using a third-party drawing library. Once the tile is finsihed drawing it can be passed to the done() callback.
var CanvasLayer = DG.GridLayer.extend({
createTile: function (coords, done) {
var error;
// create a <canvas> element for drawing
var tile = DG.DomUtil.create('canvas', 'leaflet-tile');
// setup tile width and height according to the options
var size = this.getTileSize();
tile.width = size.x;
tile.height = size.y;
// draw something and pass the tile to the done() callback
done(error, tile);
},
});
Creation
Factory | Description |
---|---|
DG.gridLayer(
|
Creates a new instance of GridLayer with the supplied options. |
Options
Option | Type | Default | Description |
---|---|---|---|
tileSize |
Number|Point |
256 |
Width and height of tiles in the grid. Use a number if width and height are equal,
or DG.point(width, height) otherwise. |
opacity |
Number |
1.0 |
Opacity of the tiles. Can be used in the createTile() function. |
updateWhenIdle |
Boolean |
depends |
If false , new tiles are loaded during panning, otherwise only after it (for better
performance). true by default on mobile browsers, otherwise false . |
updateInterval |
Number |
200 |
Tiles will not update more than once every updateInterval milliseconds. |
attribution |
String |
null |
String to be shown in the attribution control, describes the layer data, e.g. "© 2GIS". |
zIndex |
Number |
1 |
The explicit zIndex of the tile layer. |
bounds |
LatLngBounds |
undefined |
If set, tiles will only be loaded inside inside the set
LatLngBounds . |
minZoom |
Number |
0 |
The minimum zoom level that tiles will be loaded at. By default the entire map. |
maxZoom |
Number |
undefined |
The maximum zoom level that tiles will be loaded at. |
noWrap |
Boolean |
false |
Whether the layer is wrapped around the antimeridian. If true , the
GridLayer will only be displayed once at low zoom levels. |
pane |
String |
'tilePane' |
Map pane where the grid layer will be added. |
Events
Event | Data | Description |
---|---|---|
loading |
Event |
Fired when the grid layer starts loading tiles |
tileunload |
TileEvent |
Fired when a tile is removed (e.g. when a tile goes off the screen). |
tileloadstart |
TileEvent |
Fired when a tile is requested and starts loading. |
tileerror |
TileEvent |
Fired when there is an error loading a tile. |
tileload |
TileEvent |
Fired when a tile loads. |
load |
TileEvent |
Fired when the grid layer loaded all visible tiles. |
Events inherited from Layer
Methods
Method | Returns | Description |
---|---|---|
bringToFront() |
this |
Brings the tile layer to the top of all tile layers. |
bringToBack() |
this |
Brings the tile layer to the bottom of all tile layers. |
getAttribution() |
String |
Used by the attribution control , returns the
attribution option. |
getContainer() |
String |
Returns the HTML element that contains the tiles for this layer. |
setOpacity(
|
this |
Changes the opacity of the grid layer. |
setZIndex(
|
this |
Changes the zIndex of the grid layer. |
isLoading() |
Boolean |
Returns true if any tile in the grid layer has not finished loading. |
redraw() |
this |
Causes the layer to clear all the tiles and request them again. |
getTileSize() |
Point |
Normalizes the tileSize option into a point.
Used by the createTile() method. |
Extension methods
Layers extending DG.GridLayer
shall reimplement the following method.
Method | Returns | Description |
---|---|---|
createTile(
|
HTMLElement |
Called only internally, must be overriden by classes extending
GridLayer . Returns the HTMLElement
corresponding to the given coords . If the done callback
is specified, it must be called when the tile has finished loading and drawing.
|
Methods inherited from Layer
Methods inherited from Evented