5.1. Working with Vector Layers¶
The base ol.layer.Vector constructor provides a fairly flexible layer type. By default, when you create a new vector layer, no assumptions are made about where the features for the layer will come from, since this is the domain of ol.source.Vector. Customizing the rendering style is addressed in an upcoming section. This section introduces the basics of vector data formats.
5.1.1. ol.format¶
The ol.format classes in OpenLayers 3 are responsible for parsing data from the server representing vector features. The format turns raw feature data into ol.Feature objects.
Consider the two blocks of data below. Both represent the same ol.Feature object (a point in Barcelona, Spain). The first is serialized as GeoJSON (using the ol.format.GeoJSON parser). The second is serialized as KML (using the ol.format.KML parser).
5.1.1.1. GeoJSON Example¶
{
"type": "Feature",
"id": "OpenLayers.Feature.Vector_107",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [-104.98, 39.76]
}
}
5.1.1.2. KML Example¶
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Placemark>
<Point>
<coordinates>-104.98,39.76</coordinates>
</Point>
</Placemark>
</kml>