mapbox / mapbox-gl-draw

Draw tools for mapbox-gl-js
https://www.mapbox.com/mapbox-gl-js/example/mapbox-gl-draw/
ISC License
952 stars 593 forks source link

doRender() does not force rerender #959

Open hasanayan opened 4 years ago

hasanayan commented 4 years ago

I am working on a custom mode and I would like the drawing to change based on user's text input during the drawing, dynamically. So I read the input's input event and update my drawing parameters. I update my features using feature.setCoordinates() and then call this.doRender(this.state.feature.id) expecting it would rerender the drawing using the updated feature. However, the render doesn't happen unless I move mouse over the map area.

First I added the text input on the map using mapbox's Popup. Seeing it didn't work like I described above, I tried to add plain dom elements positioned over the map without using Popup. I got the same result.

Am I missing something? is there a way to force rerender in my case?

ghost commented 3 years ago

I'm running into the same issue, very frustrating! Any idea if this can be fixed?

chenlevy4 commented 2 years ago

I'm running into the same issue, does anyone know how to solve this?

nornes commented 1 year ago

I'm having the same issue. If I add the onMouseMove function as an empty function, the render will happen on every mousemove, but this won't work for touch.

I have made an ugly hack where I save the state as this.state and return this.state in the setup, and adds the display function to "this" the first time it toDisplayFeatures renders anything. Then I overwrite the doRender method like so:

MyTool.doRender = function(id) {
    if (this.display) this.toDisplayFeatures(this.state, this.getFeature(id).toGeoJSON(), this.display)
}

If you have the state available at all times it would work to just pass that as a param as well I guess, but in my case that's not an option. Also, it's node to have the params the same for the day this bug is solved and we can go back to using the proper method. This is a bit of an ugly solution, but at least in my case it works.

toniopelo commented 10 months ago

Same problem on my side, while implementing an undo function while being in draw_polygon mode, I can't find a way to force the map to re-render

gustavo-yance-ikon commented 9 months ago

Same problem on my side, while implementing an undo function while being in draw_polygon mode, I can't find a way to force the map to re-render

Had the same issue but was able to find a way by modifying the mode file and using

this._ctx.store.render()