Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

204
Visualizações
Problem with drawing arrows in OpenLayers

I would like to draw the simple arrow in OpenLayers.

I found some examples here:

OpenLayer 4 draw arrows on map https://openlayers.org/en/latest/examples/line-arrows.html Draw arrow without using any image in openlayers3

and made some code:

var arrowInteraction = new ol.interaction.Draw({
type: 'LineString',
source: vectorLayer.getSource(),
geometryFunction: function(coordinates, geometry) {
var geometry = coordinates.getGeometry();
var styles = [
    // linestring
    new ol.style.Style({
        stroke: new ol.style.Stroke({
            color: '#ffcc33',
            width: 2
        })
    })
 ];

  geometry.forEachSegment(function (start, end) {
    var dx = end[0] - start[0];
    var dy = end[1] - start[1];
    var rotation = Math.atan2(dy, dx);

    var lineStr1 = new ol.geom.LineString([end, [end[0] - 200000, end[1] 
 + 200000]]);
    lineStr1.rotate(rotation, end);
    var lineStr2 = new ol.geom.LineString([end, [end[0] - 200000, end[1] 
 - 200000]]);
    lineStr2.rotate(rotation, end);

    var stroke = new ol.style.Stroke({
        color: 'green',
        width: 1
    });

    styles.push(new ol.style.Style({
        geometry: lineStr1,
        stroke: stroke
    }));
    styles.push(new ol.style.Style({
        geometry: lineStr2,
        stroke: stroke
    }));
   });

   return styles;
 }

I am getting an error:

coordinates.getGeometry is not a function

What can be wrong here?

My full code is here:

https://mktest.opx.pl/

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This might help: TypeError: Cannot read properties of undefined (reading 'id')

If I understand it right, the functions aren't called synchronized.

In that tutorial, he catch it with:

 itemToForm = () => {
  if(this.item === undefined) {return}
         
  // The rest of the code
}

But you can also catch it with

  if(yourObjectOrValue === undefined) {// The rest of the code}

     
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda