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

Is there a way to programmatically move a vertex #147

Open
newmanw opened this issue Sep 25, 2017 · 1 comment
Open

Is there a way to programmatically move a vertex #147

newmanw opened this issue Sep 25, 2017 · 1 comment

Comments

@newmanw
Copy link

newmanw commented Sep 25, 2017

My UI allows for lat/lng's to be changed programatically. When that happens I need to move the vertex and update the layer.

I have tried this:

layer.setLatLngs(geojson);
layer.editor.reset();

Which will do the job however as one would expect that remakes the entire editLayer. I have applied some css to the selected vertex and if I call 'reset' I lose that css.

Is there a good way to update the lat/lng of a vertex without calling reset?

@bytesnz
Copy link
Contributor

bytesnz commented Jun 11, 2018

There seems to be a bug that Leaflet.Editable doesn't handle calls to the shapes setLatLngs() function. What you can do to workaround it is disable editing on the shape before you call setLatLngs, call it, then reenable editing

const workaround = (shape, coords) => {
  const editingEnabled = shape.editEnabled();
  if (editingEnabled) {
    shape.disableEdit();
  }

  shape.setLatLngs(coords);

  if (editingEnabled) {
    shape.disableEdit();
  }
};

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

2 participants