Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GeoJson amchart maps what is wrong with geoJson?

I am relatively new to ammCharts and it is my first attempt to create a geoJSON file also.

The following is my geoJson file:

GeoJSON file

This is what I am trying to achieve: example

When I load my geoJson this is what happens : my map

So only one polygon is actively working. For some reason I am having problems and could not make jsfiddle or codepen of the code. I believe something is wrong in my geoJSON as I have loaded other random Geojson Files they work fine with the codepen created by amcharts just mine dosent work.

I am using geojson.io to create the geoJson.

like image 654
hamadkh Avatar asked Jan 20 '17 06:01

hamadkh


People also ask

What is a GeoJSON map?

GeoJSON is an open standard geospatial data interchange format that represents simple geographic features and their nonspatial attributes. Based on JavaScript Object Notation (JSON), GeoJSON is a format for encoding a variety of geographic data structures.

Can GeoJSON be 3D?

Make Your GeoJSON Interactive With FME your 2D data can become 3D! By converting GeoJSON data to Cesium 3D Tiles you'll be able to drag, scale, and rotate your data in Cesium's dynamic display. You can even see the stars come out of the sky using the timeline widget.

What opens GeoJSON files?

You can open GeoJSON files from your computer, Google Drive. GeoJSON Map Viewer is a tool that views the GeoJSON file in your browser. This app allows you to validate your GeoJSON and display it on a Google map.

How do I visualize a GeoJSON file?

If you have a geojson file on your local hard drive or network and want to view/use it in QGIS, you can just drag and drop it from the Browser Panel into the Layers Panel or just double click on the file will add it to the Layers Panel.


1 Answers

The issue with your geoJSON is that it lacks ids. AmCharts' maps require unique IDs for each region. Since there's no "id" property set in any of your regions, they'll all default to null, allowing only one of the regions to be highlighted. I modified your JSON and added ids with the same value as the district in each region like so:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "division": "Muzaffarabad",
        "district": "Muzaffarabad",
        "id": "Muzaffarabad",
// ... others omitted

I also modified the example to add a "title" attribute to the converted object so that you'll get the name of the area when you hover over it by default:

  for(var i = 0; i < svg.length; i++) {
    var path = svg[i];
    var attrs = path.match(/\w+=".*?"/g);
    var area = {};
    for(var x = 0; x < attrs.length; x++) {
      var parts = attrs[x].replace(/"/g, '').split("=");
      var key = fieldMap[parts[0]] || parts[0];
      area[key] = parts[1];
    }
    //added for hover-over balloons
    area["title"] = area["id"];
    mapVar.svg.g.path.push(area);
  }

Here's a demo with the modified file and example code. You can find the fully modified geoJSON file here.

like image 78
xorspark Avatar answered Sep 26 '22 12:09

xorspark