Map
Direct Subclass:
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).
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}>{lon:> 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 |
defaults() 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 |
drawProportionalPoints(aes: Aesthetic): void 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 |
initializeCanvasAndEvents(): void 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 |
makeMap() 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 |
processData(data: Object | JSON) 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:
Name | Type | Attribute | Description |
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 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 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 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.
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.
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.
public rtree: PolygonLookup source
RBush(Rtree implementation) that is used to calculate the polygon closest to the coordinates where the user made a click.
public tempAestheticPoints: Array<Array<number>> source
Holds the points for each Aesthethic object.
public treepoints: Array<{lon: number, lat: number, properties: JSON}>{lon:> 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:
Name | Type | Attribute | Description |
_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. |
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:
Name | Type | Attribute | Description |
geojson | JSON |
Return:
void |
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.
Return:
number[] | The class breaks resulting from the use of the given algorithm and the number of classes. |
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.
public abstract defaults() source
M10) Defaults for each map. Subclasses should override this method.
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
aes | Aesthetic | The Aesthetic object. |
Return:
void |
public fitFeature(properties: JSON): Array<number> source
M18) Returns an array of Aesthetic ids that tells us the objects where the Feature belongs.
Params:
Name | Type | Attribute | Description |
properties | JSON | The Feature properties |
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).
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:
Name | Type | Attribute | Description |
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.
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:
Name | Type | Attribute | Description |
geojson | JSON | GeoJSON read from the file. |
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.
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:
Name | Type | Attribute | Description |
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
public processPolygon(polygon: {geometry: JSON, properties: JSON}): {triangles: Array<number>, vertices: Array<number>} source
M15) Deals with polygon triangulation.
public searchKdTree(lon: number, lat: number): void source
Search the rtree for the closest point from the lng, lat that was clicked.
Return:
void |
public searchRTree(lng: number, lat: number): void source
Search the rtree for the closest polygon from the lng, lat that was clicked.
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
mappos | number | This map id. |
Return:
void |
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.