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

264
Vistas
React Openlayers, Polygon is removing after drawend

I'm using openlayers in react project. And trying to draw a polygon. When i compelete to draw, polygon is removing. I believe clicking to added coordinate is causing that. But cannot find any solution.

i follow this article for creating map. and this example for drawing polygon.

here is my map component:

    <MapWrapper center={fromLonLat(DEFAULT_CENTER)} zoom={ZOOM}>
      <MapLayers>
        <MapTileLayer source={new OSM()} />
      </MapLayers>
      <Controls>
        <ZoomControl />
        <FullScreenControl />
      </Controls>
    </MapWrapper>

and this is my map wrapper component:

const MapWrapper = ({ center, zoom, children }) => {
  const mapRef = useRef();
  const [map, setMap] = useState();
  const source = new VectorSource({ wrapX: false });
  //----------------ON COMPONENT MOUNT
  useEffect(() => {
    let options = {
      view: new ol.View({ zoom, center }),
      layers: [],
      controls: [],
      overlays: [],
    };
    let mapObject = new ol.Map(options);
    mapObject.setTarget(mapRef.current);
    setMap(mapObject);
    return () => mapObject.setTarget(undefined);
  }, [zoom, center]);
  //------------ DRAWING POLYGON -----------------
  useEffect(() => {
    if (!map) return;
    let draw = new Draw({
      source: source,
      type: "Polygon",
    });
    map.addInteraction(draw);
  }, [map]);
  return (
    <MapContext.Provider value={{ map }}>
      <div className="map-container"
        ref={mapRef}
      >
        {children}
      </div>
    </MapContext.Provider>
  );
};

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