Drawing lines and polygons with WebGL

In the previous example, we stated that OpenLayers 3 cannot render lines and polygons with the WebGL renderer. However, there is a workaround, which we will use in this example, called ch07_webgl_vector.

Let's add the country boundaries layer with a little twist to our map:

var map = new ol.Map({
    […]
        new ol.layer.Image({
            source: new ol.source.ImageVector({
                source: new ol.source.Vector({
                    format: new ol.format.GeoJSON({
                        defaultDataProjection: 'EPSG:4326'
                    }),
                    url: '../../res/world_countries.geojson',
                    attributions: [
                        new ol.Attribution({
                            html: 'World Countries © Natural Earth'
                        })
                    ]
                })
            }),
            name: 'World Countries'
        })
    ],
[…]

As you can see, we converted our vector layer to an image layer. The ol.source.ImageVector

Get Mastering OpenLayers 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.