mapbox / mapbox/mapbox-gl-js

Allow custom cursors via filename/CSS

Open
#13,266 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature :green_apple:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

Motivation

Custom pointers on layer interactions. I want to be able to change the cursor to a custom .cur/.svg when hovering over different layers on the map. This will allow users to visually identify that certain symbols on the map may have interactive properties.

Design Alternatives

Allow me to use custom CSS classes to overwrite the cursor on mouseover, mouseenter, and mouseleave events or make map.getCanvas().style.cursor able to take custom cursors.

Design

Either design works and both seem minimally invasive to the current functionality of the mapbox cursors. I don't believe there are any drawbacks, I think this is a pretty intuitive feature that would provide significant enhancement to the UI/UX of mapbox.

Mock-Up

Developers:
This could be easy as one line of code for developers. For example in a 'mouseenter' event, a developer could simply set the cursor to a custom .cur/.svg file. Example:

.on('mouseenter', 'LAYERNAME', (evt: any) => {
     this.map.getCanvas().classList.add('CSS CLASS THAT OVERWRITES THE CURSOR');
OR
     this.map.getCanvas().style.cursor = "PATH TO CUSTOM CURSOR LOCATION";
})

End Users:
This would just look like the existing functionality for cursor events but replace it with a custom cursor.

Concepts

This feature could just be an addition to the current wiki page about mouse/cursor events.
I think the terminology could just be "Custom Cursor."
This feature relates to the current cursor functionality associated with mapbox mouse events.
The concept just introduces a new option customization in an intuitive way.

Implementation

For both C++ & Javascript the design implementation would be as simple as the folllowing:

  • Check if assigned string is a valid cursor name or a file
  • If it is valid cursor assign to that cursor
  • If it is a file, verify its a valid filename
  • Verify the file has the proper extension (.svg/.cur)
  • Assign to new cursor value

Edgecases:

  • File does not exist
  • File does not have the proper extension
  • File size too large
  • Cursor height and width are too big

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 by reading the existing cursor handling exposed through map.getCanvas() and the mouse/cursor event behavior described in the issue; no implementation file or test is named. Resolve whether CSS classes, canvas style values, or both are supported, including the listed file and size edge cases, then update the relevant behavior and cursor-event documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.