Street Labels

Render street names with a custom render.

Example showing the use of a text style with placement: 'line' to render text along a path.

<!DOCTYPE html>
<html>
  <head>
    <title>Street Labels</title>
    <link rel="stylesheet" href="https://openlayers.org/en/v4.6.4/css/ol.css" type="text/css">
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src=""></script>
    <script src="https://openlayers.org/en/v4.6.4/build/ol.js"></script>
  </head>
  <body>
    <div id="map" class="map"></div>
    <script>
      var style = new ol.style.Style({
        text: new ol.style.Text({
          font: 'bold 11px "Open Sans", "Arial Unicode MS", "sans-serif"',
          placement: 'line',
          fill: new ol.style.Fill({
            color: 'white'
          })
        })
      });

      var viewExtent = [1817379, 6139595, 1827851, 6143616];
      var map = new ol.Map({
        layers: [new ol.layer.Tile({
          source: new ol.source.BingMaps({
            key: 'Your Bing Maps Key from http://www.bingmapsportal.com/ here',
            imagerySet: 'Aerial'
          })
        }), new ol.layer.Vector({
          declutter: true,
          source: new ol.source.Vector({
            format: new ol.format.GeoJSON(),
            url: 'https://openlayers.org/en/v4.6.4/examples/data/geojson/vienna-streets.geojson'
          }),
          style: function(feature) {
            style.getText().setText(feature.get('name'));
            return style;
          }
        })],
        target: 'map',
        view: new ol.View({
          extent: viewExtent,
          center: ol.extent.getCenter(viewExtent),
          zoom: 17,
          minZoom: 14
        })
      });
    </script>
  </body>
</html>