function init_wrmap(i, jq_map) {
jq_map = $(jq_map);
+ var jq_map_script = jq_map.children();
OpenLayers.ImgPath = jq_map.attr('data-img-path'); // e.g. "/mediawiki/extensions/wrmap/openlayers/img/"
- var jq_sledruns = jq_map.children();
- jq_sledruns.detach();
+ var json_string = jq_map_script.text();
+ jq_map_script.detach();
+
// Introduce EPSG:3857 as an alias of the built in EPSG:900913 projection (both are the "Google/OSM" projections)
var EPSG4326 = new OpenLayers.Projection("EPSG:4326"); // lon/lat
- var EPSG3857 = new OpenLayers.Projection("EPSG:3857"); // google
+ var EPSG3857 = new OpenLayers.Projection("EPSG:900913"); // google
- // Create the map
- var map = new OpenLayers.Map(jq_map.context, {
- projection: EPSG3857,
- displayProjection: EPSG4326,
- units: "m",
- theme: null
- });
// Google Layer
var layer_map = new OpenLayers.Layer.Google("Google Physical", {
// var layer_map = new OpenLayers.Layer.Bing({
// type: "Road",
// key: "AgPH3SlIXAwajrJKf0FORQyhTqsP8KIlvtN6RKfvxe6fOB6q6-HFmg8EOFm7LSOA"});
+
- // Sledrun layer
- var layer_sledruns = new OpenLayers.Layer.Vector("Rodelbahnen", {
+ // GeoJSON
+ var layer_json = new OpenLayers.Layer.Vector("Overlay", {
+ });
+ /*
+ var layer_json = new OpenLayers.Layer.Vector("Overlay", {
styleMap: new OpenLayers.StyleMap({
"default": new OpenLayers.Style({
externalGraphic: "/vorlagen/bahnzustand${condition}_0.png",
labelOutlineColor: "white",
labelYOffset: 12,
fontWeight: "bold"
- })
+ })
}),
rendererOptions: {yOrdering: true}
});
+ */
+
+ // Sledrun layer
+ /*
jq_sledruns.each(function(j, jq_sledrun) {
jq_sledrun = $(jq_sledrun);
var lon = parseFloat(jq_sledrun.attr('data-lon'));
condition: jq_sledrun.attr('data-condition') === undefined ? '0' : jq_sledrun.attr('data-condition')
})]);
});
+ */
+
+ // Create the map
+ var lon = parseFloat(jq_map.attr('data-center-lon'));
+ var lat = parseFloat(jq_map.attr('data-center-lat'));
+ var zoom = parseInt(jq_map.attr('data-zoom'));
+ var map = new OpenLayers.Map(jq_map.context, {
+ projection: EPSG3857,
+ displayProjection: EPSG4326,
+ units: "m",
+ theme: null,
+ layers: [layer_map, layer_json],
+ center: new OpenLayers.LonLat(lon, lat).transform(EPSG4326, EPSG3857),
+ zoom: zoom
+ });
+
+
+ // tranform feature coordinates and add features
+ var format_json = new OpenLayers.Format.GeoJSON();
+ var feature_collection = format_json.read(json_string);
+ for (var i=0, len=feature_collection.length; i!=len; ++i) {
+ feature_collection[i].geometry.transform(EPSG4326, EPSG3857);
+ }
+ layer_json.addFeatures(feature_collection); // if this would be done before the layer is added to the map, the features are not added
// disable mouse wheel zoom
var navigation_control = map.getControlsByClass('OpenLayers.Control.Navigation')[0];
navigation_control.disableZoomWheel();
// print sledrun name when mouse moves over it
- map.addControl(new OpenLayers.Control.SelectFeature(layer_sledruns, {
+ /*
+ map.addControl(new OpenLayers.Control.SelectFeature(layer_json, {
hover: true,
highlightOnly: true,
autoActivate: true,
renderIntent: "highlight"
}));
+ */
// show popup when user clicks on a sledrun icon
- map.addControl(new OpenLayers.Control.SelectFeature(layer_sledruns, {
+ /*
+ map.addControl(new OpenLayers.Control.SelectFeature(layer_json, {
autoActivate: true,
toggle: true,
onSelect: function(feature) {
feature.popup = null;
}
}));
+ */
- // Center map
- map.addLayers([layer_map, layer_sledruns]);
- var lon = parseFloat(jq_map.attr('data-center-lon'));
- var lat = parseFloat(jq_map.attr('data-center-lat'));
- var zoom = parseInt(jq_map.attr('data-zoom'));
- map.setCenter(new OpenLayers.LonLat(lon, lat).transform(EPSG4326, map.getProjectionObject()), zoom);
-
}