Now rules are used to distinguish between sledrun icons and other information icons.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sat, 10 Aug 2013 21:40:11 +0000 (21:40 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sat, 10 Aug 2013 21:40:11 +0000 (21:40 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/mediawiki_extensions/wrmap/trunk@1508 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrmap.js

index 547b3f6cad3283e00d7b18e3e0b2c2743aa87916..2c6d472e232fba6d584cf5003657b1bf911b6c57 100644 (file)
--- a/wrmap.js
+++ b/wrmap.js
@@ -19,28 +19,8 @@ function init_wrmap(i, jq_map) {
        for (var i = 0; i != features_all.length; ++i) {
                var feature = features_all[i];
                feature.geometry.transform(EPSG4326, EPSG3857);
        for (var i = 0; i != features_all.length; ++i) {
                var feature = features_all[i];
                feature.geometry.transform(EPSG4326, EPSG3857);
-               if (feature.geometry.CLASS_NAME == 'OpenLayers.Geometry.Point') {
-                       if (feature.attributes.type == 'sledrun') {
-                               var condition = feature.attributes.condition;
-                               if (condition === undefined) condition = 0;
-                               feature.attributes.externalGraphic = 'bahnzustand' + condition + '_0.png';
-                               feature.attributes.graphicWidth = 17;
-                               feature.attributes.graphicHeight = 17;
-                               feature.attributes.graphicXOffset = -8;
-                               feature.attributes.graphicYOffset = -8;
-                       } else {
-                               var name = POINT_NAME[feature.attributes.type];
-                               if (feature.attributes.type == 'point' || name === undefined)
-                                       feature.attributes.externalGraphic = 'gmap.png';
-                               else
-                                       feature.attributes.externalGraphic = 'gmap' + name + '.png';
-                               feature.attributes.graphicWidth = 20;
-                               feature.attributes.graphicHeight = 34;
-                               feature.attributes.graphicXOffset = -10;
-                               feature.attributes.graphicYOffset = -33;
-                       }
-                       features_point.push(feature);
-               } else features_path.push(feature);
+               if (feature.geometry instanceof OpenLayers.Geometry.Point) features_point.push(feature);
+               else features_path.push(feature);
        }
 
 
        }
 
 
@@ -87,22 +67,63 @@ function init_wrmap(i, jq_map) {
        
        // point layer
        // -----------
        
        // point layer
        // -----------
+       var filter_point_sledrun = new OpenLayers.Filter.Comparison({
+               type: OpenLayers.Filter.Comparison.EQUAL_TO,
+               property: 'type',
+               value: 'sledrun'
+       });
+
        var layer_point = new OpenLayers.Layer.Vector("Point", {
                styleMap: new OpenLayers.StyleMap({
                        'default': new OpenLayers.Style({
        var layer_point = new OpenLayers.Layer.Vector("Point", {
                styleMap: new OpenLayers.StyleMap({
                        'default': new OpenLayers.Style({
-                                       externalGraphic: '/vorlagen/${externalGraphic}',
-                                       graphicWidth: '${graphicWidth}',
-                                       graphicHeight: '${graphicHeight}',
-                                       graphicXOffset: '${graphicXOffset}',
-                                       graphicYOffset: '${graphicYOffset}',
                                        graphicZIndex: 12,
                                        graphicZIndex: 12,
-                                       backgroundGraphic: "/vorlagen/gmap_rodelbahn_c_s.png",
-                                       backgroundWidth: 23,
-                                       backgroundHeight: 23,
-                                       backgroundXOffset: -8,
-                                       backgroundYOffset: -8,
                                        backgroundGraphicZIndex: 11,
                                        backgroundGraphicZIndex: 11,
-                                       title: '${getTitle}'
+                               }, {
+                                       context: {
+                                               // the following context functions should only be available in the rule that uses them,
+                                               // but the rule dependent contexts are ignored by OpenLayers (I think that's a bug)
+                                               getCondition: function(feature) {
+                                                       if (feature.condition === undefined) return 0;
+                                                       return feature.condition;
+                                               },
+                                               getSymbol: function(feature) {
+                                                       var name = POINT_NAME[feature.attributes.type];
+                                                       if (feature.attributes.type == 'point' || name === undefined) return '';
+                                                       return name;
+                                               }
+                                       },
+                                       rules: [
+                                               new OpenLayers.Rule({
+                                                       filter: filter_point_sledrun,
+                                                       symbolizer: {
+                                                               externalGraphic: '/vorlagen/bahnzustand${getCondition}_0.png',
+                                                               graphicWidth: 17,
+                                                               graphicHeight: 17,
+                                                               graphicXOffset: -8,
+                                                               graphicYOffset: -8,
+                                                               backgroundGraphic: "/vorlagen/gmap_rodelbahn_c_s.png",
+                                                               backgroundWidth: 23,
+                                                               backgroundHeight: 23,
+                                                               backgroundXOffset: -8,
+                                                               backgroundYOffset: -8,
+                                                       }
+                                               }),
+                                               new OpenLayers.Rule({
+                                                       elseFilter: true,
+                                                       symbolizer: {
+                                                               externalGraphic: '/vorlagen/gmap${getSymbol}.png',
+                                                               graphicWidth: 20,
+                                                               graphicHeight: 34,
+                                                               graphicXOffset: -10,
+                                                               graphicYOffset: -33,
+                                                       }
+                                               })
+                                       ]
+                               }),
+                       highlight: new OpenLayers.Style({
+                                       label: "${getTitle}",
+                                       labelOutlineColor: "white",
+                                       fontWeight: "bold"
                                }, {
                                        context: {
                                                getTitle: function(feature) {
                                }, {
                                        context: {
                                                getTitle: function(feature) {
@@ -114,13 +135,22 @@ function init_wrmap(i, jq_map) {
                                                        if (feature.attributes.name !== undefined) title += feature.attributes.name;
                                                        return title;
                                                }
                                                        if (feature.attributes.name !== undefined) title += feature.attributes.name;
                                                        return title;
                                                }
-                                       }
-                               }),
-                       'highlight': new OpenLayers.Style({
-                                       label: "${name}",
-                                       labelOutlineColor: "white",
-                                       labelYOffset: 12,
-                                       fontWeight: "bold"
+                                       },
+                                       rules: [
+                                               new OpenLayers.Rule({
+                                                       filter: filter_point_sledrun,
+                                                       symbolizer: {
+                                                               label: "${name}",
+                                                               labelYOffset: 14
+                                                       }
+                                               }),
+                                               new OpenLayers.Rule({
+                                                       elseFilter: true,
+                                                       symbolizer: {
+                                                               labelYOffset: 40
+                                                       }
+                                               })
+                                       ]
                                }) 
                }),
                rendererOptions: {yOrdering: true}
                                }) 
                }),
                rendererOptions: {yOrdering: true}