]> ToastFreeware Gitweb - philipp/winterrodeln/mediawiki_extensions/wrmap.git/blobdiff - wrmap.js
The color format is checked now.
[philipp/winterrodeln/mediawiki_extensions/wrmap.git] / wrmap.js
index 2850541a00354ce92a8d81caefee89c3a70d2858..76c69da2057bebe7a227c1170641c82aaa2c9cb7 100644 (file)
--- a/wrmap.js
+++ b/wrmap.js
@@ -11,9 +11,10 @@ function init_wrmap(i, jq_map) {
        // extract, tranform and split features to layers
        var EPSG4326 = new OpenLayers.Projection("EPSG:4326"); // lon/lat 
        var EPSG3857 = new OpenLayers.Projection("EPSG:3857"); // google
-       var POINT_NAME = {'sledrun': 'Rodelbahn', 'inn': 'Gasthaus', 'busstop': 'Haltestelle', 'carpark': 'Parkplatz', 'attention': 'Achtung', 'point': 'Punkt'};
-       var format_json = new OpenLayers.Format.GeoJSON();
-       var features_all = format_json.read(json_string);
+       var format_json = new OpenLayers.Format.JSON();
+       var json_js = format_json.read(json_string);
+       var format_geojson = new OpenLayers.Format.GeoJSON();
+       var features_all = format_geojson.read(json_js);
        var features_path = new Array();
        var features_point = new Array();
        for (var i = 0; i != features_all.length; ++i) {
@@ -37,6 +38,10 @@ function init_wrmap(i, jq_map) {
        // var layer_map = new OpenLayers.Layer.Bing({
        //     type: "Road",
        //     key: "AgPH3SlIXAwajrJKf0FORQyhTqsP8KIlvtN6RKfvxe6fOB6q6-HFmg8EOFm7LSOA"});
+       
+       // // Alternative: Dummy base layer
+       // var layer_map = new OpenLayers.Layer.Vector("Base Layer", {
+       //     isBaseLayer: true});
 
        
        // path layer
@@ -49,15 +54,16 @@ function init_wrmap(i, jq_map) {
                                context: {
                                        getStrokeColor: function(feature) {
                                                if (feature.attributes.strokeColor !== undefined) return feature.attributes.strokeColor;
-                                               if (feature.attributes.type == 'sledrun') return '#014e9a';
-                                               if (feature.attributes.type == 'walk') return '#e98401';
+                                               if (feature.attributes.type == 'rodelbahn') return '#014e9a';
+                                               if (feature.attributes.type == 'gehweg') return '#e98401';
                                                if (feature.attributes.type == 'alternative') return '#7f7fff';
                                                if (feature.attributes.type == 'lift') return '#000000';
+                                               if (feature.attributes.type == 'anfahrt') return '#e1e100';
                                                return '#ee9900';
                                        },
                                        getStrokeWidth: function(feature) {
                                                if (feature.attributes.strokeWidth !== undefined) return feature.attributes.strokeWidth;
-                                               if (feature.attributes.type == 'lift') return 3;
+                                               if (feature.attributes.type == 'lift' || feature.attributes.type == 'anfahrt') return 3;
                                                return 6;
                                        }
                                }
@@ -87,8 +93,7 @@ function init_wrmap(i, jq_map) {
                                                        return feature.condition;
                                                },
                                                getSymbol: function(feature) {
-                                                       var name = POINT_NAME[feature.attributes.type];
-                                                       if (feature.attributes.type == 'point' || name === undefined) return '';
+                                                       var name = feature.attributes.type;
                                                        return name;
                                                }
                                        },
@@ -111,7 +116,7 @@ function init_wrmap(i, jq_map) {
                                                new OpenLayers.Rule({
                                                        elseFilter: true,
                                                        symbolizer: {
-                                                               externalGraphic: '/vorlagen/gmap${getSymbol}.png',
+                                                               externalGraphic: '/vorlagen/gmap_${getSymbol}.png',
                                                                graphicWidth: 20,
                                                                graphicHeight: 34,
                                                                graphicXOffset: -10,
@@ -129,7 +134,8 @@ function init_wrmap(i, jq_map) {
                                                getTitle: function(feature) {
                                                        var title = '';
                                                        if (feature.attributes.type != 'point') {
-                                                               title = POINT_NAME[feature.attributes.type];
+                                                               title = feature.attributes.type;
+                                                               title = title.charAt(0).toUpperCase() + title.slice(1); // First letter uppercase
                                                                if (feature.attributes.name !== undefined) title += ': ';
                                                        }
                                                        if (feature.attributes.name !== undefined) title += feature.attributes.name;
@@ -159,9 +165,10 @@ function init_wrmap(i, jq_map) {
 
        // map itself
        // ----------
-       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 lon = json_js.properties.lon;
+       var lat = json_js.properties.lat;
+       var zoom = json_js.properties.zoom;
+       if (zoom === undefined) zoom = 10; // default zoom
        var map = new OpenLayers.Map(jq_map.context, {
                projection: EPSG3857,
                displayProjection: EPSG4326,