3 function init_wrmap(i, jq_map) {
5 OpenLayers.ImgPath = jq_map.attr('data-img-path'); // e.g. "/mediawiki/extensions/wrmap/openlayers/img/"
6 var jq_sledruns = jq_map.children();
9 // Introduce EPSG:3857 as an alias of the built in EPSG:900913 projection (both are the "Google/OSM" projections)
10 var EPSG4326 = new OpenLayers.Projection("EPSG:4326"); // lon/lat
11 var EPSG3857 = new OpenLayers.Projection("EPSG:3857"); // google
14 var map = new OpenLayers.Map(jq_map.context, {
16 displayProjection: EPSG4326,
22 var layer_map = new OpenLayers.Layer.Google("Google Physical", {
23 type: google.maps.MapTypeId.TERRAIN
26 // // Alternative: OSM map
27 // var layer_map = new OpenLayers.Layer.OSM();
29 // // Alternative: Microsoft Bing Maps
30 // var layer_map = new OpenLayers.Layer.Bing({
32 // key: "AgPH3SlIXAwajrJKf0FORQyhTqsP8KIlvtN6RKfvxe6fOB6q6-HFmg8EOFm7LSOA"});
35 var layer_sledruns = new OpenLayers.Layer.Vector("Rodelbahnen", {
36 styleMap: new OpenLayers.StyleMap({
37 "default": new OpenLayers.Style({
38 externalGraphic: "/vorlagen/bahnzustand${condition}_0.png",
44 backgroundGraphic: "/vorlagen/gmap_rodelbahn_c_s.png",
47 backgroundXOffset: -8,
48 backgroundYOffset: -8,
52 "highlight": new OpenLayers.Style({
54 labelOutlineColor: "white",
59 rendererOptions: {yOrdering: true}
61 jq_sledruns.each(function(j, jq_sledrun) {
62 jq_sledrun = $(jq_sledrun);
63 var lon = parseFloat(jq_sledrun.attr('data-lon'));
64 var lat = parseFloat(jq_sledrun.attr('data-lat'));
65 var point = new OpenLayers.Geometry.Point(lon, lat).transform(EPSG4326, EPSG3857);
66 layer_sledruns.addFeatures([new OpenLayers.Feature.Vector(point, {
67 label: jq_sledrun.attr('data-title'),
68 url: jq_sledrun.attr('data-url'),
69 has_report: jq_sledrun.attr('data-date_report') !== undefined,
70 date_report: jq_sledrun.attr('data-date_report') === undefined ? null : jq_sledrun.attr('data-date_report'),
71 condition: jq_sledrun.attr('data-condition') === undefined ? '0' : jq_sledrun.attr('data-condition')
75 // disable mouse wheel zoom
76 var navigation_control = map.getControlsByClass('OpenLayers.Control.Navigation')[0];
77 navigation_control.disableZoomWheel();
79 // print sledrun name when mouse moves over it
80 map.addControl(new OpenLayers.Control.SelectFeature(layer_sledruns, {
84 renderIntent: "highlight"
87 // show popup when user clicks on a sledrun icon
88 map.addControl(new OpenLayers.Control.SelectFeature(layer_sledruns, {
91 onSelect: function(feature) {
93 var popup_text = "<h2>" + feature.attributes['label'] + '</h2>\n' +
95 '<li><a href="' + feature.attributes['url'] + '">Details zur Rodelbahn</a></li>\n' +
96 '<li>Rodelbahnzustand<br/>';
97 if (feature.attributes['has_report']) {
98 var condition_text = {1: 'Sehr gut', 2: 'Gut', 3: 'Mittelmäßig', 4: 'Schlecht', 5: 'Geht nicht'};
99 var year_month_day = feature.attributes['date_report'].split('-');
100 popup_text += '<a href="' + feature.attributes['url'] + '#Eintr.C3.A4ge">' + condition_text[feature.attributes['condition']] + '</a> ' +
101 '<small>' + year_month_day[2] + '.' + year_month_day[1] + '.</small> ' +
102 '<em><a href="' + feature.attributes['url'] + '#Eintragen">Neu</a></em>';
104 popup_text += '<em><a href="' + feature.attributes['url'] + '#Eintragen">Bitte eintragen</a></em>';
106 popup_text += '</li>\n</ul>\n';
107 var selectFeatureControl = this;
108 var popup = new OpenLayers.Popup.FramedCloud('sledruninfopopup_' + feature.attributes['label'],
109 feature.geometry.getBounds().getCenterLonLat(),
112 null, true, function(event) {
114 selectFeatureControl.unselectAll();
116 feature.popup = popup;
119 onUnselect: function(feature) {
121 map.removePopup(feature.popup);
122 feature.popup.destroy();
123 feature.popup = null;
129 map.addLayers([layer_map, layer_sledruns]);
130 var lon = parseFloat(jq_map.attr('data-center-lon'));
131 var lat = parseFloat(jq_map.attr('data-center-lat'));
132 var zoom = parseInt(jq_map.attr('data-zoom'));
133 map.setCenter(new OpenLayers.LonLat(lon, lat).transform(EPSG4326, map.getProjectionObject()), zoom);
138 function init_wrmaps() {
139 var jq_maps = $('.wrmap'); // all wrmap <div> elements
140 jq_maps.each(init_wrmap);
144 $(document).ready(init_wrmaps);