[go: up one dir, main page]

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

Custom marker #348

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Custom marker #348

wants to merge 3 commits into from

Conversation

GNURub
Copy link
@GNURub GNURub commented Apr 7, 2020

The option.marker parameter has the option of being a Marker instance.

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • run npm run docs and commit changes to API.md
  • update CHANGELOG.md with changes under master heading before merging

@andrewharvey
Copy link
Collaborator

Hi @GNURub could you explain a bit more of the use case for passing an already initialised Marker instance instead of just passing the marker options and having the Geocoder Control create it for you?

@GNURub
Copy link
Author
GNURub commented Apr 7, 2020

I have a marker on the map, and I want to use this in the Geocoder Control, so I can pass the instance to it in the marker option.

const map = new new mapboxgl.Map({...});
const myExistingMarker = new mapboxgl.Marker().addTo(map);
......
map.addControl(
   new MapboxGeocoder({
       marker: myExistingMarker
    });
);

@andrewharvey
Copy link
Collaborator

Okay, it does complicate things a bit more though, since currently the marker is managed internally by the GeocoderControl, if it's shared then what happens if the GeocoderControl has removed it but you still have the reference and try to use it? Vice versa you remove it but the GeocoderControl is still expecting it there?

Then what's the expectation when you pass that existing Marker, should the GeocoderControl immediately remove it from the map, or leave it.

It feels much cleaner to simply have the GeocoderControl use it's own private Marker, that way it has control over it. There's little benefit in "reusing" a marker, so shouldn't be an issue to let the GeocoderControl create a new one.

If you really want to use your own marker, you could implement movement of it yourself via the events fired by the GeocoderControl.

Anyway, just my initial thoughts, keen to hear what others think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants