Home Reference Source Test
public class | source

Map

This class contains the Map class which represents the current map. Each map has a group of functions available. There is only one map yet(maybe there will be two if we want to compare two).

See:

Constructor Summary

Public Constructor
public

constructor(bgmap: BGMapWrapper | Object, geometry: JSON, userOptions: Object)

Map constructor.

Member Summary

Public Members
public

Aesthetic objects that were saved.

public

This is the Gisplay API Background map wrapper.

public

JSON object with the geometry that was read from the file.

public

All the options available in the Gisplay API.

public

Polygons do/do not exist.

public

This map unique identifier.

public

kdtree: kdTree

KdTree object to hold that will be used to calculate the closest point to the coordinates where the user made a click.

public

This is the maixmum value found on the dataset.

public

This is the minimum value found on the dataset.

public

rtree: PolygonLookup

RBush(Rtree implementation) that is used to calculate the polygon closest to the coordinates where the user made a click.

public

Holds the points for each Aesthethic object.

public

treepoints: Array<{lon: number, lat: number, properties: JSON}>

This object holds for each point it's long, lat and associated properties. This points will be used by k-d Tree. And k-d Tree is used to find the closest point to where the user clicked.

Private Members
private

Method Summary

Public Methods
public abstract

buildLegend(): void

M17) Creates a Legend element suitable for polygons based on the Aesthethic objects.

public

buildTrees(geojson: JSON): void

M19) Receives the dataset as parameter.

public

calcClassBreaks(numberValues: number[], classBreakMethod: string, numberOfClasses: number): number[]

M12) Calculates the class breaks using the algorithm given(k-means, quantile or equidistant).

public

clear()

M22) Clear current buffers to preset values.

public

clickEvent(lng: number, lat: number)

To be called when the user clicks on the map.

public

createAndInsertFeature(featureId: number, geometry: JSON, properties: JSON)

M14) Creates a Feature and then calls a method to insert said Feature in one or more Aesthetic objects.

public

M4) Creates a canvas element and WebGL associated information.

public abstract

M10) Defaults for each map.

public abstract

draw()

M21) Draw map function.

public

drawBorders(aes: Aesthetic): void

M24) Receiving an Aesthetics object, draws the borders contained in it's Features, aplying the color specified in the Aeshteic object for the line color(Aeshteic.strokeColor).

public

drawPoints(aes: Aesthetic): void

M26) Receiving an Aesthetics object, draws the points contained in it's Features, aplying the values specified in that Aesthetic object visual variables (color and size).

public

M27) Receiving an Aesthetics object, draws the points contained in it's Features, aplying the color specified in the Aeshteic object for the line color(Aeshteic.strokeColor) and the size of the point is based on the attribute value and the specified limits.

public

drawTriangles(aes: Aesthetic): void

M23) Receiving an Aesthetics object, draws the triangles contained in it's Features, using the color that the Aesthethics object has.

public

fitFeature(properties: JSON): Array<number>

M18) Returns an array of Aesthetic ids that tells us the objects where the Feature belongs.

public abstract

getDefaultColors(numClasses: number, dataNature: string): Array<Array<RGB>>

Returns the colors for this map given the number of classes and the nature of the data (sequential, diverging or qualitative).

public

M3) Initializes the API by: creating canvas, the WebGL program and setting up all needed events.

public

insertFeature(id: number, properties: JSON, triangles: {itemSize: number, numItems: number}, borders: {itemSize: number, numItems: number}, points: {itemSize: number, numItems: number}): void

M17) Inserts the Feature into one or more Aesthetic objects.

public

insertGroupedFeature(id: number, triangles: {itemSize: number, numItems: number}, borders: {itemSize: number, numItems: number}, points: {itemSize: number, numItems: number})

M20) Similar to insertFeature, in this case inserts a group of Features like it was only one.

public

loadGeoJSON(geojson: JSON)

M13) Loads GeoJSON object that came from the file uploaded by the user.

public

loadOptions(userOptions: Object, bgmap: Object)

M1) Loads user and default options.

public

M9) Method that executes all the process associated with the creation of the thematic map.

public

