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

Add support for markers #656

Closed
Tracked by #229
tomaspinho opened this issue Aug 7, 2014 · 67 comments
Closed
Tracked by #229

Add support for markers #656

tomaspinho opened this issue Aug 7, 2014 · 67 comments
Labels
mapbox.js → GL JS For feature parity with mapbox.js or Leaflet

Comments

@tomaspinho
Copy link

I want to use this library in conjunction with the Mapbox service for a game I am currently developing. However, we need support for custom markers like the Google Maps JavaScript API provides. We need markers with custom images, bindable events and a similar simple API.

@mourner
Copy link
Member

mourner commented Aug 7, 2014

This is possible already with the GeoJSON support — you can add markers to the map with it, style it just like you would style the OSM POIs, and add interactivity using source.featuresAt method.

But we definitely should make a simple example for this. So more of a docs task.

@mourner mourner added the docs label Aug 7, 2014
@mourner mourner added this to the future milestone Aug 7, 2014
jfirebaugh added a commit that referenced this issue Aug 8, 2014
@jfirebaugh
Copy link
Contributor

Added an example, but this is not as easy or nice as it should be. The markers don't look like the familiar Mapbox.js markers. With a SDF icon and multiple layers, you could make it look more like that, but if you are using a default GL style, you are limited to the markers and SDF icons provided by that style.

One approach would be to supply a built-in sprite sheet with an SDF marker background and maki SDFs, and a default stylesheet for markers that layers the maki icon on top of the background and supports standard tokens from GeoJSON properties -- marker-color, marker-symbol, etc. This would require support for multiple stylesheets / multiple sprites.

@mourner
Copy link
Member

mourner commented Aug 8, 2014

I like the markers sprite + stylesheet approach, but the problem with it is that in a style that uses maki icons for POIs, we would duplicate most of the sprite. Maybe we should find some middle ground first — e.g. push multiple sprites and/or individual images, then reference a marker sdf in the stylesheet, and add stylesheet code that overlays maki icons in the example style (not doing it built-in yet).

