From 4ce7f7774902f7a54c9a95089594eac480e06b25 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 7 Jan 2022 13:50:43 -0700 Subject: [PATCH] Update label decluttering example --- examples/vector-label-decluttering.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/vector-label-decluttering.js b/examples/vector-label-decluttering.js index 9048e17523..2c2b9a8991 100644 --- a/examples/vector-label-decluttering.js +++ b/examples/vector-label-decluttering.js @@ -4,12 +4,13 @@ import VectorLayer from '../src/ol/layer/Vector.js'; import VectorSource from '../src/ol/source/Vector.js'; import View from '../src/ol/View.js'; import {Fill, Stroke, Style, Text} from '../src/ol/style.js'; +import {fromLonLat} from '../src/ol/proj.js'; const map = new Map({ target: 'map', view: new View({ - center: [0, 0], - zoom: 1, + center: fromLonLat([-100, 38.5]), + zoom: 4, }), }); @@ -38,12 +39,14 @@ const countryStyle = new Style({ const style = [countryStyle, labelStyle]; const vectorLayer = new VectorLayer({ + background: 'white', source: new VectorSource({ - url: 'data/geojson/countries.geojson', + url: 'https://openlayers.org/data/vector/us-states.json', format: new GeoJSON(), }), style: function (feature) { - labelStyle.getText().setText(feature.get('name')); + const label = feature.get('name').split(' ').join('\n'); + labelStyle.getText().setText(label); return style; }, declutter: true,