leaflet.markerRotation.js 代码(这段代码是从插件 leaflet.polylineDecorator.js 中复制的):

// leaflet 实现 marker 旋转
(function () {
// save these original methods before they are overwritten
var proto_initIcon = L.Marker.prototype._initIcon;
var proto_setPos = L.Marker.prototype._setPos; var oldIE = (L.DomUtil.TRANSFORM === 'msTransform'); L.Marker.addInitHook(function () {
var iconOptions = this.options.icon && this.options.icon.options;
var iconAnchor = iconOptions && this.options.icon.options.iconAnchor;
if (iconAnchor) {
iconAnchor = (iconAnchor[0] + 'px ' + iconAnchor[1] + 'px');
}
this.options.rotationOrigin = this.options.rotationOrigin || iconAnchor || 'center bottom';
this.options.rotationAngle = this.options.rotationAngle || 0; // Ensure marker keeps rotated during dragging
this.on('drag', function (e) { e.target._applyRotation(); });
}); L.Marker.include({
_initIcon: function () {
proto_initIcon.call(this);
}, _setPos: function (pos) {
proto_setPos.call(this, pos);
this._applyRotation();
}, _applyRotation: function () {
if (this.options.rotationAngle) {
this._icon.style[L.DomUtil.TRANSFORM + 'Origin'] = this.options.rotationOrigin; if (oldIE) {
// for IE 9, use the 2D rotation
this._icon.style[L.DomUtil.TRANSFORM] = 'rotate(' + this.options.rotationAngle + 'deg)';
} else {
// for modern browsers, prefer the 3D accelerated version
this._icon.style[L.DomUtil.TRANSFORM] += ' rotateZ(' + this.options.rotationAngle + 'deg)';
}
}
}, setRotationAngle: function (angle) {
this.options.rotationAngle = angle;
this.update();
return this;
}, setRotationOrigin: function (origin) {
this.options.rotationOrigin = origin;
this.update();
return this;
}
});
})();

引用 leaflet.markerRotation.js,然后就可以设置 marker 的旋转角度了:

marker.setRotationOrigin('center center');
marker.setRotationAngle(45);

参考github:

https://github.com/bbecquet/Leaflet.RotatedMarker

