You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

离线将LineString类型GeoJSON出行路径转换为SVG的解决方案咨询

问题背景

需在列表UI中展示用户的出行路径为SVG格式,要求方案支持离线运行。

输入说明

输入为包含用户出行坐标列表、几何类型为LineString的GeoJSON数据,示例如下:

const geoJsonData = {
      type: 'FeatureCollection',
      features: [
        {
          geometry: {
            type: 'LineString',
            coordinates: [
              [77.601923, 13.054111],
              [77.602046, 13.054097],
              [77.601984, 13.054261],
              [77.601954, 13.055172],
              [77.601861, 13.055171],
              [77.601613, 13.055162],
              [77.601534, 13.055159],
              [77.601223, 13.055148],
              [77.600907, 13.055136],
              [77.60085, 13.055134],
              [77.600585, 13.055125],
              [77.600492, 13.055122],
              [77.600256, 13.055113],
              [77.600144, 13.055116],
              [77.599887, 13.055124],
              [77.599678, 13.05515],
              [77.599419, 13.055186],
              [77.599237, 13.055262],
              [77.599059, 13.055332],
              [77.598979, 13.055365],
              [77.598696, 13.055528],
              [77.598316, 13.055735],
              [77.597942, 13.055909],
              [77.597914, 13.055993],
              [77.597911, 13.056119],
              [77.597979, 13.056299],
              [77.598195, 13.056721],
              [77.59833, 13.057012],
            ],
          },
          type: 'Feature',
          properties: {
            description: 'Southern Ave',
            lines: ['Green'],
          },
        },
      ],
    };
现存问题

现有方案生成的SVG路径无法绘制出预期的路线。

预期效果

输出效果与Aspose在线GeoJSON转SVG服务的输出一致,该服务返回的path示例如下:

// 输出结果:<path d="m771.5 575.78l23.5 2.68-11.85-31.33-5.73-174.05-17.76.19-47.39 1.72-15.09.57-59.42 2.1-60.37 2.3-10.89.38-50.63 1.72-17.76.57-45.09 1.72-21.4-.57-49.1-1.53-39.93-4.97-49.48-6.88-34.78-14.52-34-13.37-15.29-6.31-54.06-31.14-72.6-39.54-71.46-33.25-5.35-16.05-.57-24.07 12.99-34.39 41.27-80.62 25.79-55.6"></path>
已尝试方案
  • 使用geojson2svg库,配置代码如下:
var converter = geojson2svg({
 viewportSize: {width: 200, height: 300},
 output: 'svg',
});
const svgStr = converter.convert(geoJsonData);

输出结果的路径几乎缩为一个圆点,不符合要求。

  • 使用D3库,配置代码如下:
const width = 200,
     height = 200;
const gfg = d3
.geoMercator()
.scale(100)
.rotate([0, 0])
.center([0, 0])
.translate([width / 2, height / 2]);

const pathGenerator = d3.geoPath().projection(gfg);
console.log(pathGenerator(geoJsonData));

输出结果为极小的填充图案,不符合要求。

需求

寻求可离线运行、输出效果与Aspose在线转换结果接近的GeoJSON转SVG实现方案。


内容的提问来源于stack exchange,提问作者pratik_qube

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 17:27:03