src/services/olHelpers.js
function recursiveStyle(data, styleName) {
        var style;
        if (!styleName) {
            styleName = 'style';
            style = data;
        } else {
            style = data[styleName];
        }
        //Instead of defining one style for the layer, we've been given a style function
        //to apply to each feature.
        if (styleName === 'style' && data instanceof Function) {
            return data;
        }

        if (!(style instanceof Object)) {
            return style;
        }

        var styleObject;
        if (Object.prototype.toString.call(style) === '[object Object]') {
            styleObject = {};
            var styleConstructor = styleMap[styleName];
            if (styleConstructor && style instanceof styleConstructor) {
                return style;
            }
            Object.getOwnPropertyNames(style).forEach(function(val, idx, array) {
                //Consider the case
                //image: {
                //  circle: {
                //     fill: {
                //       color: 'red'
                //     }
                //   }
                //
                //An ol.style.Circle is an instance of ol.style.Image, so we do not want to construct
                //an Image and then construct a Circle.  We assume that if we have an instanceof
                //relationship, that the JSON parent has exactly one child.
                //We check to see if an inheritance relationship exists.
                //If it does, then for the parent we create an instance of the child.
                var valConstructor = styleMap[val];
                if (styleConstructor && valConstructor &&
                   valConstructor.prototype instanceof styleMap[styleName]) {
                    console.assert(array.length === 1, 'Extra parameters for ' + styleName);
                    styleObject = recursiveStyle(style, val);
                    return optionalFactory(styleObject, valConstructor);
                } else {
                    styleObject[val] = recursiveStyle(style, val);

                    // if the value is 'text' and it contains a String, then it should be interpreted
                    // as such, 'cause the text style might effectively contain a text to display
                    if (val !== 'text' && typeof styleObject[val] !== 'string') {
                        styleObject[val] = optionalFactory(styleObject[val], styleMap[val]);
                    }
                }
            });
        } else {
            styleObject = style;
        }
        return optionalFactory(styleObject, styleMap[styleName]);
    }
function recursiveStyle(data, styleName) {
        var style;
        if (!styleName) {
            styleName = 'style';
            style = data;
        } else {
            style = data[styleName];
        }
        //Instead of defining one style for the layer, we've been given a style function
        //to apply to each feature.
        if (styleName === 'style' && data instanceof Function) {
            return data;
        }

        if (!(style instanceof Object)) {
            return style;
        }

        var styleObject;
        if (Object.prototype.toString.call(style) === '[object Object]') {
            styleObject = {};
            var styleConstructor = styleMap[styleName];
            if (styleConstructor && style instanceof styleConstructor) {
                return style;
            }
            Object.getOwnPropertyNames(style).forEach(function(val, idx, array) {
                //Consider the case
                //image: {
                //  circle: {
                //     fill: {
                //       color: 'red'
                //     }
                //   }
                //
                //An ol.style.Circle is an instance of ol.style.Image, so we do not want to construct
                //an Image and then construct a Circle.  We assume that if we have an instanceof
                //relationship, that the JSON parent has exactly one child.
                //We check to see if an inheritance relationship exists.
                //If it does, then for the parent we create an instance of the child.
                var valConstructor = styleMap[val];
                if (styleConstructor && valConstructor &&
                   valConstructor.prototype instanceof styleMap[styleName]) {
                    console.assert(array.length === 1, 'Extra parameters for ' + styleName);
                    styleObject = recursiveStyle(style, val);
                    return optionalFactory(styleObject, valConstructor);
                } else {
                    styleObject[val] = recursiveStyle(style, val);

                    // if the value is 'text' and it contains a String, then it should be interpreted
                    // as such, 'cause the text style might effectively contain a text to display
                    if (val !== 'text' && typeof styleObject[val] !== 'string') {
                        styleObject[val] = optionalFactory(styleObject[val], styleMap[val]);
                    }
                }
            });
        } else {
            styleObject = style;
        }
        return optionalFactory(styleObject, styleMap[styleName]);
    }
function recursiveStyle ( data , styleName ) { var style ; if ( ! styleName ) { styleName = 'style' ; style = data ; } else { style = data [ styleName ] ; } //Instead of defining one style for the layer, we've been given a style function //to apply to each feature. if ( styleName === 'style' && data instanceof Function ) { return data ; } if ( ! ( style instanceof Object ) ) { return style ; } var styleObject ; if ( Object . prototype . toString . call ( style ) === '[object Object]' ) { styleObject = { } ; var styleConstructor = styleMap [ styleName ] ; if ( styleConstructor && style instanceof styleConstructor ) { return style ; } Object . getOwnPropertyNames ( style ) . forEach ( function ( val , idx , array ) { //Consider the case //image: { //  circle: { //     fill: { //       color: 'red' //     } //   } // //An ol.style.Circle is an instance of ol.style.Image, so we do not want to construct //an Image and then construct a Circle.  We assume that if we have an instanceof //relationship, that the JSON parent has exactly one child. //We check to see if an inheritance relationship exists. //If it does, then for the parent we create an instance of the child. var valConstructor = styleMap [ val ] ; if ( styleConstructor && valConstructor && valConstructor . prototype instanceof styleMap [ styleName ] ) { console . assert ( array . length === 1 , 'Extra parameters for ' + styleName ) ; styleObject = recursiveStyle ( style , val ) ; return optionalFactory ( styleObject , valConstructor ) ; } else { styleObject [ val ] = recursiveStyle ( style , val ) ; // if the value is 'text' and it contains a String, then it should be interpreted // as such, 'cause the text style might effectively contain a text to display if ( val !== 'text' && typeof styleObject [ val ] !== 'string' ) { styleObject [ val ] = optionalFactory ( styleObject [ val ] , styleMap [ val ] ) ; } } } ) ; } else { styleObject = style ; } return optionalFactory ( styleObject , styleMap [ styleName ] ) ; }
Parse the style tree calling the appropriate constructors. The keys in styleMap can be used and the OpenLayers constructors can be used directly.
Parse the style tree calling the appropriate constructors . The keys in styleMap can be used and the OpenLayers constructors can be used directly .