3 function init_wrmap(i, jq_map) {
5 var jq_map_script = jq_map.children();
6 OpenLayers.ImgPath = jq_map.attr('data-img-path'); // e.g. "/mediawiki/extensions/wrmap/openlayers/img/"
7 var json_string = jq_map_script.text();
8 jq_map_script.detach();
11 // extract, tranform and split features to layers
12 var EPSG4326 = new OpenLayers.Projection("EPSG:4326"); // lon/lat
13 var EPSG3857 = new OpenLayers.Projection("EPSG:3857"); // google
14 var POINT_NAME = {'sledrun': 'Rodelbahn', 'inn': 'Gasthaus', 'busstop': 'Haltestelle', 'carpark': 'Parkplatz', 'attention': 'Achtung', 'point': 'Punkt'};
15 var format_json = new OpenLayers.Format.GeoJSON();
16 var features_all = format_json.read(json_string);
17 var features_path = new Array();
18 var features_point = new Array();
19 for (var i = 0; i != features_all.length; ++i) {
20 var feature = features_all[i];
21 feature.geometry.transform(EPSG4326, EPSG3857);
22 if (feature.geometry instanceof OpenLayers.Geometry.Point) features_point.push(feature);
23 else features_path.push(feature);
29 var layer_map = new OpenLayers.Layer.Google("Google Physical", {
30 type: google.maps.MapTypeId.TERRAIN
33 // // Alternative: OSM map
34 // var layer_map = new OpenLayers.Layer.OSM();
36 // // Alternative: Microsoft Bing Maps
37 // var layer_map = new OpenLayers.Layer.Bing({
39 // key: "AgPH3SlIXAwajrJKf0FORQyhTqsP8KIlvtN6RKfvxe6fOB6q6-HFmg8EOFm7LSOA"});
44 var layer_path = new OpenLayers.Layer.Vector("Path", {
45 styleMap: new OpenLayers.StyleMap(new OpenLayers.Style({
46 strokeColor: '${getStrokeColor}',
47 strokeWidth: '${getStrokeWidth}'
50 getStrokeColor: function(feature) {
51 if (feature.attributes.strokeColor !== undefined) return feature.attributes.strokeColor;
52 if (feature.attributes.type == 'sledrun') return '#014e9a';
53 if (feature.attributes.type == 'walk') return '#e98401';
54 if (feature.attributes.type == 'alternative') return '#7f7fff';
55 if (feature.attributes.type == 'lift') return '#000000';
58 getStrokeWidth: function(feature) {
59 if (feature.attributes.strokeWidth !== undefined) return feature.attributes.strokeWidth;
60 if (feature.attributes.type == 'lift') return 3;
70 var filter_point_sledrun = new OpenLayers.Filter.Comparison({
71 type: OpenLayers.Filter.Comparison.EQUAL_TO,
76 var layer_point = new OpenLayers.Layer.Vector("Point", {
77 styleMap: new OpenLayers.StyleMap({
78 'default': new OpenLayers.Style({
80 backgroundGraphicZIndex: 11,
83 // the following context functions should only be available in the rule that uses them,
84 // but the rule dependent contexts are ignored by OpenLayers (I think that's a bug)
85 getCondition: function(feature) {
86 if (feature.condition === undefined) return 0;
87 return feature.condition;
89 getSymbol: function(feature) {
90 var name = POINT_NAME[feature.attributes.type];
91 if (feature.attributes.type == 'point' || name === undefined) return '';
97 filter: filter_point_sledrun,
99 externalGraphic: '/vorlagen/bahnzustand${getCondition}_0.png',
104 backgroundGraphic: "/vorlagen/gmap_rodelbahn_c_s.png",
106 backgroundHeight: 23,
107 backgroundXOffset: -8,
108 backgroundYOffset: -8,
111 new OpenLayers.Rule({
114 externalGraphic: '/vorlagen/gmap${getSymbol}.png',
123 highlight: new OpenLayers.Style({
124 label: "${getTitle}",
125 labelOutlineColor: "white",
129 getTitle: function(feature) {
131 if (feature.attributes.type != 'point') {
132 title = POINT_NAME[feature.attributes.type];
133 if (feature.attributes.name !== undefined) title += ': ';
135 if (feature.attributes.name !== undefined) title += feature.attributes.name;
140 new OpenLayers.Rule({
141 filter: filter_point_sledrun,
147 new OpenLayers.Rule({
156 rendererOptions: {yOrdering: true}
162 var lon = parseFloat(jq_map.attr('data-center-lon'));
163 var lat = parseFloat(jq_map.attr('data-center-lat'));
164 var zoom = parseInt(jq_map.attr('data-zoom'));
165 var map = new OpenLayers.Map(jq_map.context, {
166 projection: EPSG3857,
167 displayProjection: EPSG4326,
170 layers: [layer_map, layer_path, layer_point],
171 center: new OpenLayers.LonLat(lon, lat).transform(EPSG4326, EPSG3857),
177 // if this would be done before the layer is added to the map, the features are not added
178 layer_path.addFeatures(features_path);
179 layer_point.addFeatures(features_point);
181 // disable mouse wheel zoom
182 var navigation_control = map.getControlsByClass('OpenLayers.Control.Navigation')[0];
183 navigation_control.disableZoomWheel();
186 // map.addControl(new OpenLayers.Control.LayerSwitcher());
188 // print sledrun name when mouse moves over it
189 map.addControl(new OpenLayers.Control.SelectFeature(layer_point, {
193 renderIntent: "highlight"
196 // show popup when user clicks on a sledrun icon
197 map.addControl(new OpenLayers.Control.SelectFeature(layer_point, {
200 onSelect: function(feature) {
202 if (feature.attributes.type == 'sledrun') {
203 popup_text += "<h2>" + feature.attributes.name + '</h2>\n' +
205 '<li><a href="' + feature.attributes.wiki + '">Details zur Rodelbahn</a></li>\n' +
206 '<li>Rodelbahnzustand<br/>';
207 if (feature.attributes.condition !== undefined) {
208 var condition_text = {1: 'Sehr gut', 2: 'Gut', 3: 'Mittelmäßig', 4: 'Schlecht', 5: 'Geht nicht'};
209 var year_month_day = feature.attributes.date_report.split('-');
210 popup_text += '<a href="' + feature.attributes.wiki + '#Eintr.C3.A4ge">' + condition_text[feature.attributes.condition] + '</a> ' +
211 '<small>' + year_month_day[2] + '.' + year_month_day[1] + '.</small> ' +
212 '<em><a href="' + feature.attributes.wiki + '#Eintragen">Neu</a></em>';
214 popup_text += '<em><a href="' + feature.attributes.wiki + '#Eintragen">Bitte eintragen</a></em>';
216 popup_text += '</li>\n</ul>\n';
217 } else if (feature.attributes.wiki !== undefined) {
218 if (feature.attributes.name != undefined) popup_text += '<h2>' + feature.attributes.name + '</h2>\n';
219 popup_text += '<p><a href="' + feature.attributes.wiki + '">Details</a></p>\n';
223 var selectFeatureControl = this;
224 var popup = new OpenLayers.Popup.FramedCloud('sledruninfopopup_' + feature.attributes.wiki,
225 feature.geometry.getBounds().getCenterLonLat(),
228 null, true, function(event) {
230 selectFeatureControl.unselectAll();
232 feature.popup = popup;
235 onUnselect: function(feature) {
236 if (feature.popup === null) return;
239 map.removePopup(feature.popup);
240 feature.popup.destroy();
241 feature.popup = null;
247 function init_wrmaps() {
248 var jq_maps = $('.wrmap'); // all wrmap <div> elements
249 jq_maps.each(init_wrmap);
253 $(document).ready(init_wrmaps);