0

I want to create a very simple drilldown map with Highcharts / Highmaps, with my geojsons (not those from Highcharts).

They look like this (as exported by a software) :

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "Id": "Region1",
        "Name": "My First Region" },
        "geometry": {
          "type": "MultiPolygon",
          "coordinates": [ [ [ [ 830.49832547647298, 9313.4877617806696 ], ...

Here is my code so far (based on a mashup of various tutorials and trial-and-error...) :

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { forkJoin } from 'rxjs';
import { Highcharts, MapChart } from 'angular-highcharts';

@Component({
  selector: 'app-demo-map-drilldown',
  template: '<div [chart]="chart" class="container" id="container"></div>',
  styleUrls: ['./demo-map-drilldown.component.css']
})
export class DemoMapDrilldownComponent implements OnInit {

  constructor(private httpClient: HttpClient) { }

  ngOnInit() {
    let geoJsonList = [];
    ["Country", "Region1", "Region2", "Region3"].forEach((name) => {
      geoJsonList.push(this.httpClient.get("assets/" + name + ".geojson"));
    });
    forkJoin(geoJsonList).subscribe(geoJsons => {
      geoJsons[0]["features"].map((element, i) => {
        element.drilldown = element.properties['Id']; // Id looks like "RegionX" in my files
        element.value = i;
      });

      this.chart = new MapChart({
        chart: {
          map: geoJsons[0]
        },

        title: {
          text: 'GeoJSON in Highmaps'
        },

        mapNavigation: {
          enabled: true,
          buttonOptions: {
            verticalAlign: 'bottom'
          }
        },

        colorAxis: {
          tickPixelInterval: 100
        },

        series: [{
          data: [
            ["Region1", "Region1", 44],
            ["Region2", "Region2", 49],
            ["Region3", "Region3", 53]
          ],
          keys: ['Name', 'drilldown', 'value'],
          joinBy: 'Name',
          name: 'Random data',
          states: {
            hover: {
              color: '#a4edba'
            }
          },
          dataLabels: {
            enabled: true,
            format: '{point.properties.Name}'
          }
        }],

        drilldown: {
          series: [{
            data: [
              ["CityA", 1],
              ["CityB", 5]
            ],
            id: 'Region1'
          }, {
            data: [
              ["CityC", 3],
              ["CityD", 4]
            ],
            id: 'Region2'
          }, {
            data: [
              ["CityE", 0],
              ["CityF", 2]
            ],
            id: 'Region3'
          }]
        }
      });
    });
  }
}

The problem is, I don't know how to load a different map during the drilldown. As of now, if I click on a region, the drilldown animation plays but loads the same map (well, with different data values).

Can someone help me ? Thanks !

PS : I don't know how to provide a working sample of this kind of projet, sorry...

Daneel
  • 1,173
  • 4
  • 15
  • 36
  • 1
    *PS : I don't know how to provide a working sample of this kind of projet, sorry...* Try [this](https://codesandbox.io/s/) – Core972 Aug 03 '18 at 20:37
  • 1
    Here is a useful official demo, which shows how to implement drilldown with multiple maps. https://www.highcharts.com/maps/demo/all-maps Have you seen that ? – daniel_s Aug 06 '18 at 09:23
  • Yes I saw it, and the simpler https://www.highcharts.com/maps/demo/map-drilldown too, but I think my first problem is transposing it from JavaScript to Angular. I opened another question about this, if you'd like to take a look : https://stackoverflow.com/questions/51704198/highcharts-highmaps-with-angular-cannot-run-demo – Daneel Aug 06 '18 at 09:26

0 Answers0