Home Reference Source

src/Gisplay/Gisplay.js

import { Choropleth } from './Maps/Choropleth';
import { DotMap } from './Maps/DotMap';
import { ChangeMap } from './Maps/ChangeMap';
import { ProportionalSymbolsMap } from './Maps/ProportionalSymbolsMap';
import { ChorochromaticMap } from './Maps/ChorochromaticMap';

/**
 * Gisplay API entry point with one method for each map available.
 */
export class Gisplay {

    /**
     * Creates an instance of the Gisplay API.
     * 
     * @memberOf Gisplay
     */
    constructor() {
        console.log("Gisplay Class constructor");
        /**
         * TimeStamp at the beginning.
         * @type {number} 
         */
        this.startTimeStamp = 0;

        /**
         * Whether or not it  should profile the API.
         * @type {string} - Whether or not it  should profile the API.
         */
        window.profiling = true;
        /**
         * @type {Array} - Array of maps. @WHY?
         */
        window.maps = new Array();
        /**
         * @type {number} - The number of maps. @WHY?
         */
        window.mapcount = 0;

        //WebGL API
        /**
        * @type {number} - The number of vertices produced. @WHY?
        */
        window._vertexcount = 0;
        /**
        * @type {number} - The number of ???. @WHY?
        */
        window._tricount = 0;
    }

    /**
     * Creates a map of type Choropleth.
     * @param {Object} bgmap - Background map object be used(atm only MapBox being used).- Background map object be used(atm only MapBox being used).
     * @param {JSON} geometry - The object that contains the data.
     * @param {Object} options - Object that contains user personalization options.
     * 
     * @memberOf Gisplay
     */
    makeChoropleth(bgmap, geometry, options) {
        console.log(bgmap);
        if (window.profiling == true)
            this.startTimeStamp = Date.now();
        const gismap = new Choropleth(bgmap, geometry, options);
        this.makeMap(gismap, options);
    }

    /**
     * Creates a Dot Map.
     * @param {Object} bgmap - Background map object be used(atm only MapBox being used).
     * @param {JSON} geometry - The object that contains the data.
     * @param {Object} options - Object that contains user personalization options.
     * 
     * @memberOf Gisplay
     */
    makeDotMap(bgmap, geometry, options) {
        if (window.profiling == true)
            this.startTimeStamp = Date.now();
        const gismap = new DotMap(bgmap, geometry, options);
        this.makeMap(gismap, options);
    }

    /**
     * Creates a Change Map.
     * @param {Object} bgmap - Background map object be used(atm only MapBox being used).
     * @param {JSON} geometry - The object that contains the data.
     * @param {Object} options - Object that contains user personalization options.
     * 
     * @memberOf Gisplay
     */
    makeChangeMap(bgmap, geometry, options) {
        if (window.profiling == true)
            this.startTimeStamp = Date.now();
        const gismap = new ChangeMap(bgmap, geometry, options);
        this.makeMap(gismap, options);
    }

    /**
     * Creates a Proportional Symbols Map.
     * @param {Object} bgmap - Background map object be used(atm only MapBox being used).
     * @param {JSON} geometry - The object that contains the data.
     * @param {Object} options - Object that contains user personalization options.
     * 
     * @memberOf Gisplay
     */
    makeProportionalSymbolsMap(bgmap, geometry, options) {
        if (window.profiling == true)
            this.startTimeStamp = Date.now();
        const gismap = new ProportionalSymbolsMap(bgmap, geometry, options);
        this.makeMap(gismap, options); //@Rui add options (n tinha WUT)
    }

    /**
     * Creates a Chorocromatic Map.
     * @param {Object} bgmap - Background map object be used(atm only MapBox being used).
     * @param {JSON} geometry - The object that contains the data.
     * @param {Object} options - Object that contains user personalization options.
     * 
     * @memberOf Gisplay
     */
    makeChorochromaticMap(bgmap, geometry, options) {
        if (window.profiling == true)
            this.startTimeStamp = Date.now();
        const gismap = new ChorochromaticMap(bgmap, geometry, options);
        this.makeMap(gismap, options);//@Rui .defaultid);
    }

    /**
     * Function that executes all the process associated with the creation of thematic maps.
     * @todo Should clean up this removing profiling code?
     * @param {Map} gismap - The Gisplay Map to use (Choropleth, DotMap,etc).
     * @param {Object} options - Object that contains user personalization options.
     * 
     * @memberOf Gisplay
     */
    makeMap(gismap, options) {
        let defaultid = options.defaultid != null ? defaultid : 1; //@todo Change opts.defaultid to optscolorSchemeDefaultId
        setTimeout(console => {
            let start = 0;
            if (window.profiling == true)
                start = Date.now();
            if (gismap.colorscheme == undefined)
                gismap.colorscheme = gismap.defaults(defaultid).colorScheme;
            if (gismap.classbreaks == undefined) {
                if (gismap.numberofclasses == undefined) {
                    gismap.numberofclasses = gismap.defaults(defaultid).numberOfClasses;
                }
                gismap.preProcessData(gismap.geometry, gismap.numberofclasses, gismap.algorithm, gismap.colorscheme);
            }

            //gismap.processData(gismap.geometry);
            gismap.loadGeoJSON(gismap.geometry);
            let start2 = 0;
            if (window.profiling == true) {
                start2 = Date.now();
                window.console.log(`Tempo de processamento do dados (segundos): ${(start2 - start) / 1000}`);
            }
            gismap.draw();

            let end = 0;
            if (window.profiling == true) {
                end = Date.now();
                window.console.log(`Tempo de desenho do mapa (segundos): ${(end - start2) / 1000}`);
            }
            if (options.legend != false)
                gismap.buildLegend();
            if (options.loader != false) {
                gismap.loader();
            }
            if (window.profiling == true) {
                end = Date.now();
                window.console.log(`Tempo total (segundos): ${(end - this.startTimeStamp) / 1000}`);
            }
        }, 1);
    }
}