gpt4 book ai didi

javascript - 用 Leaflet 创建一个圆(使用正半径)

转载 作者:行者123 更新时间:2023-11-30 05:32:44 28 4
gpt4 key购买 nike

在 Leaflet 中画圈似乎很简单 according to the documentation ,您只需提供坐标、半径和可选的选项对象:

L.circle( <LatLng> latlng, <Number> radius, <Path options> options? ) 

我尝试在我正在处理的 map 上执行此操作,但无论我指定的半径有多大,都只能生成一个点而不是一个圆。我让这让我发疯了一段时间,然后离开代码去从事其他项目。我最近又回来了,一时兴起,我尝试对半径使用负值:

"use strict";
var theMap = L.map("map", {
minZoom: 0,
maxZoom: 7,
crs: L.CRS.Simple
}).setView([0, 0], 0),
eventsLayer = new L.LayerGroup(),

unproject = function (coord) {
return theMap.unproject(coord, theMap.getMaxZoom());
},

coord = unproject([12057.79, 13661.21]),

southWest = unproject([0, 32768]),
northEast = unproject([32768, 0]),

radius = -8653.18, // Why isn't it working with a positive radius?!?!?
circ = L.circle(coord, radius, {color: '#f00', fillColor: '#00f'});

theMap.setMaxBounds(new L.LatLngBounds(southWest, northEast));

L.tileLayer("https://tiles.guildwars2.com/1/1/{z}/{x}/{y}.jpg", {
minZoom: 2,
maxZoom: 7,
continuousWorld: true
}).addTo(theMap);
eventsLayer.addTo(theMap);

theMap.setView(coord, 7, {animate: true});
circ.addTo(eventsLayer);

出于某种原因it creates a circle负半径。

这似乎是一个错误,因为文档使用正值作为半径。我的代码中是否有什么地方做错了导致这种错误行为,或者它可能是 Leaflet 中的错误?

最佳答案

遇到this answer之后我认为这是传单中的错误。我下载了当前版本的dev master和added into the fiddle .

radius = 1,

新版本确实接受正值并形成一个圆圈。然而,它以不同的方式存在错误。 0.7 指定圆的半径应以米为单位设置。在当前的开发版本中,即使值 1 也能覆盖数百米。

关于javascript - 用 Leaflet 创建一个圆(使用正半径),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25901249/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com