preProcessData(geojson: JSON, numberOfClasses: number, classBreaksMethod: string, colorScheme: string[])

M11) Creates Aesthetic objects.

public abstract

This function should be implemented by any subclass that wants to use another way of processing data.

public

processPolygon(polygon: {geometry: JSON, properties: JSON}): {triangles: Array<number>, vertices: Array<number>}

M15) Deals with polygon triangulation.

public

searchKdTree(lon: number, lat: number): void

Search the rtree for the closest point from the lng, lat that was clicked.

public

searchRTree(lng: number, lat: number): void

Search the rtree for the closest polygon from the lng, lat that was clicked.

public

setMatrices(gl: *)

This method will set all matrices needed to compute each point/vertex position.

public

setupEvents(mappos: number): void

M8) Setup all events used by the API.

public

M2) Calls the Background Map Wrapper to create the loader to be used later when the user feeds data to the API.

Public Constructors

public constructor(bgmap: BGMapWrapper | Object, geometry: JSON, userOptions: Object) source

Map constructor. All Map subclasses should call this first with super(...).

Params:

NameTypeAttributeDescription
bgmap BGMapWrapper | Object

Background map.

geometry JSON

Geometry read from the file.

userOptions Object

The user defined options.

TODO:

  • With the type of the map we can do an if statement inside constructor to use or not some of the variables.

Public Members

public aesthetics: Array<Aesthetic> source

Aesthetic objects that were saved.

public bGMap: BGMapWrapper source

This is the Gisplay API Background map wrapper. It contains the background map provider object to access it's methods (zoom, coordinates,etc). This map(Gisplay Map) will be drawn over the background map(bGMap).

public geometry: JSON source

JSON object with the geometry that was read from the file.

public gisplayOptions: GisplayOptions source

All the options available in the Gisplay API.

public hasPolygons: boolean source

Polygons do/do not exist. This is used to know if it to create a rtree or not on buildTrees method.

public id: number source

This map unique identifier.

public kdtree: kdTree source

KdTree object to hold that will be used to calculate the closest point to the coordinates where the user made a click.

See:

public max: number source

This is the maixmum value found on the dataset. The final value for the break. E.g. [2, 37[ 37 is the max. Used for PSymbol Map and Change Map because on those maps it's important to take in consideration this values to define the Feature color.

See:

public min: number source

This is the minimum value found on the dataset. The initial value for the break. E.g. [2, 37[ 2 is the min. Used for PSymbol Map and Change Map because on those maps it's important to take in consideration this values to define the Feature color.

See:

public rtree: PolygonLookup source

RBush(Rtree implementation) that is used to calculate the polygon closest to the coordinates where the user made a click.

See:

public tempAestheticPoints: Array<Array<number>> source

Holds the points for each Aesthethic object.

public treepoints: Array<{lon: number, lat: number, properties: JSON}> source

This object holds for each point it's long, lat and associated properties. This points will be used by k-d Tree. And k-d Tree is used to find the closest point to where the user clicked.

Private Members

private _webgl: Object source

Properties:

NameTypeAttributeDescription
_webgl.gl WebGLRenderingContext

The WebGLRenderingContext to be used.

_webgl.program WebGLProgram

The WebGLProgram to be used.

_webgl.projection Float32Array

The projection to be used. Deprecated in favor of better projection to work with multiple map background providers.

See:

Public Methods

public abstract buildLegend(): void source

M17) Creates a Legend element suitable for polygons based on the Aesthethic objects. Should be overriden by subclasses.

Return:

void

public buildTrees(geojson: JSON): void source

M19) Receives the dataset as parameter. This dataset in each row contains geometry and associated properties, then it creates one tree either for points or polygons. This tree can be k-d Treee or RBush(RTree)

Params:

NameTypeAttributeDescription
geojson JSON

Return:

void

See:

public calcClassBreaks(numberValues: number[], classBreakMethod: string, numberOfClasses: number): number[] source

M12) Calculates the class breaks using the algorithm given(k-means, quantile or equidistant). There will be as many class breaks as number of classes(numberOfClasses) given as input.

Params:

NameTypeAttributeDescription
numberValues number[]

The data values that will be used to be compute the breaks.

classBreakMethod string

The algorithm to use to calculate the class breaks.

numberOfClasses number

Number of classes the result expects.

Return:

number[]

The class breaks resulting from the use of the given algorithm and the number of classes.

See:

public clear() source

M22) Clear current buffers to preset values.

