1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| import Map from 'ol/Map.js'; import TileLayer from 'ol/layer/Tile.js'; import View from 'ol/View.js'; import {CartoDB, OSM} from 'ol/source.js';
const mapConfig = { 'layers': [ { 'type': 'cartodb', 'options': { 'cartocss_version': '2.1.1', 'cartocss': '#layer { polygon-fill: #F00; }', }, }, ], };
function setArea(n) { mapConfig.layers[0].options.sql = 'select * from european_countries_e where area > ' + n; } const areaSelect = document.getElementById('country-area'); setArea(areaSelect.value);
const cartoDBSource = new CartoDB({ account: 'documentation', config: mapConfig, });
areaSelect.addEventListener('change', function () { setArea(this.value); cartoDBSource.setConfig(mapConfig); });
const map = new Map({ layers: [ new TileLayer({ source: new OSM(), }), new TileLayer({ source: cartoDBSource, }), ], target: 'map', view: new View({ center: [8500000, 8500000], zoom: 2, }), });
|