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

How to implement markers that can be scaled and recoloured? #1594

Closed
Tracked by #229
AbrahamArun opened this issue Oct 6, 2015 · 8 comments
Closed
Tracked by #229

How to implement markers that can be scaled and recoloured? #1594

AbrahamArun opened this issue Oct 6, 2015 · 8 comments

Comments

@AbrahamArun
Copy link

I need to implement dynamic markers that can be scaled and re-coloured.

From this issue, I can see that SDF icons is a neat way to go about. But I am not sure how I can generate an SDF image? Do you use any tool for this? And I see that there is no SDF usage in V8 and it has been replaced with SVG.

SVG would be a better solution, but again from this issue that I raised earlier, it looks like SVG's are converted to png + JSON sprites, and therefore I cannot scale or re-colour it.

And I also think that there should be an example for this.

@AbrahamArun
Copy link
Author

@mourner Any thoughts on my above query?

@robertvorthman
Copy link

I am also interested in doing this. I find it strange that Mapbox GL JS is all about vector graphics but doesn't seem to have an easy way of customizing vector icons. It would be great to be able to use Mapbox GL JS instead of d3.js for mapping dynamic data.

@jordi-adame
Copy link

icon-color is also not working, this code taken from https://www.mapbox.com/mapbox-gl-js/example/geojson-markers/ wont change the marker color to red

    map.addLayer({
        "id": "markers",
        "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.6],
            "text-anchor": "top"
        },
        "paint": {
            "text-size": 12,
            "icon-color" : "#ff0000"
        }
    });

@lucaswoj
Copy link
Contributor

@jordi-adame The documentation for icon-color states that it can only be used for sdf icons.

@lucaswoj
Copy link
Contributor

ref mapbox/mapbox-gl-style-spec#97

@lucaswoj
Copy link
Contributor

Unfortunately we don't have a turnkey solution for generating sdf icons but you can see an example of how its done in the maki project https://github.com/mapbox/maki/blob/mb-pages/sdf-render.js

@indus
Copy link
Contributor

indus commented Jun 10, 2016

A poor man's attempt:

I tried to use the cli tools of imagemagick to create SDF images - and it works kind of (it is far from perfect, but at least it is simple):

As my test input I downloaded this maki icon: bicycle-15.svg

  • Step1: create a bigger raster version with some padding:
    convert.exe -size 150x150 -gravity center -extent 150% bicycle-15.svg -fill black temp.png
  • Step2: create a SDF (or something similar ?):
    convert.exe temp.png ( +clone -negate -morphology Distance Euclidean -level 60%,-50% ) -morphology Distance Euclidean -compose Plus -composite -auto-level -level 0%,30% -alpha copy -channel A -negate +channel -filter Jinc -resize 20% sprite.png

_I´m on Windows; on Linux you need no .exe but you have to escape the brackets:
convert tmp.png ... \( +clone ... \) ... sprite.png
_

together with a sprite.json:

{"icon": {"width": 38, "height": 38,"x": 0,"y": 0,"pixelRatio": 1, "sdf": true }}

this makes a single icon.

As said, this is just a quick-and-dirty solution with a lot of manual work ( e.g. the values in the IM commands could be tweaked) and I´m not sure somebody is interested.
(This is based on: https://habrahabr.ru/post/215905/ so thanks to Павел and Google Translator ;-)

@lucaswoj
Copy link
Contributor

This has been addressed with #2730 and #656

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

No branches or pull requests

6 participants