The FeaturePopups control selects vector features from a given layers on click and hover and can show the feature attributes in a popups.
OpenLayers. | The FeaturePopups control selects vector features from a given layers on click and hover and can show the feature attributes in a popups. |
Properties | |
mode | To enable or disable the various behaviors of the control. |
autoActivate | {Boolean} Activate the control when it is added to a map. |
selectOptions | {Object|null} Used to set non-default properties on SelectFeature control dedicated to select features. |
boxSelectionOptions | {Object|null} Used to set non-default properties on <OpenLayers.Handler.Box> dedicated to select features by a box. |
hoverOptions | {Object|null} Used to set non-default properties on SelectFeature control dedicated to highlight features. |
popupOptions | {Object} Options used to create a popup manager for hover & selections, see defaults for any valid keys. |
popupHoverOptions | {Object} Options used to create a popup manager to highlight on hover. |
popupHoverListOptions | {Object} Options used to create a popup manager for highlight on hover a cluster. |
popupSingleOptions | {Object} Options used to create a popup manager for single selections. |
popupListOptions | {Object} Options used to create a popup manager for multiple selections. |
popupListItemOptions | {Object} Options used to create the popup manager for show a single item into a multiple selection. |
layerListTemplate | Default is “<h2>${layer.name} - ${count}</h2><ul>${html}</ul>” |
hoverClusterTemplate | Default is “Cluster with ${cluster.length} features<br>on layer \”${layer.name}\”” |
Constructor | |
OpenLayers. | Create a new control that internally uses two <OpenLayers.Control.SelectFeature> one for selecting features, and another only to highlight them by hover (see selectOptions, and hoverOptions). |
Functions | |
destroy | |
activate | Activates the control. |
deactivate | Deactivates the control. |
clear | Clear selecction and popups. |
addLayer | Add the layer to control and assigns it the templates, see options. |
addLayers | |
removeLayer | |
unselectAll | Unselect all selected features, only works if the control is active. |
unselectGeneric | Unselect all selected features on layers on the control that don’t have popupOptions. |
unselectLayer | Unselect all selected features on the layer, only works if the control is active and layer is on the control. |
Constants | |
Modes |
To enable or disable the various behaviors of the control.
NONE | To not activate any particular behavior. CLOSE_ON_REMOVE -Popups will close when removing features in a layer, is ignored when used in conjunction with SAFE_SELECTION. |
SAFE_SELECTION | Features will remain selected even have been removed from the layer. Is useful when using <OpenLayers.Strategy.BBOX> with features with “fid” or when using <OpenLayers.Strategy.Cluster>. Using “BBOX” when a feature is added back to the layer will be re-selected automatically by “fid”. |
CLOSE_ON_UNSELECT | Popups will close when unselect the feature. |
CLOSE_BOX | Display a close box inside the popups. |
UNSELECT_ON_CLOSE | To unselect all features when a popup is closed. |
DEFAULT | Includes default behaviors SAFE_SELECTION | CLOSE_ON_UNSELECT | CLOSE_BOX | UNSELECT_ON_CLOSE |
Default is OpenLayers.Control.FeaturePopups.DEFAULT.
{Object|null} Used to set non-default properties on SelectFeature control dedicated to select features. When using a null value the select features control is not created. The default is create the control.
{Object|null} Used to set non-default properties on <OpenLayers.Handler.Box> dedicated to select features by a box. When using a null value the handler is not created. The default is do not create the handler, so don’t use box selection.
{Object|null} Used to set non-default properties on SelectFeature control dedicated to highlight features. When using a null value (or selectOptions.hover == true) the highlight features control is not created. The default is create the control.
{Object} Options used to create a popup manager for hover & selections, see defaults for any valid keys.
May contain 5 valid keys: “hover”,”hoverList”, “list”, “single” and, “listItem”. To not use the popups associated with a key set the value of the key to null.
For more details of valid options for any key see FeaturePopups.Popup.Constructor.
NOTE: Use this keys instead of popupHoverOptions, popupHoverListOptions, popupListOptions, popupSingleOptions and popupListItemOptions.
popupClass | <OpenLayers.Popup.Anchored> |
panMapIfOutOfView | false |
followCursor | true |
anchor | {size: new OpenLayers.Size(15, 19), offset: new OpenLayers.Pixel(-1, -1)} |
relatedToClear | [“hoverList”] |
popupClass | <OpenLayers.Popup.Anchored> |
panMapIfOutOfView | false |
followCursor | true |
anchor | {size: new OpenLayers.Size(15, 19), offset: new OpenLayers.Pixel(-1, -1)} |
relatedToClear | [“hover”] |
popupClass | <OpenLayers.Popup.FramedCloud> |
panMapIfOutOfView | true |
unselectFunction | Depends on the FeaturePopups.mode (internal use) |
closeBox | Depends on the FeaturePopups.mode (internal use) |
observeItems | true (internal use) |
relatedToClear | [“hover”, “hoverList”, “listItem”, “single”] |
popupClass | <OpenLayers.Popup.FramedCloud> |
panMapIfOutOfView | true |
unselectFunction | Depends on the mode (internal use) |
closeBox | Depends on the mode (internal use) relatedToClear: [“hover”, “hoverList”, “listItem”, “list”] |
popupClass | <OpenLayers.Popup.FramedCloud> |
panMapIfOutOfView | true |
closeBox | Depends on the mode (internal use) |
relatedSimultaneous | {axis: “v”, related: “list”} (internal use) |
relatedToClear | [“single”] |
{Object} Options used to create a popup manager to highlight on hover. See FeaturePopups.Popup constructor options for more details.
popupClass | <OpenLayers.Popup.Anchored> |
panMapIfOutOfView | false |
followCursor | true |
anchor | {size: new OpenLayers.Size(15, 19), offset: new OpenLayers.Pixel(-1, -1)} |
relatedToClear | [“hoverList”] |
{Object} Options used to create a popup manager for highlight on hover a cluster. See FeaturePopups.Popup constructor options for more details.
popupClass | <OpenLayers.Popup.Anchored> |
panMapIfOutOfView | false |
followCursor | true |
anchor | {size: new OpenLayers.Size(15, 19), offset: new OpenLayers.Pixel(-1, -1)} |
relatedToClear | [“hover”] |
{Object} Options used to create a popup manager for single selections. See FeaturePopups.Popup constructor options for more details.
popupClass | <OpenLayers.Popup.FramedCloud> |
panMapIfOutOfView | true |
unselectFunction | Depends on the mode |
closeBox | Depends on the mode relatedToClear: [“hover”, “hoverList”, “list”, “listItem”] |
{Object} Options used to create a popup manager for multiple selections. See FeaturePopups.Popup constructor options for more details.
popupClass | <OpenLayers.Popup.FramedCloud> |
panMapIfOutOfView | true |
unselectFunction | Depends on the mode |
closeBox | Depends on the mode |
observeItems | true |
relatedToClear | [“hover”, “hoverList”, “single”, “listItem”] |
{Object} Options used to create the popup manager for show a single item into a multiple selection. See FeaturePopups.Popup constructor options for more details.
popupClass | <OpenLayers.Popup.FramedCloud> |
panMapIfOutOfView | true |
closeBox | Depends on the mode |
relatedToClear | [“single”] |
relatedSimultaneous | {axis: “v”, related: “list”} |
Create a new control that internally uses two <OpenLayers.Control.SelectFeature> one for selecting features, and another only to highlight them by hover (see selectOptions, and hoverOptions). This control can use also a <OpenLayers.Handler.Box> to select features by a box, see boxSelectionOptions .
The control can generates three types of popup: “hover”, “single” and “list”, see addLayer. Each popup has a displayClass according to their type: “[displayClass]_hover” ,”[displayClass]_select” and “[displayClass]_list” respectively.
options | {Object} |
addLayer: function( layer, options )
Add the layer to control and assigns it the templates, see options.
To add a layer that has already been added (maybe automatically), first must be removed using removeLayer.
Templates containing patterns as ${i18n(“key”)} are internationalized using <OpenLayers.i18n> function.
The control uses the patterns as ${showPopup()} in a “item” template to show individual popups from a list. This pattern becomes a combination of the layer.id+feature.id and can be used only as an html attribute.
layer | {<OpenLayers.Layer.Vector>} |
options | {Object} Optional |
templates | {Object} Templates |
listContext | {Object} Contains the keys with the values that were used instead of values of context used by templates `list` and `hoverList`. If ‘undefined’ key exists their value will be used instead of text ‘undefined’. |
featureContext | {Object} Contains the keys with the values --could be a function or {string}--, the resulting value is used instead of values of feature property with the same name. Used by templates: single, item, hover, hoverItem. If ‘undefined’ key exists their value will be used instead of text ‘undefined’. |
eventListeners | {Object} This object will be registered with <OpenLayers.Events.on>, default scope is the control. |
pupupOptions | {Object} Inform to display the list popup separate from other layers, set to {} to use default options. See <FeaturePopups.Layer.pupupOptions> property for more details. |
templates: { hover: '${.name}', single: 'Name: ${.name}<br>Area: ${area} km2<hr>${.description}', item: '<li><a href="#" ${showPopup()}>${.name}</a></li>' }, featureContext: { area: function(feature) { return feature.geometry.getArea(); }, ... }, ...
NOTE: If the features of the layer may have an ”fid” duplicate the key “fid” of “featureContext” should be declared, and returns unique values for each layer features, e.g. as
... }, featureContext: { fid: function(feature) { return feature.id; }, ... }, ...
single | {String || Function} template used to show a single feature. |
list | {String || Function} template used to show selected features as a list (each feature is shown using “item”), defaul is layerListTemplate. |
item | {String || Function} template used to show a feature as a item in a list. |
hover | {String || Function} template used on hover a single feature. |
hoverList | {String || Function} template used on hover a clustered feature. |
hoverItem | {String || Function} template used to show a feature as a item in a list on hover a clustered feature. |
single, item, hover, hoverItem | Context is feature, can use `.` instead of `attributes.`, note that the feature can not have a layer property whether it belongs from clustered feature. |
list, hoverList | context is a object with three properties: “count” (number of features) “html” (html of list of features) and “layer” (vector layer) |
If specified some template as layer property and as options has priority the options template.
selectionchanged | Triggered after selection is changed, receives a event with “layer” and “selection” as array of features (note that features are not clustered and in this case may lack the property layer) |
featureschanged | Triggered after layer features are changed, fired only changing the list of features and ignore the clusters changes or recharge if obtained new features but with the same “fid”. Receives a event with “layer” and “features” as array of features (note that features are not clustered and in this case may lack the property layer) |
Note: “featureschanged” event is the first if the “selectionchanged” event is also triggered.
unselectGeneric: function()
Unselect all selected features on layers on the control that don’t have popupOptions. Only works if the control is active.
NONE | {Integer} Used in mode indicates to not activate any particular behavior. |
CLOSE_ON_REMOVE | {Integer} Used in mode indicates that the popups will close when removing features in a layer. |
SAFE_SELECTION | {Integer} Used in mode indicates that the features will remain selected even have been removed from the layer. Is useful when using <OpenLayers.Strategy.BBOX> with features with “fid” or when using <OpenLayers.Strategy.Cluster>. Using “BBOX” when a feature is added back to the layer will be re-selected automatically by “fid”. |
CLOSE_ON_UNSELECT | {Integer} Used in mode indicates that the popups will close when unselect the feature. |
CLOSE_BOX | {Integer} Used in mode indicates to display a close box inside the popups. |
UNSELECT_ON_CLOSE | {Integer} Used in mode indicates to unselect all features when a popup is closed. |
DEFAULT | {Integer} Used in mode indicates to activate default behaviors as SAFE_SELECTION | CLOSE_ON_UNSELECT | CLOSE_BOX | UNSELECT_ON_CLOSE. |
destroy: function()
Activates the control.
activate: function()
Deactivates the control.
deactivate: function()
Clear selecction and popups.
clear: function()
Add the layer to control and assigns it the templates, see options.
addLayer: function( layer, options )
addLayers: function( layers )
removeLayer: function( layer )
Unselect all selected features, only works if the control is active.
unselectAll: function()
Unselect all selected features on layers on the control that don’t have popupOptions.
unselectGeneric: function()
Unselect all selected features on the layer, only works if the control is active and layer is on the control.
unselectLayer: function( layer )