来自 geojson 的 Amchart 地图,只显示一个矩形

问题描述 投票:0回答:2

我的输出

这是我的输出,只是一个矩形,不像地图,当我在 geojson.iomapshapper 尝试时,我的浏览器控制台没有错误..

我的 Geojson

我已经在功能对象中使用了“id”,这是我的示例 geoJson:

{type: "FeatureCollection", features: Array(14)}
features: Array(14)

0:
geometry: {type: "Polygon", coordinates: Array(1)}
properties:{
id: 332112
kabupaten: "DEMAK"
kecamatan: "Bonang"
provinsi: "JAWA TENGAH"
__proto__: Object
type: "Feature"
__proto__: Object
}

1: {type: "Feature", geometry: {…}, properties: {…}}
2: {type: "Feature", geometry: {…}, properties: {…}}

AmChart 代码

我的 vue js 代码加载 amcharts 地图

import * as am4core from "@amcharts/amcharts4/core"
import * as am4maps from "@amcharts/amcharts4/maps"
import robots from "./assets/demak"

export default {
  mounted() {
    let map = am4core.create("chartdiv", am4maps.MapChart)

    map.geodata = robots

    console.log(robots);


    map.projection = new am4maps.projections.Miller()
    var polygonSeries = map.series.push(new am4maps.MapPolygonSeries())
    polygonSeries.useGeodata = true

    var polygonTemplate = polygonSeries.mapPolygons.template;
polygonTemplate.fill = am4core.color("#74B266");
polygonTemplate.tooltipText = "{KABUPATEN}";
var hs = polygonTemplate.states.create("hover");
hs.properties.fill = am4core.color("#367B25");

// Add zoom control
map.zoomControl = new am4maps.ZoomControl();

  },
  beforeDestroy() {
    if (this.map) {
      this.map.dispose()
    }
  }
}
javascript vue.js dictionary geojson amcharts
2个回答
0
投票

问题是 mapshaper 正在逆时针方向重新排列您的地图坐标,而 Amharts 假设它是顺时针排列的。
您可以阅读解释并尝试使用 python 代码重新排列它:
https://www.wemcouncil.org/wp/how-to-make-mapshaper-output-compatible-with-amcharts4-using-python
它适用于我的情况。


0
投票

对于遇到此问题的任何其他人,我使用了这个工具https://mygeodata.cloud/converter/shp-to-geojson,它是第一次从我的 ESRI shapefile 正确转换为 AmCharts 5。

© www.soinside.com 2019 - 2024. All rights reserved.