0

I've implemented a 'route between points' site using the 4.7 JavaScript API. The logic works fine, but I'm having a graphical display issue: when a point is picked up and dragged to a new location it doesn't redraw intermittently, the mouse simply drags an invisible point to the new location, where it reappears.

The 'update' event fires every time the mouse moves, but the graphics layer won't redraw on the screen, even when cloning the graphic, deleting it from the graphics layer, and re-adding it - the usual fix for a graphic not re-drawing upon being edited.

Oddly, everything works fine if the user zooms in or out of the map while gripping the point. Things start drawing, and the greyOutAllRouteLines function (which sets the colour of every line on the map to grey, to indicate that with the shifted point they're now out of date) works as advertised. In both cases the remove/clone/re-add method is required, otherwise nothing redraws regardless of map interaction.

It feels like the graphics layers are being updated quite happily while the 'update' events are firing, but they aren't being prompted to re-draw until the map is interacted with, at which point they function as expected. Interacting with the map using zoom functions and similar don't trigger the effect.

Here's the event handler:

enter image description here

2

Are you freezing the pan and zoom of the map so it doesn't move around?

Maybe drag isn't the correct event to use. This is quick hack, but I was able to get it to work by using the pointer-move event.

https://codepen.io/odoe/pen/vryXKo?editors=1000

view.on("click", (event) => {
  view.hitTest(event).then(({ results }) => {
    const graphic = results[0].graphic;
    view.on("pointer-move", (event) => {
      view.graphics.removeAll();
      const g = graphic.clone();
      const pt = view.toMap(event);
      g.geometry = pt;
      view.graphics.add(g);
    });
  });
});
  • Brilliant, that's solved it! Adding a 'check if a point is currently being dragged' bool has let me build exactly the functionality I was looking for. – Nick D Jun 11 '18 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.