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

261
Visualizações
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 à 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