Other tasks for the example:

  • figure out why the points collide with other symbols (e.g. "Mapbox SF" colliding with "San Francisco" label
  • add some interactivity — make markers clickable or hoverable, add some basic tooltip

@tomaspinho
Copy link
Author

Would it also be possible for you to add a simple example on how to add interactivity using the featurestAt method? Thank you very much!

@alanmclean
Copy link

Also would love to see an example for how to make markers interactive. I'm trying to reposition a marker within the map as the user drags.

@PeterPablo
Copy link

The link to the example by @jfirebaugh gives a 404. Was the page moved?

@jfirebaugh
Copy link
Contributor

Yeah, sorry about that. I updated the link.

@incanus
Copy link
Contributor

incanus commented Aug 15, 2014

I like the markers sprite + stylesheet approach, but the problem with it is that in a style that uses maki icons for POIs, we would duplicate most of the sprite.

On native, this is less likely to need to support Mapbox-style markers and/or Maki and more likely to need arbitrary client-provided imagery for markers. So we should probably focus on an approach that works in this generalized case — probably multiple sprite sheets.

@easinewe
Copy link

I would love to see some more documentation on the styling markers and initiating pop-ups. Api is somewhat limited without that feature.

@jescalan
Copy link

jescalan commented Oct 1, 2014

An example of how to make markers with custom images would be wonderful. I'm tinkering with this a bit and am nowhere close to figuring it out, to be honest. Happy to help out with working on this slash documenting it if you guys need!

@jescalan
Copy link

Any progress here? This is the only thing preventing me from moving forward with mapbox at the moment...

@tomaspinho
Copy link
Author

@Jenius try this: https://www.mapbox.com/mapbox-gl-style-spec/#sprite
with this: https://github.com/mapbox/mapbox-gl-js#sprite-generation
It does the job, even though it requires quite a bit of setup

@jescalan
Copy link

Woah, ok. So once I have generated a sprite sheet and provided it through that option, how do i make one of the sprites into a custom marker?

@jescalan
Copy link

Hey @theburdencarrier -- do you know any more about how to go about doing this? It seems like you need specific sizes for the sprites, do you know what they are supposed to be? It also seems like you need to run an icon generation afterwards with some sort of positions json file to map names to sprite positions if you want them to line up. Any more info on this second task would be great too.

Even just a short writeup that walked through how to do this would be really quite useful!

Also, is there no way to do the interactively? For example, if I were making a map that I wanted to plot peoples' faces on, and I could pull the face images with the map data, is there a way to map that image to a location where I'm going to drop a marker? Running a bunch of build scripts in that context isn't really feasible.

@hawaiikaos
Copy link

Adding my voice to this request for better documentation. Customising icons should be something that's super simple (and is in Google Maps). Using the maki sprites are just totally inadequate for most use cases. MapBox should at least have a well documented example.

@michito
Copy link

michito commented Dec 18, 2014

I'm with @hawaiikaos here. Please add a good example. I'd love to implement Mapbox GL for a project but I'm struggeling to add custom markers.

@robschley
Copy link

Is handling map labels that show up on mouse hover within the scope Mapbox GL or is that something that should be handled in HTML/JS? I tried to use some trickery to get the current hover point and bind the GeoJSON properties to a separate symbols layer to dynamically show labels when you mouse over certain GeoJSON polygons but it doesn't work fluidly. I'm using the GeoJSON source setData() API but the layer doesn't seem to be redrawn until I change the zoom level of the map. When I start zooming in and out, it sometimes works but it appears to also cache previously rendered points as well.

Edit - My issue was fixed by switching to master build after I saw this commit: 998a543

@jfirebaugh
Copy link
Contributor

Lately I've been thinking of "Markers" as being more of a series of incremental improvements and additions than as a monolithic feature. These include:

There is one marker related thing that's major enough to disqualify as "incremental" in my book, and that's clustering (#837).

@incanus
Copy link
Contributor

incanus commented Feb 20, 2015

Awesome, great way to break the progression down @jfirebaugh.

As I showed in chat the other day with @kkaefer @1ec5, on the native side, we have a high bar for markers to "just work" in the way that devs expect.

markers

Note how selection changes despite the gesture location not changing, so that obscured markers can be cycled through. Also, the selected marker temporarily moves to the front. These are the absolute barebones, simple pins without styling, added to an Apple map.

As we think about how this builds out on JS and native, taking a staged approach lets us focus on the things we need to ship for an MVP, then the rest of what people might expect of a toolkit, then the things that no one expects because it's brand new territory.

And agree on clustering.

@stepankuzmin
Copy link
Contributor

Crossposting this question.

Is there are any plans for leaflet-like markers styling? It could be something like L.divIcon which deals with gl context. It would be nice to have ability to style markers with all webgl power. Also it is not so simple to build custom markers using sprites, if marker display depends on it's content. I mean that I must have sprite icon for every possible marker view. So instead of that I want to handle marker displaying by myself.

@mirraj2
Copy link

mirraj2 commented May 2, 2016

All I want are good looking static markers. I literally just switched to google maps from mapbox because google maps lets me use whatever static image I want for my markers. On mapbox, it is HELL to use a basic PNG image as a marker.

The example you gave me uses built-in marker images that look like complete crap. I want to use actual good looking markers.

@Randgalt
Copy link

Randgalt commented May 2, 2016

Well, @lucaswoj the old JS library did perfect markers. All we want is what your other product already supports.

@ttoni
Copy link

ttoni commented May 2, 2016

Couple of points that where key to a map marker in my mapbox-js projects and fully possible with leaflet html markers:

  • Background image (f.e. png with shape of marker)
  • Font image (f.e. user avatar that was fetched from s3 and replaced a default user icon at)
  • Text overlay that has css styling (f.e. place name, user name, badge)

That´s not possible with static image markers or I couldn´t find a good documentation on how to achive this. Some map projects of mine are really stalled now because of this missing feature.

@mtin79
Copy link

mtin79 commented May 18, 2016

@lucaswoj :
I can't see how to easily (or at all) create your own markers (styling e.g.: with images like animated gifs, png, ...) via GeoJSONSource#setData as you mentioned above "Add marker in source #2552".
For me this issue is not closed.

@n1ghtie
Copy link

n1ghtie commented May 22, 2016

@mtin79 follow this guide #822 (look at what @peterqliu says), I found this useful. Although I agree there should be an easier way to do this.
Also this is useful. https://www.mapbox.com/help/custom-markers/
Simply upload your custom svg's and reference them as "marker-symbol" in your "FeaturesCollection"

@lucaswoj
Copy link
Contributor

@mtin79 Adding new icons/images/sprites at runtime is a separate issue: #358

@zo0m
Copy link

zo0m commented Jun 6, 2016

@n1ghtie Hello, I have issue with adding custom markers. I read help article from your link but I cant find button "Add SVG Images".
It should be here:
image

I dont see it:
14297761211b4969a53340f6a7fd7e20 1

Could you please help me. Thanks

@tristen
Copy link
Member

tristen commented Jun 6, 2016

@zo0m the dialog appears when you click the text input field (to the right of the "image" label), not the edit by zoom level link.

@mourner mourner mentioned this issue Jun 7, 2016
mourner added a commit that referenced this issue Jun 13, 2016
mourner added a commit that referenced this issue Jun 13, 2016
@mourner
Copy link
Member

mourner commented Jun 13, 2016

Pushed a basic implementation in #2725.

@tomaspinho
Copy link
Author

Wow, thanks @mourner and the rest of the Mapbox team!

@samvermette
Copy link

I tried adding my own SVGs to the icon library of a custom mapbox style (based off the Streets style) and was never able to link to them.. every other icon worked, but not the ones I uploaded. I published the style, made sure I was linking my Mapbox to it... tried different names...

Ended up downloading the style's json and switching the sprite reference to a custom json which only contains the icons I initially wanted to show, but now I lost every other icon too (highway shields, park, etc). Can't believe how painful it was to show custom images on the map. Any clue on why my custom icons aren't working as part of an existing style?

@n1ghtie
Copy link

n1ghtie commented Jun 16, 2016

How do you reference them? It should be like this

var markers = {
    "type": "FeatureCollection",
    "features": [{
      "type": "Feature",
      "properties": {
        "marker-symbol": "Volcano" // name of symbol in your sprite sheet
      },
      "geometry": {
        "type": "Point",
        "coordinates": [-155.24917602539062,
          19.326046963894633
        ]
      }
    }]
}
  map.addSource("markers", {
    "type": "geojson",
    "data": markers
  });
  map.addLayer({
    "id": "markers",
    "type": "symbol",
    "source": "markers",
    "layout": {
      "icon-image": "{marker-symbol}" //important to have it!
    }
 });

If you upload your images under mapbox studio and reference the name correctly you will get an image on your map :)

lucaswoj pushed a commit that referenced this issue Jun 30, 2016
* add an overlay class

Refs #656.

* Rename "Overlay" to "ElementMarker" (#2804)

* Rename "Overlay" to "DOMMarker"

* Rename DOMMarker to ElementMarker

* Remove unnecessary @Lends annotation
@achalnexus
Copy link

How to dynamic market not set in map box. I am list of data get and one by one marker set in mapbox but not successfully set marker.
I m wrote code this type of code..

var MarkerDatalist=[];
map.addSource("markers", {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [MarkerDatalist]
}
});

map.addLayer({
    "id": "markers-layers",
    "type": "symbol",
    "source": "markers",
    "layout": {
        "icon-image": "{marker-symbol}-15",
        "text-field": "{title}",
        "text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"],
        "text-offset": [0, 0.3],
        "text-anchor": "top"
    }
});

