A very basic functionality is back after the restructuring.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Thu, 8 Aug 2013 16:28:27 +0000 (16:28 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Thu, 8 Aug 2013 16:28:27 +0000 (16:28 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/mediawiki_extensions/wrmap/trunk@1498 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrmap.js

index 7d279523a832114dbb0baa9110f6d20d0c94fd7b..701780efcd5c2040a8e9a2f0f4eaaa6fc1db4081 100644 (file)
--- a/wrmap.js
+++ b/wrmap.js
@@ -2,21 +2,16 @@
 
 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", {
@@ -30,9 +25,13 @@ function init_wrmap(i, jq_map) {
        // 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",
@@ -54,10 +53,14 @@ function init_wrmap(i, jq_map) {
                                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'));
@@ -71,21 +74,48 @@ function init_wrmap(i, jq_map) {
                        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) {
@@ -123,15 +153,9 @@ function init_wrmap(i, jq_map) {
                        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);
-
 }