leaflet - 彩色相交传单圈
问题描述
我有一个关于传单/叶子的问题。我在地图上有多个圆圈。所有这些圆圈确实有一些相互重叠。我想做的是用不同的颜色画一条线/多边形,所有圆圈都在哪里相遇(相交)。
这是我想要实现的一个例子。蓝线是交叉点,需要不同的颜色。这可能在叶子或纯传单中吗?如果是这样,我该怎么做?
解决方案
您可以为此使用turfjs库和turf.intersect方法
/* eslint-disable no-undef */
/**
* intersection with turfjs
*/
// config map
let config = {
minZoom: 7,
maxZomm: 18,
};
// magnification with which the map will start
const zoom = 18;
// co-ordinates
const lat = 52.22977;
const lng = 21.01178;
// calling map
const map = L.map('map', config).setView([lat, lng], zoom);
// Used to load and display tile layers on the map
// Most tile servers require attribution, which you can set under `Layer`
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
}).addTo(map);
// three coordinate
const centers = [{
lat: 52.22990558765487,
lng: 21.01168513298035
},
{
lat: 52.22962958994604,
lng: 21.011593937873844
},
{
lat: 52.2297445891999,
lng: 21.012012362480167
}
]
// turf.circle option
const options = {
steps: 64,
units: 'meters',
options: {}
}
// circle radius
const radius = 30;
// array polygons
let polygons = [];
// set marker, add
centers.map(({
lat,
lng
}) => {
const polygon = turf.circle([lng, lat], radius, options);
// add cirkle polygon to map
L.geoJSON(polygon, {
color: "red",
weight: 2
}).addTo(map);
// add object to array
polygons.push(polygon);
})
// get intersection
const intersection = turf.intersect(...polygons);
// style intersection
const intersectionColor = {
color: "yellow",
weight: 2,
opacity: 1,
fillColor: "yellow",
fillOpacity: 0.7
};
// adding an intersection to the map
// and styling to this element
L.geoJSON(intersection, {
style: intersectionColor
}).addTo(map);
*,
:after,
:before {
box-sizing: border-box;
padding: 0;
margin: 0;
}
html {
height: 100%;
}
body,
html,
#map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@turf/turf@5/turf.min.js"></script>
<div id="map"></div>
推荐阅读
- c - Passing char by reference
- node.js - Jenkins、Docker、Kubernetes、AWS EKS:RUN npm install 要么挂起要么产生 EAI_AGAIN
- java - Android-WebRTC:设置本地描述后调用 MediaStream.removeVideoTrack
- python - 使用熊猫中的方差范围对列进行分组
- excel - 如何在二维表中使用索引功能
- android - 只获取一次随机数据的数据库查询
- hibernate - 如何解决错误消息:必须与引用的主键具有相同的列数
- xamarin - 如何在 Xamarin 表单中向用户发送用户消息?
- python-3.x - 嗨朋友我刚刚安装了opencv并检查了基本代码,但它导致了错误。代码是:
- r - 如何读取多个变量的最大值并使用 R 中的空间接近值形成平均值?