Layer Methods
These Javascript methods allow you to inspect, add, remove, and style layers on a map.
getLayers()
Get an array of the layers hash.
Method
getLayers()
Scope
F1.Maker.Map
Required Arguements: (none)
Optional Arguments: (none)
Returns:
An array of Layer objects.
Example:
mymap.getLayers();
var layers = mymap.getLayers();
// layers = [
// {
// title: "My First Layer",
// source: "finder:45",
// styles: {...},
// opacity: 1,
// visibility: 1,
// order: 1
// }]
removeLayer()
Deletes a layer from the map.
Method
F1.Maker.Map.removeLayer(layerIndex)
Required Arguements:
| Argument | Description | Example |
|---|---|---|
| layerIndex | index of the layer to show or hide. 0 is the bottom layer and then layers increase up | 1 |
Optional Arguments: (none)
Returns:
“1″ if the layer is deleted and 0 if the delete was unsuccessful.
Example:
mymap.removeLayer(0);
addLayer()
Method
addLayer(layerDefinition)
Scope
F1.Maker.Map
Required Arguements:
| Argument | Description | Example |
|---|---|---|
| layerDefinition | a hash of options for defining the layer | {} |
| source | the id of the layer | “finder:99084″ |
Optional Arguments:
| Argument | Description | Example |
|---|---|---|
| title | the string name to use for the layer title (default is the dataset title | “Hospitals in Virginia” |
| subtitle | string name for the subtitle (default: selectedAttribute name) | “Type of Hospital” |
| order | integer value to put the layer in the layers index. 0 is bottom (default:topmost layer) | |
| visibility | if the layer is visible (default: true) | {visibility:false} |
| opacity | decimal amount of opacity from 0-1 0 is transparent, 1 is fully opaque (default: .75) | {opacity: 1.0} |
| styles | the JSON hash that defines the layer. See the REST Styling API for details | styles: { type: “CHOROPLETH”, fill: { color: 0x0000FF, opacity: 0.5 } } |
| zoomToExtent | zoom to the extent of the dataset after it is mapped (default: false) | {zoomToExtent:true} |
Returns: (none)
Examples:
mymap.addLayer( { source: "finder:55" } );
// Set the title on loading, but make it hidden
mymap.addLayer( { source: "finder:55",
title: "A new layer",
subtitle: "Source: News Agency"
order: 1,
visibility: false,
opacity: 0.7,
styles: { type: "CHOROPLETH", fill: { color: 0x0000FF, opacity: 0.5 } } } );
// Automatically zoom to the layer extent on loading
mymap.addLayer( { source: "finder:55", styles: { type: "CHOROPLETH", fill: { color: 0x0000FF, opacity: 0.5 } } }, true );
// Adding a point dataset
mymap.addLayer( { source: "finder:59", title: "new layer title", position: 0, styles: { type: "GRADUATED", icon: { color: 0x0000FF, selectedAttribute: "count", classificationType: "Equal Interval", opacity: 0.5 } } } );
// Adding a polygon dataset
mymap.addLayer( { source: "finder:59", title: "new layer title", position: 0, styles: { type: "GRADUATED", icon: { colors: [14343142, 11580379, 7505585, 4481915, 2966850], selectedAttribute: "count", classificationType: "Manual", classificationBreaks: "[100, 130, 160, 200]", opacity: 0.5 } } } );
showLayer
Method
showLayer(layerIndex, visibility)
Scope
F1.Maker.Map
Required Arguements:
| Argument | Description | Example |
|---|---|---|
| layerIndex | index of the layer to show or hide. 0 is the bottom layer and increasing up | 1 |
| visibility | true if visible, false to hide (default: true) | true |
Optional Arguments: (none)
Returns: (none)
Example:
mymap.showLayer(10, true);
getLayer()
Returns the definition of a particular layer in the map as a hash.
Method
getLayer(layerIndex)
Scope
F1.Maker.Map
Required Arguements:
| Argument | Description | Example |
|---|---|---|
| layerIndex | index of the layer to show or hide. 0 is the bottom layer and increasing up | 1 |
Optional Arguments: (none)
Returns:
A reference to the layer
Object { source="finder:12784", styles={...}, more...}
Example:
mymap.getLayer(2);
setLayerStyle()
Method
setLayerStyle(layerDefinition)
Scope
F1.Maker.Map
Required Arguements:
| Argument | Description | Example |
|---|---|---|
| layerDefinition | the JSON hash of the layer definition and styles. For this use, the “source” actually refers to the layer index in the array of layers. See the Styling API for details on the “styles” parameter. | |
Optional Arguments: (none)
Returns: (none)
Example:
//Point
mymap.setLayerStyle( 0, { type: "POINT", icon: { size: 5, symbol: "flagIcon" } } );
mymap.setLayerStyle( 0, { type: "PROPORTIONAL", icon: { size: 10, symbol: "circleIcon", color: 0x00FF66, opacity: 0.5 } } );
mymap.setLayerStyle( 0, { type: "GRADUATED", icon: { classificationType: "EQUAL INTERVAL", categories: 5, symbol: "outlineSquare", colors: [0xFF776D, 0xFCC5BB, 0xF7F7F7, 0xC6DBEF, 0x4292C6], opacity: 0.75 } } );
//Custom Point Icons
mymap.setLayerStyle(0, {type: "POINT", icon:{symbol: "http://iconurlhere.com/icon.png"}});
//Polygon
mymap.setLayerStyle( 0, { type: "CHOROPLETH", fill: { classificationType: "QUANTILE", categories: 5, colors: [0xEFF3FF, 0xBDD7E7, 0x6BAED6, 0x3182BD, 0x08519C], opacity: 0.75 } } );
//Line
mymap.setLayerStyle( 0, { type: "LINE", fill: { lineStyle: "thick", color: 0x0000FF, opacity: 0.75 }, stroke: { weight: 4 } } );
mymap.setLayerStyle( 0, { type: "LINE", icon: { lineStyle: "dashedThick" }, stroke: { color: 0x0000FF, alpha: 1, weight: 3 } } );
setLayerTitle()
Method:
setLayerTitle(layerIndex, title)
Scope:
F1.Maker.Map
| Argument | Description | Example |
|---|---|---|
| layerIndex | the 0-based index of the layer for which you would like to change the title | 1 |
| title | the new title of the layer (is a string) | “US States” |
Optional Arguments: (none)
Returns: (none)
Example:
mymap.setLayerTitle(0, "US States");
setLayerSubTitle()
Method
setLayerSubTitle(layerIndex, subTitle)
Scope
F1.Maker.Map
Required Arguments:
| Argument | Description | Example |
|---|---|---|
| layerIndex | the 0-based index of the layer for which you would like to change the title | 1 |
| subTitle | the new sub-title of the layer (is a string) | “Population” |
Optional Arguments: (none)
Returns: (none)
Example:
mymap.setLayerSubTitle(0, "Population by state");
GeoIQ Blog- TechCamp April 30, 2012 Andrew Turner
- Visualizing our Changing Climate with Climascope April 27, 2012 Andrew Turner
- World Bank Annual Meetings April 23, 2012 Andrew Turner
- Just in Time Analytics – Kanban for Big Data April 5, 2012 Sean Gorman
- GeoIQ team at Where2.0, JSConf, FOSS4G-NA March 22, 2012 Andrew Turner
