// Caso de pruebas
// 1. Cargar capa de municipios
// 2. Se aplica coropletas - incluido campo porcentaje que se añade a la capa y se generan campos aleatorios
// 3. Pulsar Aplicar Proporcional - aplica proporcional respetando la simbología anterior
let mapajs = M.map({
'container': 'map',
"controls": ["layerswitcher"],
"layer": ["OSM"]
});
let layer = new M.layer.WFS({
name: "Municipios",
url: "https://clientes.guadaltel.es/desarrollo/geossigc/wfs?",
namespace: "mapea",
name: "da_municipio_pol",
legend: "Municipios - COROPLETAS",
geometry: 'POLYGON',
});;
mapajs.addLayers(layer);
mapajs.addPlugin(new M.plugin.AttributeTable());
/**
* attribute: Parametro por el cual se calcula la proporcion en los features
* maxRadius: Parametro que define el radio maximo de la proporcion
* minRadius: Parametro que define el radio minimo de la proporcion
*/
let options = {
attribute: "area",
maxRadius: 25,
minRadius: 8
};
let choropleth = new M.style.Choropleth("porcentaje", ['#0edfd0', '#ee440d'], () => [50, 80, 100]);
layer.on(M.evt.LOAD, function() {
// Crea sobre la capa una atributo de porcentaje aleatorio para aplicar clasificación inicial sobre este.
layer.getFeatures().forEach(f => f.setAttribute('porcentaje', Math.round(Math.random() * 100)));
// Aplica estilo coropleta
layer.setStyle(choropleth);
});
function aplicarProporcional(){
// Aplica proporcional - En este caso se va a preservar el estilo anterior pero se aplican los atributos proporcionales para representación
layer.setStyle( new M.style.Proportional(options.attribute, options.minRadius, options.maxRadius));
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.