When we work with vector sources, we basically have to deal with two types of data: geometry and attributes. The geometry part is responsible for storing the position of our shapes in one of the projections. We make spatial (topological) analysis with the geometries of our data.
Attribute data is responsible for storing the related information for every feature. It is also used for various analysis. Furthermore, it is utterly important when it comes to querying or styling. These are considered as basic or core capabilities in GIS software, although modern web mapping libraries tend to lack in effective attribute management. This is the reason why we will mainly focus on attribute data.
In this chapter, we will cover the following topics:
As we will mainly focus on attribute management in this chapter, we will need a vector layer with lots of attributes. I have prepared such a layer to work with. It can be located in the res folder of the code annex, and its name is world_countries.geojson. Before we make some progress, let's change our default vector layer from the capitals of the world to this one:
var map = new ol.Map({
[…]
new ol.layer.Vector({
source: new ol.source.Vector({
format: new ol.format.GeoJSON({
defaultDataProjection: 'EPSG:4326'
}),
url: '../../res/world_countries.geojson',
}),
name: 'World Countries'
})
],
[…]
});