leaflet marker 旋转的更多相关文章

  1. Leaflet 带箭头轨迹以及沿轨迹带方向的动态marker

    前面写了篇文章,mapboxgl实现带箭头轨迹线,介绍了如何基于mapboxgl实现类似高德地图导航轨迹效果. 下图是我基于leaflet实现的效果. 接下来分享一下在我基于leaflet实现该效果时 ...

  2. 【Leafletjs】2.添加marker到地图

    本人建了一个Leaflet交流群:Leaflet&WebGIS  331437754 接着上篇我们在地图中添加一个marker,非常简单只需添加如下代码即可: var marker = L.m ...

  3. leaflet地图库

    an open-source JavaScript libraryfor mobile-friendly interactive maps Overview Tutorials Docs Downlo ...

  4. 【GIS】Vue、Leaflet、highlightmarker、bouncemarker

    感谢: https://github.com/brandonxiang/leaflet.marker.highlight https://github.com/maximeh/leaflet.boun ...

  5. leaflet 结合 Echarts4 实现统计图(附源码下载)

    前言 leaflet 入门开发系列环境知识点了解: leaflet api文档介绍,详细介绍 leaflet 每个类的函数以及属性等等 leaflet 在线例子 leaflet 插件,leaflet ...

  6. 入门Leaflet之小Demo

    入门Leaflet之小Demo 写在前面 ---- WebGIS开发基础之Leaflet GIS基本概念:GIS.Map.Layer.Feature.Geometry.Symbol.Data(Poin ...

  7. GMap.NET二次开发库

    GMap.NET的出现,解决了传统的依赖于地图引擎的代价高昂的解决方案,而且使用传统地图引擎,无法迁移,就连我们的地图放大缩小这样常规的方法,都是紧紧绑定在这些令人恶心的地图引擎开发包提供的SDK接口 ...

  8. SVG 2D入门8 - 文档结构

    前面介绍了很多的基本元素,包括结构相关的组合和重用元素,这里先对SVG的文档结构中剩下的相关元素简单总结一下,然后继续向前领略SVG的其他特性. SVG文档的元素基本可以分为以下几类: 动画元素:an ...

  9. 腾讯地图JS API实现带方向箭头的线路Polyline

    最近产品提出一个需求,在我们使用的腾讯地图上为线路polyline添加线路方向.例如下图所示: 查找腾讯地图JS API提供的API,没有找到对应的支持,询问负责腾讯地图的人也得到了同样的答案,即地图 ...

  10. Leaflet - 实现按照路径方向旋转的 Marker

    在每帧动画时设置 Marker 的 transform 属性就行,zjffun/Leaflet.MovingMarker at zjf/feature-rotate 我在这个 Fork 中实现了一下. ...

随机推荐

  1. 递归与分治思想:汉诺塔(递归 && 分治思想)

    1 //64个盘子 2 //划分成小问题:1.将上面的63个盘子从x借助z移动到y上 3 2.将第64个盘子从x移动到z上 4 3.将y上的63个盘子借助x移动到z上 5 详解:https://www ...

  2. Windows之——pid为4的system进程占用80端口的解决办法

    因为Apache无法启动的原因,用netstat命令查看了一下80端口是否被占用了,如下 C:\Users\Maple>netstat -ano | findstr 0.0.0.0:80 TCP ...

  3. 在路上---学习篇(一)Python 数据结构和算法 (4) --希尔排序、归并排序

    独白: 希尔排序是经过优化的插入排序算法,之前所学的排序在空间上都是使用列表本身.而归并排序是利用增加新的空间,来换取时间复杂度的减少.这俩者理念完全不一样,注定造成的所消耗的时间不同以及空间上的不同 ...

  4. 【Javaweb】关于html转成jsp时出现乱码的问题解决

    原因是没有在代码头部添加,下面这段代码,添加之后就解决了 <%@ page language="java" contentType="text/html; char ...

  5. [python]数据分析--数据清洗处理case1

    数据预处理案例1 主要涉及pandas读取csv文件,缺失值和重复值处理,分组计数,字段类型转换 ,结果写入到Excel. 根据要求对CSV数据集进行处理要求如下: 保留数据关键信息:time.lat ...

  6. 安装Tensorflow-gpu版本

    下载cuda 链接:https://developer.nvidia.com/cuda-10.0-download-archive?target_os=Windows&target_arch= ...

  7. Python 中如何编写类型提示

    哈喽大家好,我是咸鱼 我们知道 Python 是一门具有动态特性的语言,在编写 Python 代码的时候不需要显式地指定变量的类型 这样做虽然方便,但是降低了代码的可阅读性,在后期 review 代码 ...

  8. 解密视频魔法:将ExternalOES纹理转化为TEXTURE_2D纹理

    在使用OpenGL ES进行图形图像开发时,我们常使用GL_TEXTURE_2D纹理类型,它提供了对标准2D图像的处理能力.这种纹理类型适用于大多数场景,可以用于展示静态贴图.渲染2D图形和进行图像处 ...

  9. 学习JVM---入门

    1.JVM体系结构 JVM的位置 JVM体系结构 2.类加载器 双亲委派机制 package java.lang; /** * 测试自定义java.lang.String类能否运行成功 * 体会双亲委 ...

  10. IntelliJ IDEA官方宣布中文汉化包正式发布-intellijidea-guan-fang-xuan-bu-zhong-wen-han-hua-bao-zheng-shi-fa-bu

    title: IntelliJ IDEA官方宣布中文汉化包正式发布 date: 2021-07-27 16:42:21.823 updated: 2021-12-26 17:43:12.204 url ...