See:

public clickEvent(lng: number, lat: number) source

To be called when the user clicks on the map.

Params:

NameTypeAttributeDescription
lng number

Longitude of the click event.

lat number

Latitude of the click event.

public createAndInsertFeature(featureId: number, geometry: JSON, properties: JSON) source

M14) Creates a Feature and then calls a method to insert said Feature in one or more Aesthetic objects.

Params:

NameTypeAttributeDescription
featureId number

Id of the Feature.

geometry JSON

GeoJSON Geometry Object.

properties JSON

GeoJSON properties Object.

See:

public createCanvas() source

M4) Creates a canvas element and WebGL associated information.

public abstract defaults() source

M10) Defaults for each map. Subclasses should override this method.

public abstract draw() source

M21) Draw map function. Must be overriden by subclasses.

public drawBorders(aes: Aesthetic): void source

M24) Receiving an Aesthetics object, draws the borders contained in it's Features, aplying the color specified in the Aeshteic object for the line color(Aeshteic.strokeColor).

Params:

NameTypeAttributeDescription
aes Aesthetic

The Aesthetic object.

Return:

void

public drawPoints(aes: Aesthetic): void source

M26) Receiving an Aesthetics object, draws the points contained in it's Features, aplying the values specified in that Aesthetic object visual variables (color and size).

Params:

NameTypeAttributeDescription
aes Aesthetic

The Aesthetic object.

Return:

void

public drawProportionalPoints(aes: Aesthetic): void source

M27) Receiving an Aesthetics object, draws the points contained in it's Features, aplying the color specified in the Aeshteic object for the line color(Aeshteic.strokeColor) and the size of the point is based on the attribute value and the specified limits.

Params:

NameTypeAttributeDescription
aes Aesthetic

The Aesthetic object.

Return:

void

public drawTriangles(aes: Aesthetic): void source

M23) Receiving an Aesthetics object, draws the triangles contained in it's Features, using the color that the Aesthethics object has.

Params:

NameTypeAttributeDescription
aes Aesthetic

The Aesthetic object.

Return:

void

See:

public fitFeature(properties: JSON): Array<number> source

M18) Returns an array of Aesthetic ids that tells us the objects where the Feature belongs.

Params:

NameTypeAttributeDescription
properties JSON

The Feature properties

Return:

Array<number>

The Aesthetic ids where the Feature belongs.

public abstract getDefaultColors(numClasses: number, dataNature: string): Array<Array<RGB>> source

Returns the colors for this map given the number of classes and the nature of the data (sequential, diverging or qualitative).

Params:

NameTypeAttributeDescription
numClasses number

Number of classes.

dataNature string

Nature of the data.

Return:

Array<Array<RGB>>

Default colors for the map given the number of classes and nature of data.

public initializeCanvasAndEvents(): void source

M3) Initializes the API by: creating canvas, the WebGL program and setting up all needed events.

Return:

void

public insertFeature(id: number, properties: JSON, triangles: {itemSize: number, numItems: number}, borders: {itemSize: number, numItems: number}, points: {itemSize: number, numItems: number}): void source

M17) Inserts the Feature into one or more Aesthetic objects. If the Feature does not fit in any Aesthetic then does nothing.

Params:

NameTypeAttributeDescription
id number

The Feature id.

properties JSON

The Feature properties.

triangles {itemSize: number, numItems: number}

Triangles, each in one WebGLBuffer.

borders {itemSize: number, numItems: number}

Borders, each in one WebGLBuffer.

points {itemSize: number, numItems: number}

Points, each in one WebGLBuffer.

Return:

void

public insertGroupedFeature(id: number, triangles: {itemSize: number, numItems: number}, borders: {itemSize: number, numItems: number}, points: {itemSize: number, numItems: number}) source

