Leaflet Map Canvas—允许使用显示向量层继承渲染器

Leaflet Map Canvas—允许使用显示向量层继承渲染器

Due to technical limitations, Canvas is not available in all web browsers, notably IE8, and overlapping geometries might not display properly in some edge cases.

由于技术限制,Canvas并非在所有web浏览器中都可用,尤其是IE8,重叠的几何图形在某些边缘情况下可能无法正确显示。

Usage example

Use Canvas by default for all paths in the map:

默认情况下,对地图中的所有路径使用画布:

var map = L.map('map', {
    renderer: L.canvas()
});

Use a Canvas renderer with extra padding for specific vector geometries:

为特定矢量几何体使用带有额外填充的画布渲染器:

var map = L.map('map');
var myRenderer = L.canvas({ padding: 0.5 });
var line = L.polyline( coordinates, { renderer: myRenderer } );
var circle = L.circle( center, { renderer: myRenderer } );

Creation

FactoryDescription
L.canvas(<Renderer options>
 options?)
Creates a Canvas renderer with the given options.
使用给定选项创建画布渲染器。

Options

OptionTypeDefaultDescription
toleranceNumber0How much to extend the click tolerance around a path/object on the map.
围绕地图上的路径/对象扩展单击容差的程度。

▶ Options inherited from Renderer

从渲染器继承的选项

OptionTypeDefaultDescription
paddingNumber0.1How much to extend the clip area around the map view (relative to its size) e.g. 0.1 would be 10% of map view in each direction
地图视图周围的剪辑区域延伸多少(相对于其大小),例如0.1将是每个方向地图视图的10%

▶ Options inherited from Layer

从层继承的选项

OptionTypeDefaultDescription
paneString'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.
默认情况下,图层将添加到地图的覆盖窗格中。默认情况下,覆盖此选项将导致图层放置在另一个窗格上。
attributionStringnullString 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

▶ Events inherited from Renderer

从渲染器继承的事件

EventDataDescription
updateEventFired when the renderer updates its bounds, center and zoom, for example when its map has moved
当渲染器更新其边界、居中和缩放时激发,例如当其贴图移动时

▶ Events inherited from Layer

从层继承的事件

EventDataDescription
addEventFired after the layer is added to a map
将层添加到地图后激发
removeEventFired after the layer is removed from a map
从地图中删除图层后激发

▶ Popup events inherited from Layer

从层继承的弹出事件

EventDataDescription
popupopenPopupEventFired when a popup bound to this layer is opened
当绑定到此层的弹出窗口打开时激发
popupclosePopupEventFired when a popup bound to this layer is closed
当绑定到此层的弹出窗口关闭时激发

▶ Tooltip events inherited from Layer

从层继承的工具提示事件

EventDataDescription
tooltipopenTooltipEventFired when a tooltip bound to this layer is opened.
当绑定到此层的工具提示打开时激发。
tooltipcloseTooltipEventFired when a tooltip bound to this layer is closed.
当绑定到此层的工具提示关闭时激发。

Methods

▶ Methods inherited from Layer

从层继承的方法

MethodReturnsDescription
addTo(<Map|LayerGroup> map)thisAdds the layer to the given map or layer group.
将图层添加到给定地图或图层组。
remove()thisRemoves the layer from the map it is currently active on.
从当前处于活动状态的地图中删除图层。
removeFrom(<Mapmap)thisRemoves the layer from the given map
从给定地图中删除图层
removeFrom(<LayerGroupgroup)thisRemoves the layer from the given LayerGroup
从给定的图层组中删除图层
getPane(<String> name?)HTMLElementReturns the HTMLElement representing the named pane on the map. If name is omitted, returns the pane for this layer.
返回表示地图上命名窗格的HTMLElement。如果省略名称,则返回此层的窗格。
getAttribution()StringUsed by the attribution control, returns the attribution option.
由归因控件使用,返回归因选项。

▶ Popup methods inherited from Layer

MethodReturnsDescription
bindPopup(<String|HTMLElement
|Function|Popup> content
<Popup options>
 options?)
thisBinds 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.
unbindPopup()thisRemoves the popup previously bound with bindPopup.
openPopup(<LatLnglatlng?)thisOpens the bound popup at the specified latlng or at the default popup anchor if no latlng is passed.
closePopup()thisCloses the popup bound to this layer if it is open.
togglePopup()thisOpens or closes the popup bound to this layer depending on its current state.
isPopupOpen()booleanReturns true if the popup bound to this layer is currently open.
setPopupContent(<String|
HTMLElement|Popup> content)
thisSets the content of the popup bound to this layer.
getPopup()PopupReturns the popup bound to this layer.

▶ Tooltip methods inherited from Layer

从Layer继承的弹出式方法

MethodReturnsDescription
bindTooltip(<String|
HTMLElement|
Function|Tooltip> 
content, <Tooltip optionsoptions?)
thisBinds 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()thisRemoves the tooltip previously bound with bindTooltip.
删除以前与bindTooltip绑定的工具提示。
openTooltip(<LatLng
latlng?)
thisOpens the bound tooltip at the specified latlng or at the default tooltip anchor if no latlng is passed.
在指定的latlng处打开绑定工具提示,如果未传递latlng,则在默认工具提示锚点处打开绑定的工具提示。
closeTooltip()thisCloses the tooltip bound to this layer if it is open.
如果此图层处于打开状态,则关闭绑定到此图层的工具提示。
toggleTooltip()thisOpens or closes the tooltip bound to this layer depending on its current state.
根据图层的当前状态打开或关闭绑定到此图层的工具提示。
isTooltipOpen()booleanReturns true if the tooltip bound to this layer is currently open.
如果绑定到此层的工具提示当前处于打开状态,则返回true。
setTooltipContent(<String|
HTMLElement|Tooltip> content)
thisSets the content of the tooltip bound to this layer.
设置绑定到此层的工具提示的内容。
getTooltip()TooltipReturns the tooltip bound to this layer.
返回绑定到此层的工具提示。

▶ Methods inherited from Evented

从Evented继承的方法

MethodReturnsDescription
on(<String> type
<Function> fn, <Object> 
context?)
thisAdds 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)thisAdds a set of type/listener pairs, e.g. {click: onClick, mousemove: onMouseMove}
添加一组类型/侦听器对,例如{click:onClick,mousemove:onMouseMove}
off(<String> type, <Function> 
fn?, <Object> context?)
thisRemoves 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)thisRemoves a set of type/listener pairs.
移除一组类型/侦听器对。
off()thisRemoves all listeners to all events on the object. This includes implicitly attached events.
删除对象上所有事件的所有侦听器。这包括隐式附加的事件。
fire(<String> type, <Object> 
data?, <Boolean> propagate?)
thisFires 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?)
BooleanReturns 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()thisBehaves as on(…), except the listener will only get fired once and then removed.
行为与on(…)相同,但侦听器只会被解雇一次,然后被移除。
addEventParent(<Eventedobj)thisAdds an event parent – an Evented that will receive propagated events
添加事件父级-将接收传播事件的Evented
removeEventParent(<Eventedobj)thisRemoves an event parent, so it will stop receiving propagated events
移除事件父级,因此它将停止接收传播的事件
addEventListener()thisAlias to on(…)
removeEventListener()thisAlias to off(…)
clearAllEventListeners()thisAlias to off()
addOneTimeEventListener()thisAlias to once(…)
fireEvent()thisAlias to fire(…)
hasEventListeners()BooleanAlias to listens(…)
5 1 投票
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论x