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

111
Vistas
How can I make an SVG segment clickable in a webpage?

Below is a code snippet I am using to draw a simple square (though the shape will get much more complex further in the project as it is meant to visualize DWG files imported from a back-end).

I have however hit a wall in trying to get the SVG segment that is clicked. What I am looking to do in the current setup is:

  1. User clicks on a segment of the SVG
  2. The segment closest to it (with some margin) is captured
  3. I can use that captured information in my code (preferably 4 number values, representing the x1, x2, y1 and y2)

The problem I am having is that I don't know how to identify the segments, while I can see that they advance with an [x1, y1, x2, y2, x3, y3, x4, y4] pattern.

var draw = svg.SVG().addTo('body').size(300, 300);
var arr = new svg.Array([0, 0, 0, 100, 100, 100, 100, 0])
draw.polygon(arr).fill("0x000000");

An example of what I want to be able to do:

get the line along the point [50, 0] which should be in the first segment of the shape drawn in the snippet above. I need to correctly identify the segment the user has selected so I can work with that information. If I can somehow get the begin and end coordinate of the segment that was clicked that would probably lead me to a successful solution.

about 4 years ago · Juan Pablo Isaza
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