leaflet +高德地图纠偏

一、html源码

<!DOCTYPE html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title><meta charset="utf-8" /><linkrel="stylesheet"href="https://unpkg.com/leaflet@1.9.3/dist/leaflet.css"integrity="sha256-kLaT2GOSpHechhsozzB+flnD+zUyjE2LlfWPgU04xyI="crossorigin=""/><scriptsrc="https://unpkg.com/leaflet@1.9.3/dist/leaflet.js"integrity="sha256-WBkoXOwTeyKclOHuWtc+i2uENFpDZ9YPdf5Hf+D7ewM="crossorigin=""></script><script type="text/javascript" src="./js/leaflet.ChineseTmsProviders.js"></script><!--纠偏--><script type="text/javascript" src="./js/leaflet.mapCorrection.min.js"></script><style>html,body {height: 100%;width: 100%;padding: 0;margin: 0;}#map {height: 100%;width: 100%;}</style></head><body><div id="map"></div><script>var map = L.map('map', {center: [39.90554, 116.39133],zoom: 15,zoomControl: false});var gaodeMap = L.tileLayer.chinaProvider('GaoDe.Normal.Map').addTo(map);//设置参照物L.marker([39.90554, 116.39133]).addTo(map).bindPopup('<p>我是WGS84坐标下,天安门广场国旗所在位置</p>');</script></body>
</html>

二、leaflet.ChineseTmsProviders.js