function CreateMarker(pID, pointlong, pointLat, icon1, InfoHTML, bDraggable, sTitle, ParkName, Parksize) {
var MapMarkerset = {
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [pointlong, pointLat]
        },
        "properties": {
            "id": pID,
            "title": sTitle,
            "description": InfoHTML,
            "parksize": Parksize,
            "marker-symbol": "monument"
        }
    }]
}
MarkerDatalist.push(MapMarkerset);
//map.getSource('markers').setData(MapMarkerset);

}

and other issue is zoom in out page reload in asp.net..?
Give me some help.

lucaswoj pushed a commit that referenced this issue Jan 31, 2017
@kylebebak
Copy link

Adding markers to a map is really basic functionality. I put it to the Mapbox devs that most people, if they knew how difficult it was to render a few hundred markers with custom styles to a map, wouldn't even consider using Mapbox for a project.

The attitude I've seen in these issues regarding markers is really disconcerting, and will ensure that a lot of users migrate to Google Maps.

Better documentation is needed, with an example showing exactly how to handle this use case. It's a really common use case. It's probably the most common use case.

@ryanbaumann
Copy link
Contributor

@kylebebak See https://www.mapbox.com/mapbox-gl-js/example/add-image/ for a great example of adding a custom icon / marker at runtime.

@Rajavelu
Copy link

Hi, any examples for handling mouseover, click events on markers which are created as symbol layer?

@fallenartist
Copy link

Such an example can be found in examples: https://www.mapbox.com/mapbox-gl-js/example/center-on-symbol/ 😃

@melroy89
Copy link

I know this is closed, but I still miss the basic marker by using geojson.

How cool would it be to have addLayer({ "type": "marker" (which implements mapboxgl.Marker()). So I do not need to create my own sprites and images, png and whatever!

This really drove my crazy today###.
So now I even need to convert to SDF in order to color my markers again :\

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mapbox.js → GL JS For feature parity with mapbox.js or Leaflet
Projects
None yet
Development

No branches or pull requests