Set cartodb initial map state from input
This commit is contained in:
@@ -10,17 +10,28 @@ const mapConfig = {
|
|||||||
'options': {
|
'options': {
|
||||||
'cartocss_version': '2.1.1',
|
'cartocss_version': '2.1.1',
|
||||||
'cartocss': '#layer { polygon-fill: #F00; }',
|
'cartocss': '#layer { polygon-fill: #F00; }',
|
||||||
'sql': 'select * from european_countries_e where area > 0',
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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({
|
const cartoDBSource = new CartoDB({
|
||||||
account: 'documentation',
|
account: 'documentation',
|
||||||
config: mapConfig,
|
config: mapConfig,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
areaSelect.addEventListener('change', function () {
|
||||||
|
setArea(this.value);
|
||||||
|
cartoDBSource.setConfig(mapConfig);
|
||||||
|
});
|
||||||
|
|
||||||
const map = new Map({
|
const map = new Map({
|
||||||
layers: [
|
layers: [
|
||||||
new TileLayer({
|
new TileLayer({
|
||||||
@@ -32,17 +43,7 @@ const map = new Map({
|
|||||||
],
|
],
|
||||||
target: 'map',
|
target: 'map',
|
||||||
view: new View({
|
view: new View({
|
||||||
center: [0, 0],
|
center: [8500000, 8500000],
|
||||||
zoom: 2,
|
zoom: 2,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
function setArea(n) {
|
|
||||||
mapConfig.layers[0].options.sql =
|
|
||||||
'select * from european_countries_e where area > ' + n;
|
|
||||||
cartoDBSource.setConfig(mapConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('country-area').addEventListener('change', function () {
|
|
||||||
setArea(this.value);
|
|
||||||
});
|
|
||||||
|
|||||||
Reference in New Issue
Block a user