Y-SLD/assets/plugins/leaflet/leaflet-canvasicon/leaflet-canvasicon.js

73 lines
1.8 KiB
JavaScript
Raw Normal View History

2024-03-01 11:23:55 +00:00
/*global L */
(function () {
'use strict';
/**
* Canvas Icon
* @type {L.CanvasIcon}
* @extends {L.Icon}
*/
L.CanvasIcon = L.Icon.extend({
options: {
/** @var {L.Point} */
iconSize: [24, 24],
/** @var {L.Point} */
iconAnchor: [12, 12],
/** @var {function} */
drawIcon: null,
/* @var {string} */
className: 'leaflet-canvas-icon'
},
/**
* @param {HTMLElement} oldIcon
* @returns {HTMLCanvasElement}
*/
createIcon: function (oldIcon) {
var size = L.point(this.options.iconSize);
var icon = (oldIcon && (oldIcon.tagName == 'CANVAS')) ? oldIcon : document.createElement('canvas');
icon.width = size.x;
icon.height = size.y;
this._setIconStyles(icon, 'icon');
return icon;
},
/**
* @param {HTMLElement} oldIcon
* @returns {null}
*/
createShadow: function (oldIcon) {
return null;
},
/**
* @param {HTMLElement} icon
* @param {string} type
* @private
*/
_setIconStyles: function (icon, type) {
if (typeof this.options.drawIcon == 'function') {
this.options.drawIcon.apply(this, arguments);
}
L.Icon.prototype._setIconStyles.apply(this, arguments);
}
});
/**
* Canvas Icon factory
* @param {Object} options
* @returns {L.CanvasIcon}
*/
L.canvasIcon = function (options) {
return new L.CanvasIcon(options);
};
/**
* AMD compatibility
*/
if ((typeof define == 'function') && define.amd) {
define(L.CanvasIcon);
}
}());