mapbox / mapbox/mapbox-gl-geocoder

Adding an initial marker

Open
#458 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged needs information
Dominant language
JavaScript
Stars
388
Forks
181
PR merge metrics
No merged PRs in 30d

Description

I'm trying to use with plugin as a widget to input geolocation of a venue. But I have two requirements:

  • the marker should be draggable so users can make small changes to the pin position suggested by geocoder if they wish so
  • if a venue is being edited and it already has a position, the map should reflect that by showing an initial marker, bound to the geolocation search

options.marker accepts a Boolean or an Object. I assumed the intent of the latter was precisely to pass an existing marker instance to use when searching. However, I've tried doing this and no initial marker is being shown on the map:

const map = new mapboxgl.Map({
    container: map,
    style: 'mapbox://styles/mapbox/streets-v11',
    center: coords,
});

map.addControl(new MapboxGeocoder({
    accessToken: mapboxgl.accessToken,
    mapboxgl: mapboxgl,
    coords: new mapboxgl.Marker({draggable: true}).setLngLat(coords)
}), 'top-left');

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 MapboxGeocoder's handling of the marker option and the mapboxgl.Marker setup shown in the issue. Reproduce the configuration with an existing draggable marker, then verify that the marker appears at the supplied coordinates and remains connected to the geocoder search behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.