1 function init_wrmap(i, jq_map) {
3 var jq_sledruns = jq_map.children();
6 // Introduce EPSG:3857 as an alias of the built in EPSG:900913 projection (both are the "Google/OSM" projections)
7 var EPSG4326 = new OpenLayers.Projection("EPSG:4326"); // lon/lat
8 var EPSG3857 = new OpenLayers.Projection("EPSG:3857"); // google
11 var map = new OpenLayers.Map(jq_map.context, {
13 displayProjection: EPSG4326,
19 var layer_map = new OpenLayers.Layer.Google("Google Physical", {
20 type: google.maps.MapTypeId.TERRAIN
23 // // Alternative: OSM map
24 // var layer_map = new OpenLayers.Layer.OSM();
26 // // Alternative: Microsoft Bing Maps
27 // var layer_map = new OpenLayers.Layer.Bing({
29 // key: "AgPH3SlIXAwajrJKf0FORQyhTqsP8KIlvtN6RKfvxe6fOB6q6-HFmg8EOFm7LSOA"});
32 var layer_sledruns = new OpenLayers.Layer.Vector("Rodelbahnen", {
33 styleMap: new OpenLayers.StyleMap({
34 "default": new OpenLayers.Style({
35 externalGraphic: "/vorlagen/gmap_rodelbahn_c.png",
41 backgroundGraphic: "/vorlagen/gmap_rodelbahn_c_s.png",
44 backgroundXOffset: -8,
45 backgroundYOffset: -8,
49 "highlight": new OpenLayers.Style({
51 labelOutlineColor: "white",
56 rendererOptions: {yOrdering: true}
58 jq_sledruns.each(function(j, jq_sledrun) {
59 jq_sledrun = $(jq_sledrun);
60 var lon = parseFloat(jq_sledrun.attr('data-lon'));
61 var lat = parseFloat(jq_sledrun.attr('data-lat'));
62 var point = new OpenLayers.Geometry.Point(lon, lat).transform(EPSG4326, EPSG3857);
63 layer_sledruns.addFeatures([new OpenLayers.Feature.Vector(point, {
64 label: jq_sledrun.attr('data-title'),
65 url: jq_sledrun.attr('data-url')
68 map.addControl(new OpenLayers.Control.SelectFeature(layer_sledruns, {
72 renderIntent: "highlight"
74 map.addControl(new OpenLayers.Control.SelectFeature(layer_sledruns, {
77 onSelect: function(feature) {
79 var selectFeatureControl = this;
80 var popup = new OpenLayers.Popup.FramedCloud("sledruninfopopup_" + feature.attributes['label'],
81 feature.geometry.getBounds().getCenterLonLat(),
83 "<h2>" + feature.attributes['label'] + "</h2>\n" +
85 "<li><a href=\"" + feature.attributes['url'] + "\">Details</a></li>\n" +
87 null, true, function(event) {
89 selectFeatureControl.unselectAll();
91 feature.popup = popup;
94 onUnselect: function(feature) {
96 map.removePopup(feature.popup);
97 feature.popup.destroy();
104 map.addLayers([layer_map, layer_sledruns]);
105 var lon = parseFloat(jq_map.attr('data-center-lon'));
106 var lat = parseFloat(jq_map.attr('data-center-lat'));
107 var zoom = parseInt(jq_map.attr('data-zoom'));
108 map.setCenter(new OpenLayers.LonLat(lon, lat).transform(EPSG4326, map.getProjectionObject()), zoom);
113 function init_wrmaps() {
114 var jq_maps = $('.wrmap'); // all wrmap <div> elements
115 jq_maps.each(init_wrmap);
119 $(document).ready(init_wrmaps);