Home Reference Source

src/Gisplay/Maps/Choropleth.js

import { Map } from './Map';
import { Legend } from '../Legend';

/**
 * Choropleth implementation 06/03
 */
export class Choropleth extends Map {

    constructor(bgmap, geometry, options) {
        super(bgmap, geometry, options);
        this.aesthetics = new Array();
        this.geometry = geometry;
        this.loadOptions(options, bgmap);
        this.id = mapcount++;
        this.type = 'CP';
        maps.push(this);
        this.initialize();
        /*return this;*/
    }

    //@override
    draw() {
        //console.log("Choropleth drawaaa() called");
        this.clear();
        for (let i = 0; i < this.aesthetics.length; i++) {
            if (this.aesthetics[i].enabled == true) {
                this.drawTriangles(this.aesthetics[i]);
            }
            this.drawBorders(this.aesthetics[i]);
        }
    }

    buildLegend() {
        //console.log("Choropleth buildLegend() called");
        this.legend = new Legend(this.id, this.legendTitle);
        for (const a in this.aesthetics) {
            this.legend.insertPolygonRow(this.aesthetics[a], this);
        }
        this.legend.insertLegend(this.map);
    }

    defaults(defaultid) {
        //console.log("Choropleth defaults() called");
        const options = {};
        switch (defaultid) {
            case 1:
                options.colorScheme = ['white', 'yellow', 'orange', 'red'];
                options.numberOfClasses = 4;
                break;
            default:
                break;
        }
        return options;
    }
}