Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drawcontrol doesn't work on pre-existing layers #566

Open
StefanoOcchetti opened this issue Sep 5, 2022 · 0 comments
Open

Drawcontrol doesn't work on pre-existing layers #566

StefanoOcchetti opened this issue Sep 5, 2022 · 0 comments

Comments

@StefanoOcchetti
Copy link

StefanoOcchetti commented Sep 5, 2022

If a map is initialized with some feature, the drawcontrol doesn't handle them.

To replicate the problem:

  1. open the code sandbox at https://codesandbox.io/s/xenodochial-tu-pwly8.
  2. add a new layer (you can replace the code in index.js in the sandbox with the following, that just adds a GeoJSONLayer, displaying a magenta line from around London to somewhere in the Indian Ocean ):
import React from "react";
import ReactDOM from "react-dom";
import ReactMapboxGl, {GeoJSONLayer} from "react-mapbox-gl";
import DrawControl from "react-mapbox-gl-draw";
import "@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css";

import "./styles.css";
const geojsonStyles = {  
  linePaint: {
    "line-color": "#ff11ff",
    "line-width": 4,
    "line-opacity": 1
  }  
}

const data = {
  'type': 'Feature',
  'properties': {},
  'geometry': {
    'type': 'LineString',
    'coordinates': [[-0.23,51.54], [90,0]]
  }
}


const Map = ReactMapboxGl({
  accessToken:
    "pk.eyJ1IjoiZmFrZXVzZXJnaXRodWIiLCJhIjoiY2pwOGlneGI4MDNnaDN1c2J0eW5zb2ZiNyJ9.mALv0tCpbYUPtzT7YysA2g"
});

function App() {
  const onDrawCreate = ({ features }) => {
    console.log(features);
  };

  const onDrawUpdate = ({ features }) => {
    console.log(features);
  };

  return (
    <div>
      <h2>Welcome to react-mapbox-gl-draw</h2>
      <Map
        style="mapbox://styles/mapbox/streets-v9" // eslint-disable-line
        containerStyle={{
          height: "600px",
          width: "100vw"
        }}
      >
        <DrawControl onDrawCreate={onDrawCreate} onDrawUpdate={onDrawUpdate} />
        <GeoJSONLayer {...geojsonStyles} data={data} />
      </Map>
    </div>
  );
}

ReactDOM.render(<App />, document.getElementById("root"));
  1. run the code.

-> the drawcontrol doesn't act on the pre-existing line.

A code sandbox for this behaviour is available at: https://codesandbox.io/s/infallible-poitras-lpwr41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant