Display a rectangular shape on an AmChart map using geojson data

Output Example https://i.sstatic.net/BGQ3V.png

The output I'm seeing is just a simple rectangle, unlike the maps I create using tools like geojson.io or mapshapper. Strangely, there are no errors showing up in my browser console.

My Geojson Data

I have already included an "id" field within the features object. Here's a snippet of my geoJson data:

{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 Implementation

This is the Vue.js code I'm using to load the amcharts map:

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()
    }
  }
}

Answer №1

Mapshaper was causing your map coordinates to be reorganized in a counterclockwise direction, while Amharts expected them to be arranged clockwise.
For a solution and Python code to reorganize the coordinates accordingly, check out:

This method worked in my situation.

Answer №2

If you ever come across this issue, I stumbled upon a useful tool that successfully converted my ESRI shapefile to GeoJson for my project. Additionally, I utilized mapshaper to streamline the output with excellent results.

Update: Another alternative I discovered is a free tool that not only reverses geojson coordinates but also checks for possible errors, like missing "id" attributes.

Correction: The website I mentioned earlier is called

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Submitting data from a dropdown menu using Ajax in Struts 2: A step-by-step guide

I have a select tag with the s:select element inside a form. My goal is to send a post request to the specified action using Struts 2 json plugin. I do not have much knowledge in javascript or jquery. <s:form action="selectFileType" method="post" ...

Ways to invoke a next.js api that implements next-auth programmatically

In my next.js app, I have integrated next-auth which is set up to allow authentication using Facebook and Google as providers. Additionally, there are some endpoints located in the pages/api folder of the app. These endpoints are accessed from standard ne ...

The V-img component in Vue (specifically in Vuetify) does not appear as an image in the browser's context menu

When using the Vuetify framework, I created a v-img element. However, when I open the context menu in my browser, the usual image options (Save as, Open image, Copy image) are missing. I have tested this on both Firefox and Chrome. How can I resolve this i ...

Revamp nested .map calls to utilize async/await pattern

Currently, I am working with a JSON file structured similarly to the example below: [ { "Item": "Item1", "ItemChild": [ { "Category": "Category1", ...

The specified class is not found in the type 'ILineOptions' for fabricjs

Attempting to incorporate the solution provided in this answer for typescript, , regarding creating a Line. The code snippet from the answer includes the following options: var line = new fabric.Line(points, { strokeWidth: 2, fill: '#999999', ...

Is async/await necessary even if the outcome is not important to me?

Imagine I have an API call that performs X and I convert it into asynchronous code using async/await: export default async (req: NextApiRequest, res: NextApiResponse) => { let success = await sendEmail({ //... }); return res.status(200) ...

Disabling contentType and processData parameters in a POST request, causes the request to be processed without any

Attempting to send a file to my server through AJAX has been successful. However, the issue arises when I include contentType: false and processData: false. var formData = new FormData(); formData.append('image', input.files[0]); $.ajax({ u ...

Utilizing PHP to send arrays through AJAX and JSON

-I am facing a challenge with an array in my PHP file that contains nested arrays. I am trying to pass an integer variable (and may have to handle something different later on). -My objective is to make the PHP file return an array based on the incoming v ...

Issue: Using v-model with an InputEvent object in the Framework7 Vue framework.Error: The

Utilizing FrameWork7 Vue (), I am encountering the following issue: Why am I unable to modify the value of "Dispositivo"? Does the usage of "v-model" function properly in FrameWork7 Vue? index.html: <!DOCTYPE html> <html> <head> < ...

Developing a Highchart Graph using JavaScript

I am trying to develop a high chart graph. Check out my code on FIDDLE LINK. I have two values, a and b, for the x-axis and y-axis. The issue arises when the difference between a and b is minimal, such as when both are equal (-9). In such cases, the grap ...

Mastering the art of Promises and handling errors

I've been tasked with developing a WebApp using Angular, but I'm facing a challenge as the project involves Typescript and asynchronous programming, which are new to me. The prototype already exists, and it includes a handshake process that consi ...

Watching a specific property amongst various objects using VueJS deep watcher

Issue at Hand In my scenario, I have an array named "products" that consists of multiple objects. Each object within the product array includes a property called "price". My goal is to monitor any changes in this particular property for each product. This ...

How to add an element to an array with a function in ExtJS

I am looking to add an element to the drawnShapes array within the draw() function and the getDrawnShapesCount() function should return the total number of shapes drawn The drawnShapes variable represents an array of shapes Ext.define('Shape', ...

Utilizing the V-for loop technique without triggering immediate rendering

Whenever the loadComparison method is triggered, it retrieves the necessary data for each item in compare. However, after the Axios request is completed, the v-for loop refreshes with the new data, causing a continuous loop until all new data has been rece ...

Illuminate objects using three.js

My expertise in shaders and three.js is limited, however I am currently experimenting with creating a dynamic glowing effect similar to lights being flicked on and off. Currently, I am adjusting the color saturation and lightness which somewhat achieves ...

The function is not functioning properly due to an issue with the HTTP request

I am working with an AngularJS Framework controller. var app = angular.module('myApp', []); app.controller('myCtrl', function($scope, $http) { var locations =[]; var map; var markers = []; $scope.mappa = function(){ map = new g ...

Retrieve isolated scope of directive from transcluded content

I am not certain if it is possible, but I am essentially looking for a reverse version of the '&' isolate scope in AngularJS. You can check out this Plunkr to see an example. In essence, I have created a custom directive that provides some r ...

Retrieve the identification number from the code snippet containing the "append(<tr><td="ID">..." template

I have a table that I'm populating with data from a firebase database using the append() function. $("#table_body").append("<tr><td>" + name + "</td>" + "<td>" + brand + "</td>" + ...

Button Hover Effect: Transition with Style

I am trying to implement a one-second transition from the default color scheme to the hover color for a Button element in Material UI. I am using the transitions.create(props, options) method as described in this article: https://medium.com/@octaviocoria/c ...

Updating state of an array nested inside an object using React and ES6

I'm fairly new to Javascript and I feel like my lack of fundamental knowledge might be hindering me from solving this issue. Despite trying different approaches and reading tutorials, I can't seem to get it right. My goal is to manipulate the st ...