Working with Data

[ezcol_2third]


Using business data in layers

In general, aside from private 3rd party layers like select CartoDB and ESRI layers, layers consume generic business data fields such as:
values, labels, locations, colors, categories,
as well as a variety of other common layer properties. The individual layer types then implement their own special behaviors, using that data. This way, much coding around data can be implemented in a generic fashion.

Set Data

Setting data at the map level and layer level produces the same result.

At the map-level

In general when setting data at the map level, each layer gets its own array of data which is why the lyr1.locations below is wrapped in brackets, becuase it’s a 2D Array property where each array corresponds to the layer at the same index/position in the map. In this case, setting data for layer 1/position 0.

 

var lyr1 = {
	name:"Choropleth Pins",
	locations:["37.7693911,-122.4290072","37.790998,-122.431254","37.7480245,-122.4208806"],
	labels: ["Dr. Goldstein", "Dr. Smith", "Dr. Jones"],
	values:[50, 11, 12]
}

cMap.layerNames([lyr1.name]).
	locations([lyr1.locations]).
	labels([lyr1.labels]).
	values([lyr1.values]);

At the layer-level

 

layer.locations(lyr1.locations).
	labels(lyr1.labels).
	values(lyr1.values);

Getting Data Basics

Getting data at the map level and layer level can produce different results. At the map level, the
map will simply return the data it has been fed, while at the layer level, the data is processed and subject to various optional filter
criteria.

At the map-level

 

console.log(cMap.locations());
console.log(cMap.labels());
console.log(cMap.values());
console.log(cMap.colors());
console.log(cMap.categories());

At the layer-level

 

console.log(layer.getLocations());
console.log(layer.getColors());
console.log(layer.getLabels());
console.log(layer.getValues());
console.log(layer.getVisibilityFlags());
console.log(layer.getCategories());

Filtering data

Based on your coding needs, data filters can be applied at the map-level as well as at the individual layer level.

Map Filtering

 

/*Returns the corresponding data for the specified number 
of the highest data values. This does not filter 
what's displayed.*/
cMap.getTopNLayerData(layerIx, howMany, onlyVisible);
/*Returns the corresponding data for the specified number 
of the lowest data values. This does not filter 
what's displayed.*/
cMap.getBottomNLayerData(layerIx, howMany, onlyVisible);

/*Visually filters the layer's display to include 
the corresponding objects for the specified number 
of the highest data values.*/
cMap.filterLayerByTopNLayerData(layerIx, howMany);
/*Visually filters the layer's display to include the 
corresponding objects for the specified number of the 
lowest data values.*/
cMap.filterLayerByBottomNLayerData(layerIx, howMany);

/*2D Array. Each child array corresponds to the layer 
at the same position/index. Arbitrary data that the map can 
filter and format for you, based on the current layer selections. 
Can be helpful when using the map as a filtering mechanism 
in your application.*/
cMap.layersSourceData([[1,2,3,"hello",45,254]]);
/*Each child string corresponds to 
the layer at the same index 
and instructs the map how to return the filtered 
data for that layer.*/
cMap.layersFilteredSourceDataTypes(["position" | "label" | "value" | "row" | "column"]);
/*returns the layersSourceData in 
the specified format*/
cMap.filteredLayersSourceData();

//Returns the selected layer data in row format
cMap.getLayersSelectedLocationsRows();
//Returns the selected layer data in column format
cMap.getLayersSelectedLocationsColumns();

/*Anything below each layer's min value 
will be hidden, this assumes the first 3 map layers.*/
cMap.minValueFilters([10, 11, 1500]);

/*Anything above each layer's max value will be hidden, 
this assumes the first 3 map layers.*/
cMap.maxValueFilters([150, 141, 15100]);

/*Maximum number of layer objects to display, 
this assumes the first 3 map layers. 
maxCountFilters uses the layer's sorted data 
values to determine how many objects to show.*/
cMap.maxCountFilters([5, 6, 7]);

/*Each string corresponds to the layer 
at the same position/index and determines the 
sort type used (ascending or descending ).*/
cMap.maxCountSortType(["ascending|descending", "ascending|descending"]);

/*Each string corresponds to the layer 
at the same position/index and determines the 
filter used. The filter string will be matched 
using case-insensitive, partial matching. So 
if "ME" is specified as a filter, the labels
"same thing" and "James" will produce a positive match.*/
cMap.labelFilters(["ME"]);

//Clears all filters for the specified layerIx
cMap.clearLayerFilters(layerIx);

Getting filtered layer-level data

These flags can be used to filter the data returned by the layer methods
(getting data section above), e.g. layer.getValues(). These don’t affect the display, only
the data returned.

 

/*Restricts the data to only 
what's currently in the viewable map area*/
layer.restrictCalcsToViewport = false;
/*Restricts the data to only what's currently 
visible in the entire map, not just the viewable area.*/
layer.restrictCalcsToVisible = true;
/*Restricts the data to only what's 
currently selected in the layer*/
layer.restrictCalcsToSelected = false;
[/ezcol_2third] [ezcol_1third_end] [post-content id=7776] [/ezcol_1third_end]