M20) Similar to insertFeature, in this case inserts a group of Features like it was only one. It creates one WebGLBuffer with all the points instead of one WebGLBuffer per point. This method should only be used when we already grouped the Features by Aesthetic class (fitFeature() method). This method exists to provide one alternative less expensive in terms of memory for low end devices. Used only on Dot Map because on those we can easily end up with millions of different Features.

Params:

NameTypeAttributeDescription
id number

Aesthethics id.

triangles {itemSize: number, numItems: number}

Not used ?

borders {itemSize: number, numItems: number}

Not used ?

points {itemSize: number, numItems: number}

All the points for the Aesthethic object in one WebGLBuffer.

public loadGeoJSON(geojson: JSON) source

M13) Loads GeoJSON object that came from the file uploaded by the user. Extracts the Features present in the geometry object and inserts them in Aesthetic object(s) This method will create and insert features to Aesthetic objects and build trees of relationships between points or polygons.

Params:

NameTypeAttributeDescription
geojson JSON

GeoJSON read from the file.

See:

public loadOptions(userOptions: Object, bgmap: Object) source

M1) Loads user and default options. For each case if it isn't provided by the user, then it uses the default option. 1st method to be called.

Params:

NameTypeAttributeDescription
userOptions Object

Options given by the user.

bgmap Object

The background map provider.

public makeMap() source

M9) Method that executes all the process associated with the creation of the thematic map.

public preProcessData(geojson: JSON, numberOfClasses: number, classBreaksMethod: string, colorScheme: string[]) source

M11) Creates Aesthetic objects. If there's the need to calculate the class intervals, the method calcClassBreaks is called

Params:

NameTypeAttributeDescription
geojson JSON

GeoJSON object.

numberOfClasses number

Number of classes that the Legend will contain.

classBreaksMethod string

Algorithm to be used to calculate class breaks. Only used it class breaks are not given by the user.

colorScheme string[]

Color scheme to be used by this map.

public abstract processData(data: Object | JSON) source

This function should be implemented by any subclass that wants to use another way of processing data. By default it loads GeoJSON but if the user wants to load another type of data it should do so by implementing this method. A function similar to loadGeoJSON should also be implemented

Params:

NameTypeAttributeDescription
data Object | JSON

Dataset to be used. TODO: Add static to this method.

public processPolygon(polygon: {geometry: JSON, properties: JSON}): {triangles: Array<number>, vertices: Array<number>} source

M15) Deals with polygon triangulation.

Params:

NameTypeAttributeDescription
polygon {geometry: JSON, properties: JSON}

The geometry and properties of the polygon.

Return:

{triangles: Array<number>, vertices: Array<number>}

The triangles and vertices calculated by earcut triangulation. The vertices are the outside of the polygon, the triangles are the inside.

See:

public searchKdTree(lon: number, lat: number): void source

Search the rtree for the closest point from the lng, lat that was clicked.

Params:

NameTypeAttributeDescription
lon number

The longitude of the click.

lat number

The latitude of the click.

Return:

void

public searchRTree(lng: number, lat: number): void source

Search the rtree for the closest polygon from the lng, lat that was clicked.

Params:

NameTypeAttributeDescription
lng number

The longitude of the click.

lat number

The latitude of the click.

Return:

void

public setMatrices(gl: *) source

This method will set all matrices needed to compute each point/vertex position. This will use the Before sending the matrix to webGL we change the last column transformation in X and Y to the last row X and Y because WebGL is column major. See MMatrix[6] =...

Params:

NameTypeAttributeDescription
gl *

public setupEvents(mappos: number): void source

M8) Setup all events used by the API. Right now the API uses: drag, zoom and click events. This events will be fired by the background map provider and we can use them to draw(zoom and pan) or alert information(click). Pan/Zoom = move, click = click rtree will be used to find the closest polygon to the where the clicked event happened. kdtree will be used to find the closest point to where the click event happened.

Params:

NameTypeAttributeDescription
mappos number

This map id.

Return:

void

See:

TODO:

  • This method is doing uneccessary job if the user set interative to false and mapOnClickFunction is undefined.

public showLoader() source

M2) Calls the Background Map Wrapper to create the loader to be used later when the user feeds data to the API.