【有偿回答】leaflet与leaflet-measure地图测量工具问题?
问题描述:地图和测量插件集成后,新建测量,此时点击地图画点,点会向右下方向偏移(点击位置1 实际打的点会偏移到位置 2)
请给出解决方案(有偿)
vue 组件代码 如下 可赋值下来到vue项目中调试
package.json中下载依赖
"leaflet": "^1.9.3",
"leaflet-measure-ex": "^3.0.7" 或者 "leaflet-measure": "^3.1.0",
组件代码
<template>
<div class="content_map">
<div id="map"></div>
</div>
</template>
<script>
import 'leaflet/dist/leaflet.css';
import './leaflet/L.Control.MousePosition';
import './leaflet/L.Control.MousePosition.css';
import { cloneDeep } from 'lodash';
import 'leaflet-measure-ex/dist/leaflet-measure';
import 'leaflet-measure-ex/dist/leaflet-measure.css';
// import './leaflet/leaflet-measure.css';
// import './leaflet/leaflet-measure.cn';
let map = null;
let basemap = null;
let scaleControl = null;
let zoomControl = null;
let mapBounds = null;
const basemapUrl = 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}';
const basemapProp = {
maxZoom: 21,
minZoom: 0,
label: 'ESRI Satellite',
};
export default {
name: 'ContentMap',
data() {
return {};
},
computed: {},
watch: {},
mounted() {
this.initDate();
},
beforeDestroy() {
map.remove();
},
methods: {
initDate() {
map = L.map('map', {
center: [39.077514, 117.713544], // 地图中心
zoom: 14, //缩放比列
scrollWheelZoom: true, // 允许鼠标滚轮缩放地图
positionControl: true, // 左下角显示当前位置
zoomControl: false,
minZoom: 0,
maxZoom: 24,
// measureControl: true,
// preferCanvas: true,
});
// 初始化地图图层 缩放比例等
const tileProps = cloneDeep(basemapProp);
tileProps.maxNativeZoom = tileProps.maxZoom;
tileProps.maxZoom = tileProps.maxZoom + 99;
basemap = L.tileLayer(basemapUrl, tileProps);
basemap.addTo(map);
// 初始化测量工具
// L.control
// .measure({
// labels: {},
// primaryLengthUnit: 'meters',
// secondaryLengthUnit: 'feet',
// primaryAreaUnit: 'sqmeters',
// secondaryAreaUnit: 'acres',
// position: 'topright',
// })
// .addTo(map);
L.control.measure().addTo(map);
// 左下角刻度尺
scaleControl = L.control.scale({ maxWidth: 250 }).addTo(map);
// 左下角加减号
zoomControl = L.control.zoom({ position: 'bottomleft' }).addTo(map);
map.fitWorld();
map.attributionControl.setPrefix('');
},
},
};
</script>
<style src="../../../../../static/leaflet/css/theme.scss"></style>
<style lang="scss">
.content_map {
position: relative;
width: 100%;
height: 100%;
#map {
position: absolute;
width: 100%;
height: 100%;
z-index: 1;
}
}
</style>
底部样式文件theme.scss
.leaflet-bar a,
.leaflet-control > a {
background-color: #999 !important;
border-color: #000 !important;
color: #f6e5bd !important;
&:hover {
background-color: #555 !important;
}
}
.leaflet-control-scale-line {
border: 2px solid #444 !important;
background: #999 !important;
text-shadow: none !important;
color: #f6e5bd !important;
}
回复
1个回答
test
2024-06-29
回复
适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容