// this L.CRS.Baidu from https://github.com/muyao1987/leaflet-tileLayer-baidugaode/blob/master/src/tileLayer.baidu.jsif (L.Proj) {L.CRS.Baidu = new L.Proj.CRS('EPSG:900913', '+proj=merc +a=6378206 +b=6356584.314245179 +lat_ts=0.0 +lon_0=0.0 +x_0=0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext  +no_defs', {resolutions: function () {level = 19var res = [];res[0] = Math.pow(2, 18);for (var i = 1; i < level; i++) {res[i] = Math.pow(2, (18 - i))}return res;}(),origin: [0, 0],bounds: L.bounds([20037508.342789244, 0], [0, 20037508.342789244])});
}L.TileLayer.ChinaProvider = L.TileLayer.extend({initialize: function(type, options) { // (type, Object)var providers = L.TileLayer.ChinaProvider.providers;options = options || {}var parts = type.split('.');var providerName = parts[0];var mapName = parts[1];var mapType = parts[2];var url = providers[providerName][mapName][mapType];options.subdomains = providers[providerName].Subdomains;options.key = options.key || providers[providerName].key;if ('tms' in providers[providerName]) {options.tms = providers[providerName]['tms']}L.TileLayer.prototype.initialize.call(this, url, options);}
});L.TileLayer.ChinaProvider.providers = {TianDiTu: {Normal: {Map: "//t{s}.tianditu.com/DataServer?T=vec_w&X={x}&Y={y}&L={z}&tk={key}",Annotion: "//t{s}.tianditu.com/DataServer?T=cva_w&X={x}&Y={y}&L={z}&tk={key}"},Satellite: {Map: "//t{s}.tianditu.com/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk={key}",Annotion: "//t{s}.tianditu.com/DataServer?T=cia_w&X={x}&Y={y}&L={z}&tk={key}"},Terrain: {Map: "//t{s}.tianditu.com/DataServer?T=ter_w&X={x}&Y={y}&L={z}&tk={key}",Annotion: "//t{s}.tianditu.com/DataServer?T=cta_w&X={x}&Y={y}&L={z}&tk={key}"},Subdomains: ['0', '1', '2', '3', '4', '5', '6', '7'],key: "174705aebfe31b79b3587279e211cb9a"},GaoDe: {Normal: {Map: 'http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}'},Satellite: {Map: '//webst0{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}',Annotion: '//webst0{s}.is.autonavi.com/appmaptile?style=8&x={x}&y={y}&z={z}'},Subdomains: ["1", "2", "3", "4"]},Google: {Normal: {Map: "//www.google.cn/maps/vt?lyrs=m@189&gl=cn&x={x}&y={y}&z={z}"},Satellite: {Map: "//www.google.cn/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}",Annotion: "//www.google.cn/maps/vt?lyrs=y@189&gl=cn&x={x}&y={y}&z={z}"},Subdomains: []},Geoq: {Normal: {Map: "//map.geoq.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer/tile/{z}/{y}/{x}",PurplishBlue: "//map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetPurplishBlue/MapServer/tile/{z}/{y}/{x}",Gray: "//map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetGray/MapServer/tile/{z}/{y}/{x}",Warm: "//map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetWarm/MapServer/tile/{z}/{y}/{x}",},Theme: {Hydro: "//thematic.geoq.cn/arcgis/rest/services/ThematicMaps/WorldHydroMap/MapServer/tile/{z}/{y}/{x}"},Subdomains: []},OSM: {Normal: {Map: "//{s}.tile.osm.org/{z}/{x}/{y}.png",},Subdomains: ['a', 'b', 'c']},Baidu: {Normal: {Map: '//online{s}.map.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles=pl&scaler=1&p=1'},Satellite: {Map: '//shangetu{s}.map.bdimg.com/it/u=x={x};y={y};z={z};v=009;type=sate&fm=46',Annotion: '//online{s}.map.bdimg.com/tile/?qt=tile&x={x}&y={y}&z={z}&styles=sl&v=020'},Subdomains: '0123456789',tms: true}};L.tileLayer.chinaProvider = function(type, options) {return new L.TileLayer.ChinaProvider(type, options);
};

三、leaflet.mapCorrection.min.js

L.CoordConver = function() {function a(b, c) {var d = -100 + 2 * b + 3 * c + .2 * c * c + .1 * b * c + .2 * Math.sqrt(Math.abs(b)), d = d + 2 * (20 * Math.sin(6 * b * e) + 20 * Math.sin(2 * b * e)) / 3, d = d + 2 * (20 * Math.sin(c * e) + 40 * Math.sin(c / 3 * e)) / 3;return d += 2 * (160 * Math.sin(c / 12 * e) + 320 * Math.sin(c * e / 30)) / 3}function f(b, c) {var d = 300 + b + 2 * c + .1 * b * b + .1 * b * c + .1 * Math.sqrt(Math.abs(b)), d = d + 2 * (20 * Math.sin(6 * b * e) + 20 * Math.sin(2 * b * e)) / 3, d = d + 2 * (20 * Math.sin(b * e) + 40 * Math.sin(b / 3 * e)) / 3;return d += 2 * (150 * Math.sin(b / 12 * e) + 300 * Math.sin(b / 30 * e)) / 3}this.getCorrdType = function(b) {var c = "wgs84";switch (b.split(".")[0]) {case "Geoq":case "GaoDe":case "Google":c = "gcj02";break;case "Baidu":c = "bd09";break;case "OSM":case "TianDiTu":c = "wgs84"}return c};this.bd09_To_gps84 = function(b, c) {var d = this.bd09_To_gcj02(b, c);return this.gcj02_To_gps84(d.lng, d.lat)};this.gps84_To_bd09 = function(b, c) {var d = this.gps84_To_gcj02(b, c);return this.gcj02_To_bd09(d.lng, d.lat)};this.gps84_To_gcj02 = function(b, c) {var d = a(b - 105, c - 35), k = f(b - 105, c - 35), l = c / 180 * e, g = Math.sin(l), g = 1 - n * g * g, m = Math.sqrt(g), d = 180 * d / (h * (1 - n) / (g * m) * e), k = 180 * k / (h / m * Math.cos(l) * e);return {lng: b + k,lat: c + d}};this.gcj02_To_gps84 = function(b, c) {var d = a(b - 105, c - 35), k = f(b - 105, c - 35), l = c / 180 * e, g = Math.sin(l), g = 1 - n * g * g, m = Math.sqrt(g), d = 180 * d / (h * (1 - n) / (g * m) * e), k = 180 * k / (h / m * Math.cos(l) * e);return {lng: 2 * b - (b + k),lat: 2 * c - (c + d)}};this.gcj02_To_bd09 = function(b, c) {var d = Math.sqrt(b * b + c * c) + 2E-5 * Math.sin(c * p), a = Math.atan2(c, b) + 3E-6 * Math.cos(b * p);return {lng: d * Math.cos(a) + .0065,lat: d * Math.sin(a) + .006}};this.bd09_To_gcj02 = function(b, c) {var d = b - .0065, a = c - .006, e = Math.sqrt(d * d + a * a) - 2E-5 * Math.sin(a * p), d = Math.atan2(a, d) - 3E-6 * Math.cos(d * p);return {lng: e * Math.cos(d),lat: e * Math.sin(d)}};var e = 3.141592653589793, h = 6378245, n = .006693421622965943, p = 3E3 * e / 180
}
;
L.coordConver = function() {return new L.CoordConver
}
;
L.TileLayer.ChinaProvider.include({addTo: function(a) {a.options.corrdType || (a.options.corrdType = this.options.corrdType);a.addLayer(this);return this}
});
L.tileLayer.chinaProvider = function(a, f) {f = f || {};f.corrdType = L.coordConver().getCorrdType(a);return new L.TileLayer.ChinaProvider(a,f)
}
;
L.GridLayer.include({_setZoomTransform: function(a, f, e) {var h = f;void 0 != h && this.options && ("gcj02" == this.options.corrdType ? h = L.coordConver().gps84_To_gcj02(f.lng, f.lat) : "bd09" == this.options.corrdType && (h = L.coordConver().gps84_To_bd09(f.lng, f.lat)));f = this._map.getZoomScale(e, a.zoom);e = a.origin.multiplyBy(f).subtract(this._map._getNewPixelOrigin(h, e)).round();L.Browser.any3d ? L.DomUtil.setTransform(a.el, e, f) : L.DomUtil.setPosition(a.el, e)},_getTiledPixelBounds: function(a) {var f = a;void 0 != f && this.options && ("gcj02" == this.options.corrdType ? f = L.coordConver().gps84_To_gcj02(a.lng, a.lat) : "bd09" == this.options.corrdType && (f = L.coordConver().gps84_To_bd09(a.lng, a.lat)));a = this._map;var e = a._animatingZoom ? Math.max(a._animateToZoom, a.getZoom()) : a.getZoom(), e = a.getZoomScale(e, this._tileZoom), f = a.project(f, this._tileZoom).floor();a = a.getSize().divideBy(2 * e);return new L.Bounds(f.subtract(a),f.add(a))}
});

 参考链接:leaflet中如何优雅的解决百度、高德地图的偏移问题 | 地图

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/20235.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

利用远程调试获取Chromium内核浏览器Cookie

前言 本文将介绍不依靠DPAPI的方式获取Chromium内核浏览器Cookie 远程调试 首先我们以edge为例。edge浏览器是基于Chromium的&#xff0c;而Chromium是可以开启远程调试的&#xff0c;开启远程调试的官方文档如下&#xff1a; https://blog.chromium.org/2011/05/remote-deb…

中介者(Mediator)模式

目录 动机使用场景参与者协作效果实现相关模式应用和思考 中介者(Mediator)是对象行为模式&#xff0c;用一个中介对象来封装一系列对象的交互。中介者使各对象不需要显式的相互应用&#xff0c;从而使其耦合松散&#xff0c;而且可以独立的改变他们之间的交互 动机 面向对象设…

【Arduino小车实践】PID应用之四驱小车

一、 PID公式 二、 PID应用的必要性 1. 四驱小车运动 左边两个驱动轮和右边两个驱动轮的速度相同直线右边轮子的速度大于左边轮子的速度左偏右边轮子的速度小于左边轮子的速度 右偏 2. 产生多种运动的原因 小车的4个电机&#xff0c;减速箱以及车轮在物理层面上存在误差&am…

STM32 Proteus仿真LCD12864火灾检测烟雾火焰温度报警器MQ2 -0064

STM32 Proteus仿真LCD12864火灾检测烟雾火焰温度报警器MQ2 -0064 Proteus仿真小实验&#xff1a; STM32 Proteus仿真LCD12864火灾检测烟雾火焰温度报警器MQ2 -0064 功能&#xff1a; 硬件组成&#xff1a;STM32F103R6单片机 LCD12864 液晶显示DS18B20 温度传感器多个按键电位…

【数据结构导论】第 5 章:图

目录 一、图的基本概念 &#xff08;1&#xff09;图的定义 &#xff08;2&#xff09;图的基本术语 &#xff08;3&#xff09;图的基本运算 二、图的存储结构 &#xff08;1&#xff09;邻接矩阵 ① 图的邻接矩阵 ② 带权图(网)的邻接矩阵 ③ 邻接矩阵的类型定…

二次-InsCode Stable Diffusion 美图活动一期

模型&#xff1a; AbyssOrangeMix2 - SFW_Soft NSFW_AbyssOrangeMix2_sfw.safetensors 参数配置&#xff1a; 正&#xff1a;Mountains and seas, people 负&#xff1a;NSFW, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochr…

模拟对讲机会被数字对讲机取代吗?

经常在网上看到有网友讨论&#xff0c;模拟对讲机是不是快被淘汰了&#xff0c;要被数字对讲机取代了。其实不管是模拟还是数字对讲机&#xff0c;都有其各自的优势&#xff0c;数字对讲要想全面取代模拟对讲&#xff0c;还是有些为时尚早。 传统的模拟对讲机主要是将语音、信…

贪心算法、贪心搜索/采样(greedy search/sampling)、集束搜索(beam search)、随机采样(random sample)

首先需要了解贪心算法&#xff1a; 贪心算法&#xff0c;又名贪婪法&#xff0c;是寻找最优解问题的常用方法&#xff0c;这种方法模式一般将求解过程分成若干个步骤&#xff0c;但每个步骤都应用贪心原则&#xff0c;选取当前状态下最好/最优的选择&#xff08;局部最有利的选…

conda修改环境保存地址

可以在命令行中通过conda config指令进行修改 如&#xff1a; 添加环境目录envs_dirs conda config --add envs_dirs F:\conda_env\envs 添加pkgs_dirs conda config --add pkgs_dirs F:\conda_env\pkgs 也可以直接进入Anaconda Nacigator进行修改

星云零售信贷基于 Apache Doris 的 OLAP 演进之路

本文导读&#xff1a; 腾梭科技是国内领先的零售金融数字化及安全服务提供商&#xff0c;是腾讯投资且在金融领域的战略合作伙伴&#xff0c;并与腾讯联合研发了“星云智慧信贷解决方案。在其信贷业务转型过程中&#xff0c;随着系统规模不断扩大&#xff0c;早期架构无法再满…

SpringBoot + Vue 实现酒店客房管理系统

目录 1 问题的提出 5 2系统开发的可行性研究 6 2.1 技术上可行性分析 6 系统现阶段的发展过程中&#xff0c;利用现有人力和物力是完全具备的能力开发出来 6 2.2 经济的可行性分析 6 2.3 操作可行性分析 6 3 需求分析 7 3.1 需求描述 7 3.2 功能需求分析 7 3.3 非功能需求分析…

迭代器模式:简化集合元素遍历的设计模式

迭代器模式是一种行为型设计模式&#xff0c;它提供了一种遍历集合元素的统一接口&#xff0c;使得我们可以在不暴露集合内部结构的情况下访问集合中的元素。迭代器模式可以简化集合的遍历操作&#xff0c;提高代码的可读性和可维护性。本文将详细介绍迭代器模式的原理、结构和…