Newer
Older
Alan Palazzolo
committed
/**
* @file
* JS Implementation of OpenLayers behavior.
*/
* Javascript Drupal Theming function for inside of Tooltips
* To override
*
* @param feature
* OpenLayers feature object.
Drupal.theme.prototype.openlayersTooltip = function(feature) {
Alan Palazzolo
committed
if (feature.attributes.name) {
output += '<div class="openlayers-popup openlayers-tooltip-name">' + feature.attributes.name + '</div>';
}
if (feature.attributes.description) {
output += '<div class="openlayers-popup openlayers-tooltip-description">' + feature.attributes.description + '</div>';
}
Alan Palazzolo
committed
return output;
/**
* OpenLayers Tooltip Behavior
*/
Alan Palazzolo
committed
Drupal.openlayers.addBehavior('openlayers_behavior_tooltip', function (data, options) {
var map = data.openlayers;
var layers = [];
Alan Palazzolo
committed
// For backwards compatiability, if layers is not
// defined, then include all vector layers
if (typeof options.layers == 'undefined' || options.layers.length == 0) {
layers = map.getLayersByClass('OpenLayers.Layer.Vector');
}
else {
for (var i in options.layers) {
var selectedLayer = map.getLayersBy('drupalID', options.layers[i]);
if (typeof selectedLayer[0] != 'undefined') {
layers.push(selectedLayer[0]);
Alan Palazzolo
committed
}
}
Alan Palazzolo
committed
// if only 1 layer exists, do not add as an array. Kind of a
// hack, see https://drupal.org/node/1393460
if (layers.length == 1) {
layers = layers[0];
}
Alan Palazzolo
committed
// Define feature select events for selected layers.
var popupSelect = new OpenLayers.Control.SelectFeature(layers,
{
hover: true,
clickout: false,
multiple: false,
onSelect: function(feature) {
// Create FramedCloud popup for tooltip.
var output = Drupal.theme('openlayersTooltip', feature);
if (typeof output != 'undefined') {
popup = new OpenLayers.Popup.FramedCloud(
'tooltip',
feature.geometry.getBounds().getCenterLonLat(),
null,
output,
null,
true
);
feature.popup = popup;
feature.layer.map.addPopup(popup);
Drupal.attachBehaviors();
Alan Palazzolo
committed
},
onUnselect: function(feature) {
// Remove popup.
if (typeof feature.popup != 'undefined') {
feature.layer.map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}
}
Alan Palazzolo
committed
);
Campbell Vertesi
committed
popupSelect.handlers['feature'].stopDown = false;
popupSelect.handlers['feature'].stopUp = false;
Alan Palazzolo
committed
// Actiate the popups
map.addControl(popupSelect);
popupSelect.activate();
});