CP-070-03
StylePolygon (A nivel de capa y features)
by SIGC
HTML
<script src="https://sigc.desarrollo.guadaltel.es/mapea5/js/mapea.ol.min.js"></script>
<link rel="stylesheet" href="https://sigc.desarrollo.guadaltel.es/mapea5/assets/css/mapea.ol.min.css">
<script src="https://sigc.desarrollo.guadaltel.es/mapea5/js/configuration.js"></script>
<div>
<p>Estilos a nivel de capa:</p>
<div>
<button onclick="setStyleNull()">style null</button>
<button onclick="setStyleVacio()">style vacio</button>
<button onclick="setStyleLayer(polygons, nullStylePolygon)">style polygon sin parametros</button>
<button onclick="setStyleLayer(polygons, colorStylePolygon)">style polygon solo fill: color</button>
<button onclick="setStyleLayer(polygons, strokeStylePolygon)">style polygon solo stroke: color</button>
<br>
<button onclick="setStyleLayer(polygons, stylePolygon)">Estilo poligono ejemplo 1</button>
<button onclick="setStyleLayer(polygons, stylePolygon2)">Estilo poligono ejemplo 2</button>
<button onclick="setStyleLayer(polygons, stylePolygon3)">Estilo poligono ejemplo 3</button>
<button onclick="setStyleLayer(polygons, stylePolygon4)">Estilo poligono ejemplo 4</button>
<button onclick="setStyleLayer(polygons, stylePolygon5)">Estilo poligono ejemplo 5</button>
</div>
<p> Estilos a nivel de feature:</p>
<div>
<button onclick="setStyleLayer(polygon, nullStylePolygon)">style polygon sin parametros</button>
<button onclick="setStyleLayer(polygon, colorStylePolygon)">style polygon solo fill: color</button>
<button onclick="setStyleLayer(polygon, strokeStylePolygon)">style polygon solo stroke: color</button>
<br>
<button onclick="setStyleLayer(polygon, stylePolygon)">Estilo poligono ejemplo 1</button>
<button onclick="setStyleLayer(polygon, stylePolygon2)">Estilo poligono ejemplo 2</button>
<button onclick="setStyleLayer(polygon, stylePolygon3)">Estilo poligono ejemplo 3</button>
<button onclick="setStyleLayer(polygon, stylePolygon4)">Estilo poligono ejemplo 4</button>
...
CSS
<style rel="stylesheet">
html,
body {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
}
JavaScript
// CP-070-03 - StylePolygon (A nivel de capa y features)
// Caso de prueba orientado a verificar la aplicación de estilos a nivel de capa y a nivel de features.
// constructor del mapa
let mapajs = M.map({
container: "map",
projection: "EPSG:4326*d",
layers: ["OSM"],
center: {
x: -5.9584180843195425,
y: 37.36912689160224
},
zoom: 5,
controls: ['layerswitcher', 'overviewmap'],
});
let polygons = new M.layer.WFS({
name: "Municipios",
url: "https://clientes.guadaltel.es/desarrollo/geossigc/wfs?",
namespace: "mapea",
name: "da_municipio_pol",
legend: "Municipios - Plantilla Símbolo",
getfeatureinfo:"plain",
geometry: 'POLYGON',
extract: true,
});
mapajs.addLayers([polygons]);
let polygon = null;
//Seleccionamos un polígono que esté en el centro de Andalucía para localizarlo mejor (SANTAELLA)
polygons.on(M.evt.LOAD, function() {
polygon = M.filter.EQUAL("cod_ine_municipio","14060").execute(polygons.getFeatures())[0];
})
// Set estilo null
function setStyleNull() {
polygons.setStyle( null );
}
function setStyleVacio() {
polygons.setStyle( );
}
// Estilos vacíos (no se visualizarán)
let nullStylePolygon = new M.style.Polygon();
// Estilos solo color
let colorStylePolygon = new M.style.Polygon({
fill: {
color: 'red'
}
});
// Estilos stroke
let strokeStylePolygon = new M.style.Polygon({
stroke: {
color: 'red'
}
});
//=============================================================================
// Estilos variados de polígonos
// EJEMPLO STROKE
let stylePolygon = new M.style.Polygon({
stroke: {
color: '#C8FE2E',
width: 15,
linedash: [1, 20],
linedashoffset: 60,
linecap: 'square',
linejoin: 'miter',
miterlimit: 15
}
});
// EJEMPLO FILL
let stylePolygon2 = new M.style.Polygon({
fill: {
color: '#6A0888',
opacity: 0.5
}
});
// EJEMPLO FILL - PATTERN
let stylePolygon3 = new M.style.Polygon({
stroke: {
color: '#C8FE2E',
...