Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

694
Vistas
openlayers, drawing clouds, polygon with customized stroke

I am working with openlayers 6 and I need to draw clouds on the maps a polygon with half circles stroke or a linestring, it doesn't matter the type as long as I can modify it ( adding and removing points, stretching, shrinking it). My knowledge of Openlayers is very limited so I am asking for guidance, how can I possibly do that

this image containes and example of what I want to achieve, an editable cloud shape drawn by a user

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could use a custom style which changes the displayed geometry, similar to https://openlayers.org/en/latest/examples/polygon-styles.html but replacing the segments of the polygon ring with semi-circular arcs.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.14.1/css/ol.css" type="text/css">
    <style>
      html, body, .map {
        margin: 0;
        padding: 0;
        width: 100%;
        height: 100%;
      }
    </style>
    <script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.14.1/build/ol.js"></script>
  </head>
  <body>
    <div id="map" class="map"></div>
    <script>
      var raster = new ol.layer.Tile({
        source: new ol.source.OSM()
      });

      var source = new ol.source.Vector({wrapX: false});

      var style = new ol.style.Style({
        stroke: new ol.style.Stroke({
          color: 'blue',
          width: 3
        }),
        fill: new ol.style.Fill({
          color: 'rgba(0, 0, 255, 0.1)'
        }),
        geometry: function (feature) {
          var geometry = feature.getGeometry();
          if (geometry.getType() === 'Polygon') {
            var coordinates = geometry.getCoordinates(true)[0];
            var arcs = [];
            for (let i = 0, len = coordinates.length - 1; i < len; ++i) {
              var center = [
                (coordinates[i + 1][0] + coordinates[i][0]) / 2,
                (coordinates[i + 1][1] + coordinates[i][1]) / 2
              ];
              var dx = coordinates[i + 1][0] - coordinates[i][0];
              var dy = coordinates[i + 1][1] - coordinates[i][1];
              var radius = Math.sqrt(dx * dx + dy * dy) / 2;
              var angle = Math.atan2(-dy, -dx);
              var sides = 32;
              arcs = arcs.concat(
                ol.geom.Polygon.fromCircle(
                  new ol.geom.Circle(center, radius),
                  sides,
                  angle
                ).getCoordinates(true)[0].slice(0, sides / 2)
              );
            }
            return new ol.geom.Polygon([arcs.concat([arcs[0]])]);
          } else {
            return geometry;
          }
        }
      });

      var vector = new ol.layer.Vector({
        source: source,
        style: style
      });

      var map = new ol.Map({
        layers: [raster, vector],
        target: 'map',
        view: new ol.View({
          center: [-11000000, 4600000],
          zoom: 4
        })
      });

      var modify = new ol.interaction.Modify({source: source});
      map.addInteraction(modify);

      var draw = new ol.interaction.Draw({
        source: source,
        type: 'Polygon',
        style: style
      });
      map.addInteraction(draw);

      var snap = new ol.interaction.Snap({source: source});
      map.addInteraction(snap);

    </script>
  </body>
</html>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda