I encountered a similar challenge when implementing MVLayer, so if you look at that code, you can see how I dealt with it. Basically, to create a layer, you need one of the ol.layer (e.g. ol.layer.Vector, ol.layer.Image) classes and an ol.source layer (e.g. ol.source.Vector, ol.source.StaticImage) and they all vary depending on the type of layer you are doing. The MVLayer has an argument called "source" which is just the name of the source class to use. I found a way to instantiate a class from a string on the JavaScript side of things. All the constructors for open layers classes take a JavaScript objects. There is another argument of MVLayer called "options" which just takes a dictionary, which is then converted to a JavaScript object and passed into the constructor of the "source" class specified. The layer class can be derived from the type of source object selected, so that is handled automagically, though there is a "layer_options" argument to MVLayer that takes a dictionary and passes that into the layer class when it is instantiated. This does what I needed it to do for MVLayer, but it would be better if we could generalize it so that we could instantiate any open layers class, perhaps using a dictionary structure like so:
{
"ol_class": "ol.layer.Vector",
"options": { ... }
}
Then we just need to recursively parse through the structure and instantiate any objects with a "ol_class" property.