有没有办法在反应传单中添加“对齐道路”?

问题描述

我正在寻找使每个标记间的所有多段线“对齐道路”的方法,而不是在 a 点和 b 点之间绘制一条直线。因此,在任何两点之间,我希望这些点自动放置在最近的道路上(如果标记未放置在道路上),并希望沿两点之间最短的道路路线生成折线。我刚刚开始研究 google maps API,看起来他们有这个功能,但我不想改变我已经拥有的一切。这是我的代码

import React from "react";
import { useSelector,usedispatch } from "react-redux";
import { MapContainer,TileLayer,polyline } from "react-leaflet";
import "../styles/Map.css";
import AddMarkers from "./AddMarkers";

const Map = () => {
  const markers = useSelector((state) => state.markers);

  return (
    <div className="leaflet-container">
      <MapContainer
        center={[50.868031999999996,-9]}
        zoom={20}
        scrollWheelZoom={true}
      >
        <TileLayer
          attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
          url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
        />
        <AddMarkers />
        {markers.length > 1 && (
          <polyline
            positions={markers.map((marker) => {
              return [marker.lat,marker.lng];
            })}
          />
        )}
      </MapContainer>
    </div>
  );
};

export default Map;

解决方法

看来您可能会搜索:https://github.com/makinacorpus/Leaflet.Snap

这应该可以将可拖动标记捕捉到折线和其他图层。 此页面中的 Demo-Link 已损坏,但在 GitHub-Page 中似乎有详细说明,如何使用。我认为您需要使用 let Source = Excel.CurrentWorkbook(){[Name="Table10"]}[Content],//Group by Name and Other Data // extract a delimited list of the sub_text and sub_codes #"Grouped Rows" = Table.Group(Source,{"name","other_data"},{ {"sub_text",each Text.Combine([sub_text],";"),type text},{"sub_code",each Text.Combine([sub_code],type text} }),//split the delimited lists into separate columns. #"Split Column by Delimiter" = Table.SplitColumn(#"Grouped Rows","sub_text",Splitter.SplitTextByDelimiter(";",QuoteStyle.Csv)),#"Split Column by Delimiter1" = Table.SplitColumn(#"Split Column by Delimiter","sub_code",QuoteStyle.Csv)) in #"Split Column by Delimiter1" 部分进行实施。

祝您好运,让您的地图按预期工作。