Add basic style functions.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Mon, 28 May 2018 19:41:48 +0000 (21:41 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Mon, 28 May 2018 19:42:06 +0000 (21:42 +0200)
wrmap.js

index d6d985f..8855429 100644 (file)
--- a/wrmap.js
+++ b/wrmap.js
@@ -91,6 +91,40 @@ function init_wrmap(i, jq_map) {
        
        // path layer
        // ----------
+       function style_point_function(feature, resolution) {
+               var src = img_path + '/marker_p_' + feature.get('type') + '.png';
+               return new ol.style.Style({
+                       image: new ol.style.Icon({
+                               src: src,
+                               imgSize: [20, 34],
+                               anchor: [0.5, 1.0]
+                       })
+               });
+       }
+
+       function style_path_function(feature, resolution) {
+               var line_color = {
+                       'rodelbahn': '#014e9a',
+                       'gehweg': '#e98401',
+                       'alternative': '#7f7fff',
+                       'lift': '#000000',
+                       'anfahrt': '#e1e100'
+               };
+               var color = feature.get('strokeColor') || line_color[feature.get('type')] || '#e7525b';
+               var width = (feature.get('type') in ['lift', 'anfahrt']) ? 3 : 6;
+               return new ol.style.Style({
+                       stroke: new ol.style.Stroke({
+                               color: color,
+                               width: width
+                       })
+               });
+       }
+
+       function style_function(feature, resolution) {
+               if (feature.getGeometry() instanceof ol.geom.Point) return style_point_function(feature, resolution);
+               return style_path_function(feature, resolution);
+       };
+
        var layer_path = new OpenLayers.Layer.Vector("Path", {
                styleMap: new OpenLayers.StyleMap(new OpenLayers.Style({
                                strokeColor: '${getStrokeColor}',
@@ -261,8 +295,8 @@ function init_wrmap(i, jq_map) {
 
        var layer_sledrun_source = new ol.source.Vector({features: features_all});
        var layer_sledrun = new ol.layer.Vector({
-               source: layer_sledrun_source
-               // style: styleFunction
+               source: layer_sledrun_source,
+               style: style_function
        });
 
        var map = new ol.Map({