This package contains functions mostly for manipulating, rendering and switching among various map views, though it also contains other utility functions that can be useful to various modules.
Function
nhmc.ctrl.scaleStateMap(state, factor)
This function scales the map view specified by state by the scale factor specified by factor. Scaling the map view consists of resizing each state or county path in the map view and then resizing each city label in the map view.
Note
Despite the name state in the argument and the function name, that term in this context is used in a general sense to refer to the name of any map view, including us_all for the nationwide state map and us_counties for the nationwide county map.
Function
nhmc.ctrl.scaleSurface(factor)
This function sets the height and width of the map surface to the default image size scaled in both dimensions by factor; for example, a 768x486px image scaled by 0.5 would be 384x243px.
Function
nhmc.ctrl.scaleCurrentMap(factor)
This function first scales the map surface and then scales the current map view, both by factor.
Function
nhmc.ctrl.setStateColors(states, color)
This function only has an effect on the nationwide state map and sets the fill color of each specified state. It accepts two arguments:
Function
nhmc.ctrl.setCountyColors(state, counties, color)
This function affects both nationwide and statewide county maps. It accepts three arguments:
Function
nhmc.ctrl.addCity(cityName, cityData, existingCities)
This function adds a city label to a map view (currently limited to statewide county maps). It takes three arguments:
Function
nhmc.ctrl.zoomToState(state)
This function clears the current map view (by calling nhmc.cleanup.clearMap) and renders the one named by the state argument.
If tooltips are already bound on the page before this function is called, they are reinitialized when the map view has finished rendering.
See also
For more information on the map views themselves and the objects they comprise, see nhmc.geo.
Function
nhmc.ctrl.hashParams([newParams[, destroyCurrent]])
Some modules make use of the URL fragment identifier to direct users to a particular starting map view or other initial state. To streamline this process, the nhmc.ctrl.hashParams function returns an object that contains all values stored in the fragment identifier. Where possible, items are coerced to Number objects; Boolean values are also accepted in the form of the values “true” or “false”, and keys without values are treated as true.
Assuming the default values for the properties of nhmc.config.hashParams and the fragment identifier foo=bar|spam=false|magic|xyzzy=42, calling nhmc.ctrl.hashParams() would return the following object:
{
"foo": "bar",
"spam": false,
"baz": true,
"xyzzy": 42
}
This function also may be used to set any or all values in the fragment identifier, and it accepts up to two arguments to that effect:
These functions are used for programmatically manipulating states and counties, which consists of clicking them or triggering tooltips related to them.
Function
nhmc.ctrl.highlightArea(area, pageX, pageY)
This function highlights the area object, which is a state or county object from nhmc.geo, renders its tooltip if any exists and positions the tooltip at the coordinates (pageX, pageY) if those coordinates are specified. If those coordinates are not specified, the tooltip is positioned at the left edge of the map with its top edge one-third of the way down the map.
Function
nhmc.ctrl.dehighlightAreas()
This function removes any highlights and tooltips created by nhmc.ctrl.highlightArea.
Function
nhmc.ctrl.highlightCounty(stateName, countyName, pageX, pageY)
This function highlights the county with the name countyName in the state with the name stateName and positions the tooltip (if applicable) at (pageX, pageY) if specified. For more details, see nhmc.ctrl.highlightArea.
Function
nhmc.ctrl.clickCounty(stateName, countyName)
This function triggers a click event on the county with the name countyName in the state with the name stateName. This only makes sense for maps that show counties, such as the nationwide county map or the statewide county maps.
Function
nhmc.ctrl.highlightState(stateName, pageX, pageY)
This function highlights the state with the name stateName and positions the tooltip (if applicable) at (pageX, pageY) if specified. For more details, see nhmc.ctrl.highlightArea.
Function
nhmc.ctrl.clickState(stateName)
This function triggers a click event on the state with the name stateName. This only makes sense for map views with state boundaries, which currently only includes the nationwide state map.
Function
nhmc.ctrl.renderLegend(title, items)
This function was intended to simplify rendering of map legends by accepting two parameters:
This function hasn’t actually been used, though, since individual modules often render the legend in different ways.
Todo
Remove this.