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. 提高cin cout的速度

     ios::sync_with_stdio(false) :用来关闭iostream与stdio的同步,从而提高 cin cout 的效率,但是就不能再用 scanf printf 了,因为不关闭之前 ...

  2. 【让AI女友跟我表白】大白话说Python+Flask入门(四)Flask Sijax的使用

    写在前面 先吐槽两句,搞个mysql安装配置弄了4个小时,怎么都是外网无法访问,我靠,我特么也是服了. 当然,后来我投降了,明天再说,学什么不是学,娘的,换个方向,状态依然在! Sijax是什么? 代 ...

  3. Markdown语法入门与进阶指南

    一.Markdown简介 Markdown是一种轻量级标记语言,创始人为约翰·格鲁伯(john Gruber).它允许人们使用易读易写的纯文本格式编写文档,然后转换成有效的XHTML(或者HTML)文 ...

  4. STM32外设:专用定时器 IWDG、WWDG、RTC

    主要外设: IWDG:Independent Watch DoG 独立看门狗 WWDG:Window Watch DoG 窗口看门狗 RTC: Real-Time Clock 实时时钟 IWDG 主要 ...

  5. hbase报错 ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet

    hbase报错:hbase shell能打开 网页也能打开 但是一执行命令就开始报错. 原因:hadoop的安全模式打开. 解决方法:关闭安全模式 ,再重新启动HBase就可以了. 具体的命令: 1. ...

  6. Hive架构组件

    架构图 Hive组件

  7. 解决Tensorflow2.0出现:AttributeError: module 'tensorflow' has no attribute 'get_default_graph'的问题

    问题描述 在使用tensorflow2.0时,遇到了这个问题: AttributeError: module 'tensorflow' has no attribute 'get_default_gr ...

  8. Java8新特性Stream流

    1.是什么? Stream(流)是一个来自数据源的元素队列并支持聚合操作 2.能干嘛? Stream流的元素是特定类型的对象,形成一个队列. Java中的Stream并不会存储元素,而是按需计算. 数 ...

  9. C++ Qt开发:StringListModel字符串列表映射组件

    Qt 是一个跨平台C++图形界面开发库,利用Qt可以快速开发跨平台窗体应用程序,在Qt中我们可以通过拖拽的方式将不同组件放到指定的位置,实现图形化开发极大的方便了开发效率,本章将重点介绍QString ...

  10. Docker容器运行、使用、管理

    docker container [COMMAND] 命令: **exec 在容器中执行命令** export 将容器的文件系统导出为tar归档文件(和docker save的区别在于,save会记录 ...