CP-070-08

Panel StyleLine

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 class="row">
      <table id='tableStyle'>
        <tr>
          <th onclick="ocultarTable('fill')">Fill</th>
        </tr>
        <tr>
          <td id="fill-td" class="display-hidden">
            <div class="input-group">
              <span class="label label-default">Color:</span>
              <input type="color" id="fill.color" onchange="set(this)">
            </div>
            <div class="input-group">
              <span class="label label-default">Opacity:</span>
              <input type="range" id="fill.opacity" onchange="set(this)" value="0.5" min="0" max="1" step="0.1">
            </div>
            <div class="input-group">
              <span class="label label-default">Width:</span>
              <input type="range" id="fill.width" onchange="set(this)" value="0.5" min="0" max="1" step="0.1">
            </div>
          </td>
        </tr>
        <tr>
          <th onclick="ocultarTable('stroke')">Stroke</th>
        </tr>
        <tr>
          <td id="stroke-td" class="display-hidden">
            <div class="input-group">
              <span class="label label-default">Color:</span>
              <input type="color" id="stroke.color" onchange="set(this)">
            </div>
            <div class="input-group">
              <span class="label label-default">Width:</span>
              <input type="range" name="" min="1" max="100" id="stroke.width" onchange="set(this)">
            </div>
            <div class="input-group">
              <span class="label label-default">LineCap</span>
              <select name="linecap" id="stroke.linecap" onchange="set(this)">
                  <option value="butt">butt</option>
                  <option...

CSS

<style rel="stylesheet">
      html,


      body {
        margin: 0;
        padding: 0;
        height: 100%;
        overflow: auto;
      }

      #tableStyle {
        font-family: arial, sans-serif;
        border-collapse: collapse;
        width: 100%;
      }

      table#tableStyle td {
        border: 1px solid #dddddd;
        text-align: left;
        padding: 8px;
      }

      table#tableStyle th {
        border: 1px solid #dddddd;
        text-align: left;
        padding: 8px;
      }

      table#tableStyle tr:nth-child(even) {
        background-color: #dddddd;
      }

      input-group {
        margin: 20%;
      }

      .display-hidden {
        display: none;
      }

      .input-group {
        margin-bottom: 1em;
      }
    </style>

JavaScript

// CP-070-08 - Panel StyleLine
// Caso de prueba orientado a verificar las caracterísitcas de estilo de líneas

function ocultarTable(elementToManage) {
  let element = document.getElementById(elementToManage + "-td");
  if (element.classList.contains("display-hidden")) {
    element.classList.remove("display-hidden")
  }
  else {
    element.classList.add("display-hidden")
  }
}
let mapajs = M.map({
  container: "mapjs",
  projection: "EPSG:4326*d",
  layers: ["OSM"],
  center: {
    x: -5.9584180843195425,
    y: 37.36912689160224
  },
  zoom: 5,
  controls: ['layerswitcher', 'overviewmap'],
});

var polylines = new M.layer.WFS({
  name: "Ríos",
  url: "https://clientes.guadaltel.es/desarrollo/geossigc/wfs",
  namespace: "mapea",
  name: "mapb_hs1_100",
  legend: "mapb_hs1_100 - COROPLETAS",
  getfeatureinfo: "plain",
  geometry: 'LINE',
  extract: true,
});

mapajs.addLayers([polylines]);
var nullStyleLine = new M.style.Line({
  stroke: {
    color: '#C8FE2E'
  }
});

polylines.setStyle(nullStyleLine);

// Setea estilo a nivel de capa
function setStyleLayer(layer, style) {
  layer.setStyle(style);
}

//Setea estilo a nivel de feature
function setStyleFeature(feature, style) {
  feature.setStyle(style);
}


var amarillo = new M.style.Line({
  fill: {
    color: 'yellow',
    width: 15
  },
  stroke: {
    color: 'black',
    width: 2
  },
  label: {
    text: "feature",
    font: "24px Arial",
    fill: new ol.style.Fill({
      color: "red"
    }),
    stroke: new ol.style.Stroke({
      color: "#fff",
      width: 3
    }),
    textBaseline: 'middle',
    textAlign: "right",
    rotateWithView: false,
    textOverflow: "ellipsis",
    minWidth: 60,
    path: true

  }
});

polylines.setStyle(amarillo);

function set(element) {
  let style = polylines.getStyle();
  if (element.type == "checkbox") {

    style.set(element.id, element.value);
  }
  else {
    let r = element.value;
    if (element.value == "true") {
      r = true;
    }
    if (element.value ==...