openlayers / openlayers/openlayers

Modify interaction breaking map when using webworkers

Open
#12,980 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
12.6k
Forks
3.2k
Avg merge
2d 17h
Merged PRs (30d)
21

Description

Describe the bug

I have used this example as the foundation for my code for getting WebWorkers working with loading Vector tiles into OpenLayers:

https://openlayers.org/en/latest/examples/offscreen-canvas.html

After adding Feature objects to the map, it works very well until I start adding interactions. When adding a Modify interaction (either before or adding the Vector tiles) the map stops working. CPU usage goes up and the map tab blows up.

The Feature objects are being added to a separate VectorLayer which is not being loaded by the web worker.

I have tested if this is actually an issue with using the Vector Tiles - it's not. If I add the Features and interactions to the map with the "Advanced Mapbox Vector Tiles" example everything works ok.

Also, if I delay the adding of the modify interaction by using setTimeout() the map tiles load OK but as soon as the function inside the setTimeout() function fires the map blows up and the browser tab crashes.

This seems that it is not actually the loading that is breaking. Instead, the map itself is breaking.

To Reproduce

This can be replicated by combining the following examples:

Instructions

  1. Start with this example: https://github.com/openlayers/openlayers/files/7507032/offscreen-canvas.txt
  2. Replace the contents of offscreen-canvas.js file with the contents of the attached offscreen-canvas.txt file.
  3. See lines 263 - 281. Add/remove the modify interaction.

offscreen-canvas.txt

Expected behavior

When using a web worker to load the map tiles, a Modify interaction can be added to the amp without crashing the map.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the offscreen-canvas example and attached offscreen-canvas.txt, especially lines 263–281, then compare with the regularshape example. Reproduce the crash by adding or removing the Modify interaction while loading Vector tiles in a web worker; done means the map continues loading and the browser tab does not crash.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.