Now a popup with clickable link is shown when clicking on a sledrun.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Wed, 12 Dec 2012 13:17:50 +0000 (13:17 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Wed, 12 Dec 2012 13:17:50 +0000 (13:17 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/trunk/extensions/wrmap@1230 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrmap.js

index d269823bfbeef6081f881b87dd078001c5111cf9..b146387e4041faca7ecd15e4cc3188bda4d427f0 100644 (file)
--- a/wrmap.js
+++ b/wrmap.js
@@ -61,7 +61,10 @@ function init_wrmap(i, jq_map) {
                var lon = parseFloat(jq_sledrun.attr('data-lon'));
                var lat = parseFloat(jq_sledrun.attr('data-lat'));
                var point = new OpenLayers.Geometry.Point(lon, lat).transform(EPSG4326, EPSG3857);
-               layer_sledruns.addFeatures([new OpenLayers.Feature.Vector(point, {label: jq_sledrun.attr('data-title')})]);
+               layer_sledruns.addFeatures([new OpenLayers.Feature.Vector(point, {
+                       label: jq_sledrun.attr('data-title'),
+                       url: jq_sledrun.attr('data-url')
+               })]);
        });
        map.addControl(new OpenLayers.Control.SelectFeature(layer_sledruns, {
                hover: true,
@@ -69,6 +72,34 @@ function init_wrmap(i, jq_map) {
                autoActivate: true,
                renderIntent: "highlight"
        }));
+       map.addControl(new OpenLayers.Control.SelectFeature(layer_sledruns, {
+               autoActivate: true,
+               toggle: true,
+               onSelect: function(feature) {
+                       // Open popup
+                       var selectFeatureControl = this;
+                       var popup = new OpenLayers.Popup.FramedCloud("sledruninfopopup_" + feature.attributes['label'], 
+                       feature.geometry.getBounds().getCenterLonLat(),
+                       null,
+                       "<h2>" + feature.attributes['label'] + "</h2>\n" +
+                       "<ul>\n" + 
+                       "<li><a href=\"" + feature.attributes['url'] + "\">Details</a></li>\n" +
+                       "</ul>\n",
+                       null, true, function(event) {
+                               // onPopupClose
+                               selectFeatureControl.unselectAll();
+                       });
+                       feature.popup = popup;
+                       map.addPopup(popup);
+               },
+               onUnselect: function(feature) {
+                       // Close popup
+                       map.removePopup(feature.popup);
+                       feature.popup.destroy();
+                       feature.popup = null;
+               }
+       }));
+
 
        // Center map
        map.addLayers([layer_map, layer_sledruns]);