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 format_json = new OpenLayers.Format.GeoJSON();
15 var features_all = format_json.read(json_string);
16 var features_path = new Array();
17 var features_point = new Array();
18 var features_sledrun = 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.CLASS_NAME == 'OpenLayers.Geometry.Point') {
23 if (feature.attributes.type == 'sledrun') {
24 if (feature.attributes.condition === undefined) feature.attributes.condition = 0;
25 features_sledrun.push(feature);
26 } else features_point.push(feature);
27 } else features_path.push(feature);
33 var layer_map = new OpenLayers.Layer.Google("Google Physical", {
34 type: google.maps.MapTypeId.TERRAIN
37 // // Alternative: OSM map
38 // var layer_map = new OpenLayers.Layer.OSM();
40 // // Alternative: Microsoft Bing Maps
41 // var layer_map = new OpenLayers.Layer.Bing({
43 // key: "AgPH3SlIXAwajrJKf0FORQyhTqsP8KIlvtN6RKfvxe6fOB6q6-HFmg8EOFm7LSOA"});
48 var layer_path = new OpenLayers.Layer.Vector("Path", {
49 styleMap: new OpenLayers.StyleMap(new OpenLayers.Style({
50 strokeColor: '${getStrokeColor}',
51 strokeWidth: '${getStrokeWidth}'
54 getStrokeColor: function(feature) {
55 if (feature.attributes.strokeColor !== undefined) return feature.attributes.strokeColor;
56 if (feature.attributes.type == 'sledrun') return '#014e9a';
57 if (feature.attributes.type == 'walk') return '#e98401';
58 if (feature.attributes.type == 'alternative') return '#7f7fff';
59 if (feature.attributes.type == 'lift') return '#000000';
62 getStrokeWidth: function(feature) {
63 if (feature.attributes.strokeWidth !== undefined) return feature.attributes.strokeWidth;
64 if (feature.attributes.type == 'lift') return 3;
74 var layer_point = new OpenLayers.Layer.Vector("Point", {
75 rendererOptions: {yOrdering: true}
81 var layer_sledrun = new OpenLayers.Layer.Vector("Sledrun", {
82 styleMap: new OpenLayers.StyleMap({
83 "default": new OpenLayers.Style({
84 externalGraphic: "/vorlagen/bahnzustand${condition}_0.png",
90 backgroundGraphic: "/vorlagen/gmap_rodelbahn_c_s.png",
93 backgroundXOffset: -8,
94 backgroundYOffset: -8,
95 backgroundGraphicZIndex: 11,
98 "highlight": new OpenLayers.Style({
100 labelOutlineColor: "white",
105 rendererOptions: {yOrdering: true}
110 var lon = parseFloat(jq_map.attr('data-center-lon'));
111 var lat = parseFloat(jq_map.attr('data-center-lat'));
112 var zoom = parseInt(jq_map.attr('data-zoom'));
113 var map = new OpenLayers.Map(jq_map.context, {
114 projection: EPSG3857,
115 displayProjection: EPSG4326,
118 layers: [layer_map, layer_path, layer_point, layer_sledrun],
119 center: new OpenLayers.LonLat(lon, lat).transform(EPSG4326, EPSG3857),
125 // if this would be done before the layer is added to the map, the features are not added
126 layer_path.addFeatures(features_path);
127 layer_point.addFeatures(features_point);
128 layer_sledrun.addFeatures(features_sledrun);
130 // disable mouse wheel zoom
131 var navigation_control = map.getControlsByClass('OpenLayers.Control.Navigation')[0];
132 navigation_control.disableZoomWheel();
135 map.addControl(new OpenLayers.Control.LayerSwitcher());
137 // print sledrun name when mouse moves over it
138 map.addControl(new OpenLayers.Control.SelectFeature(layer_sledrun, {
142 renderIntent: "highlight"
145 // show popup when user clicks on a sledrun icon
146 map.addControl(new OpenLayers.Control.SelectFeature(layer_sledrun, {
149 onSelect: function(feature) {
151 var popup_text = "<h2>" + feature.attributes.name + '</h2>\n' +
153 '<li><a href="' + feature.attributes.wiki + '">Details zur Rodelbahn</a></li>\n' +
154 '<li>Rodelbahnzustand<br/>';
155 if (feature.attributes.date_report !== undefined) {
156 var condition_text = {1: 'Sehr gut', 2: 'Gut', 3: 'Mittelmäßig', 4: 'Schlecht', 5: 'Geht nicht'};
157 var year_month_day = feature.attributes.date_report.split('-');
158 popup_text += '<a href="' + feature.attributes.wiki + '#Eintr.C3.A4ge">' + condition_text[feature.attributes.condition] + '</a> ' +
159 '<small>' + year_month_day[2] + '.' + year_month_day[1] + '.</small> ' +
160 '<em><a href="' + feature.attributes.wiki + '#Eintragen">Neu</a></em>';
162 popup_text += '<em><a href="' + feature.attributes.wiki + '#Eintragen">Bitte eintragen</a></em>';
164 popup_text += '</li>\n</ul>\n';
165 var selectFeatureControl = this;
166 var popup = new OpenLayers.Popup.FramedCloud('sledruninfopopup_' + feature.attributes.wiki,
167 feature.geometry.getBounds().getCenterLonLat(),
170 null, true, function(event) {
172 selectFeatureControl.unselectAll();
174 feature.popup = popup;
177 onUnselect: function(feature) {
179 map.removePopup(feature.popup);
180 feature.popup.destroy();
181 feature.popup = null;
187 function init_wrmaps() {
188 var jq_maps = $('.wrmap'); // all wrmap <div> elements
189 jq_maps.each(init_wrmap);
193 $(document).ready(init_wrmaps);