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

266
Vistas
【capa abierta】 agregue una función a la capa, pero no puede obtener la función haciendo clic en el evento, cómo resolver el problema

Pregunta

versión de capas abiertas: 6.4.3

Agregue una función creada por una cadena SVG al mapa, luego haga clic en la función en el mapa, pero no puede obtener la función de la función de devolución de llamada. Sin embargo, creo una función con una URL de imagen nomarl, puedo obtener la característica haciendo clic en la función en el mapa.

como puedo resolver el problema

código

 import 'ol/ol.css'; import Feature from 'ol/Feature'; import Map from 'ol/Map'; import Point from 'ol/geom/Point'; import TileJSON from 'ol/source/TileJSON'; import VectorSource from 'ol/source/Vector'; import View from 'ol/View'; import {Icon, Style} from 'ol/style'; import {Tile as TileLayer, Vector as VectorLayer} from 'ol/layer'; const iconFeature = new Feature({ geometry: new Point([0, 0]), name: 'Null Island', population: 4000, rainfall: 500, }); const src = `data:image/svg+xml;utf8,` + `<svg version="1.1" xmlns="http://www.w3.org/2000/svg" >` + `<path d='M0,0 L0,60 L90,30 z'/>` + "</svg>"; const iconStyle = new Style({ image: new Icon({ anchor: [0.5, 46], anchorXUnits: 'fraction', anchorYUnits: 'pixels', src, }), }); iconFeature.setStyle(iconStyle); const vectorSource = new VectorSource({ features: [iconFeature], }); const vectorLayer = new VectorLayer({ source: vectorSource, }); const rasterLayer = new TileLayer({ source: new TileJSON({ url: 'https://a.tiles.mapbox.com/v3/aj.1x1-degrees.json?secure=1', crossOrigin: '', }), }); const target = document.getElementById('map'); const map = new Map({ layers: [rasterLayer, vectorLayer], target: target, view: new View({ center: [0, 0], zoom: 3, }), }); map.on("click", function (evt) { const feature = map.forEachFeatureAtPixel(evt.pixel, function (feature) { return feature; }); // when i click the feature area,i can't get the feature console.log(feature) //undefined });

resultado

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

0

El SVG necesita ancho y alto para funcionar con la detección de coincidencias de OpenLayers

 const src = `data:image/svg+xml;utf8,` + `<svg width="90" height="60" version="1.1" xmlns="http://www.w3.org/2000/svg" >` + `<path d='M0,0 L0,60 L90,30 z'/>` + "</svg>";
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