Leaflet Map DivIcon—表示使用简单元素而不是图像的标记的轻型图标继承自 Icon 但忽略 iconUrl 和阴影选项

Leaflet Map DivIcon—表示使用简单
元素而不是图像的标记的轻型图标继承自 Icon 但忽略 iconUrl 和阴影选项

表示使用简单<div>元素而不是图像的标记的轻型图标。继承自 Icon 但忽略 iconUrl 和阴影选项。

Represents a lightweight icon for markers that uses a simple <div> element instead of an image. Inherits from Icon but ignores the iconUrl and shadow options.

Usage example

var myIcon = L.divIcon({className: 'my-div-icon'});
// you can set .my-div-icon styles in CSS

L.marker([50.505, 30.57], {icon: myIcon}).addTo(map);

By default, it has a ‘leaflet-div-icon’ CSS class and is styled as a little white square with a shadow.

默认情况下,它有一个“leaflet-div-icon”CSS类,并且样式为带有阴影的白色小方块。

Creation

FactoryDescription
L.divIcon(<DivIcon options
options)
Creates a DivIcon instance with the given options.
使用给定选项创建 DivIcon 实例。

Options

OptionTypeDefaultDescription
htmlString|HTMLElement''Custom HTML code to put inside the div element, empty by default. Alternatively, an instance of HTMLElement.
要放入 div 元素中的自定义 HTML 代码,默认情况下为空。或者,HTMLElement的一个实例。
bgPosPoint[0, 0]Optional relative position of the background, in pixels
背景的可选相对位置(以像素为单位)

▶ Options inherited from Icon

从图标继承的选项

OptionTypeDefaultDescription
iconUrlStringnull(required) The URL to the icon image (absolute or relative to your script path).
(必填)图标图像的 URL(绝对或相对于脚本路径)。
iconRetinaUrlStringnullThe URL to a retina sized version of the icon image (absolute or relative to your script path). Used for Retina screen devices.
图标图像的视网膜大小版本的 URL(绝对或相对于脚本路径)。用于视网膜屏幕设备。
iconSizePointnullSize of the icon image in pixels.
图标图像的大小(以像素为单位)。
iconAnchorPointnullThe coordinates of the “tip” of the icon (relative to its top left corner). The icon will be aligned so that this point is at the marker’s geographical location. Centered by default if size is specified, also can be set in CSS with negative margins.
图标“尖端”的坐标(相对于其左上角)。图标将对齐,使该点位于标记的地理位置。如果指定了大小,则默认居中,也可以在CSS中设置负边距。
popupAnchorPoint[0, 0]The coordinates of the point from which popups will “open”, relative to the icon anchor.
弹出窗口将“打开”的点相对于图标锚点的坐标。
tooltipAnchorPoint[0, 0]The coordinates of the point from which tooltips will “open”, relative to the icon anchor.
工具提示将从中“打开”的点相对于图标锚点的坐标。
shadowUrlStringnullThe URL to the icon shadow image. If not specified, no shadow image will be created.
图标阴影图像的URL。如果未指定,则不会创建阴影图像。
shadowRetinaUrlStringnull
shadowSizePointnullSize of the shadow image in pixels.
阴影图像的大小(以像素为单位)。
shadowAnchorPointnullThe coordinates of the “tip” of the shadow (relative to its top left corner) (the same as iconAnchor if not specified).
阴影“尖端”的坐标(相对于其左上角)(如果未指定,则与iconAnchor相同)。
classNameString''A custom class name to assign to both icon and shadow images. Empty by default.
要分配给图标和阴影图像的自定义类名。默认情况下为空。
crossOriginBoolean|StringfalseWhether the crossOrigin attribute will be added to the tiles. If a String is provided, all tiles will have their crossOrigin attribute set to the String provided. This is needed if you want to access tile pixel data. Refer to CORS Settings for valid String values.
是否将crossOrigin属性添加到平铺中。如果提供了字符串,则所有平铺都将其crossOrigin属性设置为所提供的字符串。如果要访问平铺像素数据,则需要此选项。有关有效的字符串值,请参阅CORS设置。

Methods

▶ Methods inherited from Icon

从图标继承的方法

MethodReturnsDescription
createIcon(<HTMLElement> oldIcon?)HTMLElementCalled internally when the icon has to be shown, returns a <img> HTML element styled according to the options.
当必须显示图标时在内部调用,返回根据选项设置样式的<img>HTML元素。
createShadow(<HTMLElement> oldIcon?)HTMLElementAs createIcon, but for the shadow beneath it.
作为createIcon,但用于其下的阴影。
0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论x