用于将多个层分组并将其作为一个层处理。如果将其添加到地图中,则组中添加或移除的任何图层也将在地图上添加/移除。扩展层。
Usage example
L.layerGroup([marker1, marker2])
.addLayer(polyline)
.addTo(map);
Creation
Factory | Description |
---|---|
L.layerGroup(<Layer[]> layers?, <Object> options?) | Create a layer group, optionally given an initial set of layers and an options object.创建一个图层组,可以选择给定一组初始图层和一个选项对象。 |
Options
▶ Options inherited from Interactive layer
从交互层继承的选项
Option | Type | Default | Description |
---|---|---|---|
interactive | Boolean | true | If false , the layer will not emit mouse events and will act as a part of the underlying map.如果为false,该层将不会发出鼠标事件,并将作为基础贴图的一部分。 |
bubblingMouseEvents | Boolean | true | When true , a mouse event on this layer will trigger the same event on the map (unless L.DomEvent.stopPropagation is used).如果为true,此层上的鼠标事件将触发地图上的相同事件(除非使用L.DomEvent.stopPropagation)。 |
▶ Options inherited from Layer
从层继承的选项
Option | Type | Default | Description |
---|---|---|---|
pane | String | 'overlayPane' | By default the layer will be added to the map’s overlay pane. Overriding this option will cause the layer to be placed on another pane by default. 默认情况下,图层将添加到地图的覆盖窗格中。默认情况下,覆盖此选项将导致图层放置在另一个窗格上。 |
attribution | String | null | String to be shown in the attribution control, e.g. “© OpenStreetMap contributors”. It describes the layer data and is often a legal obligation towards copyright holders and tile providers. 属性控件中显示的字符串,例如“©OpenStreetMap贡献者”。它描述了层数据,通常是版权持有人和瓦片提供商的法律义务。 |
Events
▶ Mouse events inherited from Interactive layer
从交互层继承的鼠标事件
Event | Data | Description |
---|---|---|
click | MouseEvent | Fired when the user clicks (or taps) the layer. 当用户单击(或轻击)层时激发。 |
dblclick | MouseEvent | Fired when the user double-clicks (or double-taps) the layer. 当用户双击(或双击)层时激发。 |
mousedown | MouseEvent | Fired when the user pushes the mouse button on the layer. 当用户在层上按下鼠标按钮时激发。 |
mouseup | MouseEvent | Fired when the user releases the mouse button pushed on the layer. 当用户释放层上的鼠标按钮时激发。 |
mouseover | MouseEvent | Fired when the mouse enters the layer. 当鼠标进入层时激发。 |
mouseout | MouseEvent | Fired when the mouse leaves the layer. 当鼠标离开层时激发。 |
contextmenu | MouseEvent | Fired when the user right-clicks on the layer, prevents default browser context menu from showing if there are listeners on this event. Also fired on mobile when the user holds a single touch for a second (also called long press). 当用户右键单击层时激发,防止默认浏览器上下文菜单显示此事件上是否有侦听器。当用户按住一秒钟(也称为长按)时,也会在手机上触发。 |
▶ Events inherited from Layer
从层继承的事件
Event | Data | Description |
---|---|---|
add | Event | Fired after the layer is added to a map 将层添加到地图后激发 |
remove | Event | Fired after the layer is removed from a map 从地图中删除图层后激发 |
▶ Popup events inherited from Layer
从层继承的弹出事件
Event | Data | Description |
---|---|---|
popupopen | PopupEvent | Fired when a popup bound to this layer is opened 当绑定到此层的弹出窗口打开时激发 |
popupclose | PopupEvent | Fired when a popup bound to this layer is closed 当绑定到此层的弹出窗口关闭时激发 |
▶ Tooltip events inherited from Layer
从层继承的工具提示事件
Event | Data | Description |
---|---|---|
tooltipopen | TooltipEvent | Fired when a tooltip bound to this layer is opened. 当绑定到此层的工具提示打开时激发。 |
tooltipclose | TooltipEvent | Fired when a tooltip bound to this layer is closed. 当绑定到此层的工具提示关闭时激发。 |
Methods
Method | Returns | Description |
---|---|---|
toGeoJSON(<Number|false> precision?) | Object | Coordinates values are rounded with formatNum function with given precision . Returns a GeoJSON representation of the layer group (as a GeoJSON FeatureCollection , GeometryCollection , or MultiPoint ).坐标值使用formatNum函数以给定精度进行四舍五入。返回图层组的GeoJSON表示(作为GeoJSON FeatureCollection、GeometryCollection或MultiPoint)。 |
addLayer(<Layer> layer) | this | Adds the given layer to the group. 将给定图层添加到组中。 |
removeLayer(<Layer> layer) | this | Removes the given layer from the group. 从组中删除给定层。 |
removeLayer(<Number> id) | this | Removes the layer with the given internal ID from the group. 从组中删除具有给定内部ID的层。 |
hasLayer(<Layer> layer) | Boolean | Returns true if the given layer is currently added to the group.如果给定层当前已添加到组中,则返回true。 |
hasLayer(<Number> id) | Boolean | Returns true if the given internal ID is currently added to the group.如果给定的内部ID当前已添加到组中,则返回true。 |
clearLayers() | this | Removes all the layers from the group. 从组中删除所有层。 |
invoke(<String> methodName, …) | 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 .在该组中包含的每个层上调用methodName,传递任何其他参数。如果包含的层没有实现methodName,则没有效果。 |
eachLayer(<Function> fn, <Object> context?) | this | Iterates over the layers of the group, optionally specifying context of the iterator function.group.eachLayer(function (layer) { layer.bindPopup('Hello'); }); 在组的各个层上迭代,可选地指定迭代器函数.group的上下文。eachLayer(函数(层){layer.bindPopup(’Hello’);}); |
getLayer(<Number> id) | Layer | Returns the layer with the given internal ID. 返回具有给定内部ID的层。 |
getLayers() | Layer[] | Returns an array of all the layers added to the group. 返回添加到组中的所有层的数组。 |
setZIndex(<Number> zIndex) | this | Calls setZIndex on every layer contained in this group, passing the z-index.在该组中包含的每个层上调用setZIndex,传递z索引。 |
getLayerId(<Layer> layer) | Number | Returns the internal ID for a layer 返回层的内部ID |
▶ Methods inherited from Layer
从层继承的方法
Method | Returns | Description |
---|---|---|
addTo(<Map|LayerGroup> map) | this | Adds the layer to the given map or layer group. 将图层添加到给定地图或图层组。 |
remove() | this | Removes the layer from the map it is currently active on. 从当前处于活动状态的地图中删除图层。 |
removeFrom(<Map> map) | this | Removes the layer from the given map 从给定地图中删除图层 |
removeFrom(<LayerGroup> group) | this | Removes the layer from the given LayerGroup 从给定的图层组中删除图层 |
getPane(<String> name?) | HTMLElement | Returns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.返回表示地图上命名窗格的HTMLElement。如果省略名称,则返回此层的窗格。 |
getAttribution() | String | Used by the attribution control , returns the attribution option.由归因控件使用,返回归因选项。 |
▶ Popup methods inherited from Layer
从Layer继承的弹出式方法
Method | Returns | Description |
---|---|---|
bindPopup(<String|HTMLElement| Function|Popup> content, <Popup options> options?) | this | Binds a popup to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement .将弹出窗口绑定到包含传递内容的层,并设置必要的事件侦听器。如果传递了Function,它将接收层作为第一个参数,并应返回String或HTMLElement |
unbindPopup() | this | Removes the popup previously bound with bindPopup .删除以前与bindPopup绑定的弹出窗口。 |
openPopup(<LatLng> latlng?) | this | Opens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.在指定的latlng处打开绑定的弹出窗口,如果未传递latlng,则在默认弹出窗口锚点处打开绑定弹出窗口。 |
closePopup() | this | Closes the popup bound to this layer if it is open. 关闭绑定到此层的弹出窗口(如果它是打开的)。 |
togglePopup() | this | Opens or closes the popup bound to this layer depending on its current state. 根据当前状态打开或关闭绑定到此层的弹出窗口。 |
isPopupOpen() | boolean | Returns true if the popup bound to this layer is currently open.如果绑定到此层的弹出窗口当前处于打开状态,则返回true。 |
setPopupContent(<String| HTMLElement|Popup> content) | this | Sets the content of the popup bound to this layer. 设置绑定到此层的弹出窗口的内容。 |
getPopup() | Popup | Returns the popup bound to this layer. 返回绑定到此层的弹出窗口。 |
▶ Tooltip methods inherited from Layer
从Layer继承的工具提示方法
Method | Returns | Description |
---|---|---|
bindTooltip(<String|HTMLElement |Function|Tooltip> content, <Tooltip options> options?) | this | Binds a tooltip to the layer with the passed content and sets up the necessary event listeners. If a Function is passed it will receive the layer as the first argument and should return a String or HTMLElement .将工具提示绑定到包含传递内容的层,并设置必要的事件侦听器。如果传递了Function,它将接收层作为第一个参数,并应返回String或HTMLElement。 |
unbindTooltip() | this | Removes the tooltip previously bound with bindTooltip .删除以前与bindTooltip绑定的工具提示。 |
openTooltip(<LatLng> latlng?) | this | Opens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.在指定的latlng处打开绑定工具提示,如果未传递latlng,则在默认工具提示锚点处打开绑定的工具提示。 |
closeTooltip() | this | Closes the tooltip bound to this layer if it is open. 如果此图层处于打开状态,则关闭绑定到此图层的工具提示。 |
toggleTooltip() | this | Opens or closes the tooltip bound to this layer depending on its current state. 根据图层的当前状态打开或关闭绑定到此图层的工具提示。 |
isTooltipOpen() | boolean | Returns true if the tooltip bound to this layer is currently open.如果绑定到此层的工具提示当前处于打开状态,则返回true。 |
setTooltipContent(<String| HTMLElement|Tooltip> content) | this | Sets the content of the tooltip bound to this layer. 设置绑定到此层的工具提示的内容。 |
getTooltip() | Tooltip | Returns the tooltip bound to this layer. 返回绑定到此层的工具提示。 |
▶ Methods inherited from Evented
从Evented继承的方法
Method | Returns | Description |
---|---|---|
on(<String> type, <Function> fn, <Object> context?) | this | Adds a listener function (fn ) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. 'click dblclick' ).将侦听器函数(fn)添加到对象的特定事件类型。您可以选择指定侦听器的上下文(this关键字将指向的对象)。您还可以传递几个空格分隔的类型(例如“click dblclick”)。 |
on(<Object> eventMap) | this | Adds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove} 添加一组类型/侦听器对,例如{click:onClick,mousemove:onMouseMove} |
off(<String> type, <Function> fn?, <Object> context?) | this | Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to on , you must pass the same context to off in order to remove the listener.删除以前添加的侦听器函数。如果没有指定函数,它将从对象中删除该特定事件的所有侦听器。请注意,如果将自定义上下文传递给on,则必须将相同的上下文传递给off才能删除侦听器。 |
off(<Object> eventMap) | this | Removes a set of type/listener pairs. 移除一组类型/侦听器对。 |
off() | this | Removes all listeners to all events on the object. This includes implicitly attached events. 删除对象上所有事件的所有侦听器。这包括隐式附加的事件。 |
fire(<String> type, <Object> data?, <Boolean> propagate?) | this | Fires an event of the specified type. You can optionally provide a data object — the first argument of the listener function will contain its properties. The event can optionally be propagated to event parents. 激发指定类型的事件。您可以选择提供一个数据对象-侦听器函数的第一个参数将包含其属性。可以选择将事件传播到事件父级。 |
listens(<String> type, <Boolean> propagate?) | Boolean | Returns true if a particular event type has any listeners attached to it. The verification can optionally be propagated, it will return true if parents have the listener attached to it.如果特定事件类型有任何侦听器附加到它,则返回true。验证可以选择性地传播,如果父母将监听器连接到它,它将返回true。 |
once(…) | this | Behaves as on(…) , except the listener will only get fired once and then removed.行为与on(…)相同,但侦听器只会被解雇一次,然后被移除。 |
addEventParent(<Evented> obj) | this | Adds an event parent – an Evented that will receive propagated events添加事件父级-将接收传播事件的Evented |
removeEventParent(<Evented> obj) | this | Removes an event parent, so it will stop receiving propagated events 移除事件父级,因此它将停止接收传播的事件 |
addEventListener(…) | this | Alias to on(…) |
removeEventListener(…) | this | Alias to off(…) |
clearAllEventListeners(…) | this | Alias to off() |
addOneTimeEventListener(…) | this | Alias to once(…) |
fireEvent(…) | this | Alias to fire(…) |
hasEventListeners(…) | Boolean | Alias to listens(…) |