Reading features directly using Protocols
OpenLayers allows us to read data from different origins and sources. As we have described in the chapter's introduction, OpenLayers offers the helper classes: protocols and formats.
Protocols are designed to simplify the task of retrieving data from different origins: via HTTP, from an WFS server, and so on.
On the other hand, formats simplifies the task of reading from (or writing to) a given data format. It is very common to load data from different origins and know how to work directly with protocols that can incredibly simplify this task.
As an example, this recipe shows how we can add features from different data sources in the same vector layer, by working directly with the protocol instances.
How to do it...
Create an HTML file and add the OpenLayers dependencies. Then create a
DOM
element to hold the map:<!-- Map DOM element --> <div id="ch3_protocol" style="width: 100%; height: 100%;"></div>
Next, initialize the map, add some...