Layer Filter API

addFilter()

Adds a filter to the filters list on an overlay

Method:
addFilter(layerIndex,expression)

Scope:
F1.Maker.Map

Required Arguments:

ArgumentDescriptionExample
layerIndexthe index of the layer being filtered lowest being 03
expressionactual filter expression being applied to a layer“$[sales] > 1000″

Optional Arguments: (none)

Returns: (none)

Example:


mymap.addFilter(0, { expression: "$[sales] > 1000" });

removeFilter()

Adds a filter to the filters list on an overlay

Method:
removeFilter(layerIndex,expression)

Scope:
F1.Maker.Map

Required Arguments:

ArgumentDescriptionExample
layerIndexthe index of the layer being filtered lowest being 03
expressionactual filter expression being remove from a layer“$[sales] > 1000″

Optional Arguments: (none)

Returns: (none)

Example:

mymap.removeFilter(0, { expression: "$[sales] > 1000" });

getFilters()

List all filters for an overlay

Method:
getFilters(layerIndex)

Scope:
F1.Maker.Map

Required Arguments:

ArgumentDescriptionExample
layerIndexthe index of the layer being filtered lowest being 03

Optional Arguments: (none)

Returns: (none)

Example:

mymap.getFilters(0);

clearFilters()

List all filters for an overlay

Method:
clearFilters(layerIndex)

Scope:
F1.Maker.Map

Required Arguments:

ArgumentDescriptionExample
layerIndexthe index of the layer being cleared of filters lowest being 03

Optional Arguments: (none)

Returns: (none)

Example:

mymap.clearFilters(0);

addHighlight()

Highlights features using a given expression

Method
addHighlight(layerIndex, expression)

Scope
F1.Maker.Map

Required Arguments:

ArgumentDescriptionExample
layerIndexthe 0-based index of the layer for which you would like to change the filter1
expressionthe filter-style expression to evaluate for highlighting“$[population] > 100000″

Optional Arguments: (none)

Returns: (none)

Example:


mymap.addHighlight(0, "$[population] > 100000");

removeHighlight()

Removes a previously added highlight

Method:
removeHighlight(layerIndex, expression)

Scope:
F1.Maker.Map

Required Arguments:

ArgumentDescriptionExample
layerIndexthe 0-based index of the layer for which you would like to change the filter1
expressionthe filter-style expression to remove highlighting“$[population] > 100000″

Optional Arguments: (none)

Returns: (none)

Example:


mymap.removeHighlight(0, "$[population] > 100000");

clearHighlights()

Removes all highlights on a given layer

Method:
clearHighlights(layerIndex)

Scope:
F1.Maker.Map

Required Arguments:

ArgumentDescriptionExample
layerIndexthe 0-based index of the layer for which you would like to remove all the filters1

Optional Arguments: (none)

Returns: (none)

Example:


mymap.clearHighlights(0);

Basics

Filtering a dataset uses an mathematic syntax, using operators and operators.

Syntax:

{ filters: [ { expression: "$[attribute] operator value" } ] }

The operators you may use to evaluate expressions are:
<, >, ==, <=, >=

Logical operators:
AND, OR

Grouping operators:
(, )

For example:
I want all the starbucks that sell (inclusively) between 10,000 and 50,000 cups yearly, where the median income is below $50,000, is franchised:

{ filters: [ { expression: "$[sales] >= 10000 AND $[sales] <= 50000 AND $[income] < 50000 AND $[franchised] == true" } ] }

Example with parentheses and OR operators:

{ filters: [ { expression: "($[sales] <= 10000 OR $[sales] > 50000) AND ($[income] < 50000 AND $[franchised] == 'true') AND $[business] == 'starbucks'" } ] }

Multiple filters will all be run independently, so inherently executed with an AND logical operator.

Javascript API

You may use the following methods to add, remove, list, and clear filters.
In the following examples, overlayId can be either the GeoIQ overlay ID, or the 0-based layer index on the map. (For example, the first layer in a map would be id 0)

addFilter(overlayId, filter) – Adds a filter to the filters list on an overlay

F1.Maker.current_map.addFilter(0, { expression: "$[sales] > 1000" });

removeFilter(overlayId, filter) – Removes a filter from the filters list on an overlay

F1.Maker.current_map.removeFilter(0, { expression: "$[sales] > 1000" });

getFilters(overlayId) – List all filters for an overlay

F1.Maker.current_map.getFilters(0);

clearFilters(overlayId) – Remove all custom filters from an overlay

F1.Maker.current_map.clearFilters(0);

Creating a Filtered Map

To create a map with filters on an overlay, or add an overlay with filters to a map, follow the instructions on the [[Visualization_API]], but add the ‘filters’ section for each overlay on which you would like a filter, like so:

{   
	"title": "State Population",
	"tags": ["demographics","US"],
	"description": "A map showing the US state population in 2005.",
	"layers": [{
		"source": "finder:968",
		"visible": true,
		"opacity": 1.0,
		"title": "Population by State",
		"subtitle": "2005",
		"filters": [ { expression: "$[population] < 5000000 or $[population] > 10000000" } ],
		"styles": {
			"type": "GRADUATED",
			"icon": {
				"opacity": 0.75,
				"size": 1,
				"symbol": "propCircle",
				"classificationType": "St Dev",
				"selectedAttribute": "pop 2005",
				"categories": 5,
				"color": "0x74479a" 
			}
		}
	}],
	"extent": "-163.370225180872,13.3953456046146,-52.1006976720957,61.8070605914375",
	"basemap": "OpenStreetMap (Road)" 
}

addLayerCategoryFilter()

Sets layer categorical icons based on the string value of an attribute. This is useful for setting the icons of a the features in a dataset based on categories such as land use or business type.

Method
addLayerCategoryFilter(layerID, categoryDefinition)

Scope
F1.Maker.Map

Arguments

  • layerID (_required_) Layer index (_integer_)
  • categoryDefinition (_required_) a hash of definiing the attribute and categories
    • attribute (_required_) the string name of the attribute to them based on category
    • categories (_required_) a hash of Category (_string_) with Icon URL (_string_)

Example

mymap.addLayerCategoryFilter(0,{attribute:"Operation Sector",categories:{"Health":"image1.jpg","Water and Infrastructure:"image2.jpg"}})

addLayerInfoWindowFilter()

Defines InfoWindow content. Sets content filters based on layer attributes.

Method
addLayerInfoWindowFilter(layerID, filterDefinition)

Scope
F1.Maker.Map

Arguments

  • layerID (_required_) Layer index (_integer_)
  • filterDefinition (_required_) a hash of defining info window parameters
    • title (_optional_) a string defining info window title. Use $[attribute] to pass attribute value
    • subtitle (_optional_) a string defining info window sub itle. Use $[attribute] to pass attribute value
    • tabs (_optional_) a hash defining tabs – title, content.
      • title (_required_) string, tab title. Use $[attribute] to pass attribute value.
      • value (_required_) string, tab content. Use $[attribute] to pass attribute value. When populating a table simple pass attribute names $[attribute1]$[attribute2]$[attribute3] etc.
      • type (_required_) string, tab type. Available types – text, table.

Example

mymap.addLayerInfoWindowFilter('0',{title:"Title is $[attribute]", subtitle:"Subtitle string", tabs:[{title:"Text tab", type:"text", value:"Hello world $[attribute]"},{title:"Table tab", value:"$[attribute]", type:"table"}]})
 

Comments are closed.