CP-072-02

Style Category POL

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 id="mapjs" class="container"></div>
<div id="pruebas" class="container">


<button type="button" onclick="crea()">new StyleCategory( AtributeName, JSON-Category-Style)</button>

      <P>Introduzca el nuevo AttributeName
        <INPUT type="text" name="AttributeName" id="AttributeName"> </P>

      <P>Introduzca la categoria
        <INPUT type="text" name="CategoryStyle" id="CategoryStyle"> </P>


      <P>GetStyleForCategories devolverá el estilo de una categoria (escpecificada por parametro)</P>

      <button type="button" onclick="GetStyleForCategories()">GetStyleForCategories</button>

      <P>SetStyleForCategories aplicará un estilo nuevo (por defecto se ha configurado uno internamente) a una categoria (escpecificada por parametro)</P>

      <button type="button" onclick="SetStyleForCategories()">SetStyleForCategories</button>

      <P>Devuelve el valor de AttributeName del objeto CategoryStyle</P>


      <button type="button" onclick="GetAttributeName()">GetAttributeName</button>

      <P>Cambia el valor AttributeName del objeto CategoryStyle</P>

      <button type="button" onclick="SetAttributeName()">SetAttributeName</button>




      <P>Devuelve todas las posibles valores que tiene una determinada categoria</P>

      <button type="button" onclick="GetCategories()">GetCategories</button>
    </div>

CSS

<style rel="stylesheet">
      html,
      body {
        margin: 0;
        padding: 0;
        height: 100%;
        overflow: hidden;
      }

JavaScript

var mapajs = M.map({
  'container': 'mapjs',
  "controls": ["layerswitcher", "mouse", "scale", "overviewmap", "panzoombar", "scaleline"],
});


let layer = 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([layer]);

mapajs.addPlugin(new M.plugin.AttributeTable());
mapajs.addPlugin(new M.plugin.Printer());


let rojo = new M.style.Polygon({
  fill: {
    color: 'red'
  },
  stroke: {
    color: 'black',
    width: 2
  },

});

let amarillo = new M.style.Polygon({
  fill: {
    color: 'yellow'
  },
  stroke: {
    color: 'black',
    width: 2
  },

});

let rosa = new M.style.Polygon({
  fill: {
    color: 'pink'
  },
  stroke: {
    color: 'black',
    width: 2
  },

});

let azul = new M.style.Polygon({
  fill: {
    color: 'blue'
  },
  stroke: {
    color: 'black',
    width: 2
  },

});

let verde = new M.style.Polygon({
  fill: {
    color: 'green'
  },
  stroke: {
    color: 'black',
    width: 2
  },

});

let marron = new M.style.Polygon({
  fill: {
    color: 'brown'
  },
  stroke: {
    color: 'black',
    width: 2
  },

});

let cyan = new M.style.Polygon({
  fill: {
    color: 'cyan'
  },
  stroke: {
    color: 'black',
    width: 2
  },

});

let naranja = new M.style.Polygon({
  fill: {
    color: 'orange'
  },
  stroke: {
    color: 'black',
    width: 2
  },

});



var categoryStyle = new M.style.Category("nom_provincia", {
  "SEVILLA": verde,
  "JAEN": azul,
  "ALMERIA": rojo,
	"MALAGA": rosa,
	"CORDOBA": amarillo,
	"GRANADA": marron,
	"HUELVA": cyan,
	"CADIZ": naranja
});




function crea(){
layer.setStyle(categoryStyle);

}







function GetStyleForCategories() {
  let CategoryStyle = document.getElementById('CategoryStyle').value;
  let res =...