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. |
| 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 | |
| showSingleFeatureById | |
| addSelectionByIds | |
| setSelectionByIds | |
| removeSelectionByIds | |
| getSelectionIds | |
| 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 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 |
| unselectOnClose | Depends on the mode |
| closeBox | Depends on the mode |
| observeItems | true 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 |
| unselectOnClose | 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, if “fid” key is declared must be a function that returns unique values for each layer features. (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. |
NOTE: If the features of the layer may have an ”fid” duplicate the key “fid” of “featureContext” should be declared, 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 to a clustered layer. |
| 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.
showSingleFeatureById: function( layerId, featureId )
| layerId | {String} id of the layer of selected feature. |
| featureId | {String} id of the feature, see featureContext at addLayer. |
| 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 )
showSingleFeatureById: function( layerId, featureId )
addSelectionByIds: function( layerId, featureIds, silent )
setSelectionByIds: function( layerId, featureIds, silent )
removeSelectionByIds: function( layerId, featureIds, silent )
getSelectionIds: function( layer )