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
Is there an API I can use for calling setLayoutProperty method on the map instance? #683
Comments
I tried again and found the load event listener callback function had never been called, is it right to use Mapbox GL JS API give a way to listen load event like this:
|
onLoad={evt => {
const map = evt.target;
// do something
}}
onLoad={evt => console.log(evt.target.getStyle().layers)} |
@Pessimistress Sorry for the typos, I used
For the third tip, I think And for the second tip, I found
Would properties passed to StaticMap like I am also confused why Another confusing point is would that cause some problems if I use And you also attach event listener on this variable: But it seems this code won't work for me:
I wonder if there is some extra configurations for Thanks :-) |
It seems I look an PR of this repo and directs the codes to a different developer's repo, but the https://github.com/uber/react-map-gl/blob/master/src/mapbox/mapbox.js#L282-L283 And to prevent the things you mentioned above, I used mapbox official package to change layoutProperty for me @mapbox/mapbox-gl-language and upadte the
It seems I would not modify a layer that not exist anymore, but the problem still exists. Currently, I can passby this problem (can't modify mapbox's layout property) by adding the same operation to
|
First of all, if you're using react-map-gl from the fork that you linked to, it is extremely outdated (mapbox-gl dependency on 0.37). I cannot speak to whether anything still works with that version. Regarding your failed attempt at using
I'm fairly certain that I just tried this and it works perfectly: https://github.com/uber/react-map-gl/blob/set-language-example/examples/set-language/app.js |
@Pessimistress Thanks for your codes and detailed explanations! I am using the latest I think
I think I tried the same way to listen the map https://github.com/uber/react-map-gl/blob/set-language-example/examples/set-language/app.js#L15-L18
Then the calling to A different thing that in my code is I import Staticmap, rathen than import from default map layer in your code:
I replace As I said before, currently, I can passby this problem (can't modify mapbox's layout property) by adding the same operation to |
What do you mean by "I would get event.target to be null sometimes" -- is it called multiple times during runtime? Is Well you can always do this: _onLoad(event) {
// const map = event.target;
const map = this.staticMap.current.getMap();
map.setLayoutProperty('country-label-lg', 'text-field', ['get', 'name_zh'])
} |
Since my project couldn't verify the runtime of firing |
I tried again. It's pretty wired that I only caught the problem sometimes. I use
I print the I just add |
@Pessimistress I quickly look through the things I mentioned above, and I thought it's not a problem of specific map like StaticMap but should belongs to an event problem. It seems
And looking into the definition of mapbox
I am not sure whether the necessary resources mentioned in
So I thought the reason why such situation I mentioned above (also mentioned in mapbox-gl-js issue mapbox/mapbox-gl-language#27 ) would appear sometimes is that I use Currently, according to documents, react-map-gl only provides three events: So on the hand, I thought react-map-gl may provide another event handler like |
Fix published in 4.0.10. |
I think it's not a problem of specific map like StaticMap but should belongs to an event problem, so it’s not resolved yet (according to my last comment in this issue)? |
Can you create a minimal example that reproduces this issue? |
I don't know if you can reproduce it in your computer, because it also appeared sometimes in my environment. Here's the code https://gist.github.com/hijiangtao/a53a5922428331b63c44f6d2d7cb07d3: I make my problem more clear in this way:
NOT RELATED WITH ABOVE ITEMS: Besides, as I mentioned above #683 (comment) , I suggest react-map-gl to provide another event handler like |
Just saying, it is probably way easier if you just create a custom map style that uses Chinese for all label layers. |
Maybe there are too much trivial things need to be handled, since there are too many label types that I need to modify (specify the name value one by one)? And mapbox studio may be the only way I could customize map layer. 😐 |
@hijiangtao I am in the same situation, only using |
@marciobarrios It's too long from I first reported this problem, I think there's some problems (maybe not work sometimes with only just You can locate the problem if you are not too busy right now, and please let me know if there's any progress on it, I am glad to help solve it together. I looked through my codes, and find I can make my codes work with const addMapControl = (map) => {
map.addControl(new MapboxLanguage({
defaultLanguage: 'zh',
}));
map.setLayoutProperty('country-label-lg', 'text-field', ['get', 'name_zh']);
} Just as I said in reply
|
The mapbox API provides
setLayoutProperty
method for developers to change the layout property of a map instance, such as thelanguage
:According to mapbox API, I can use it in this way:
I am developing project with react-map-gl and deck.gl, I use
StaticMap
exactly in my project and need to change the display language of maps.But after looking through the docs of react-map-gl and
StaticMap
file, I couldn't find a method to achieve that.I found that
StaticMap
provides a method calledgetMap()
:https://github.com/uber/react-map-gl/blob/cb173b0ac405c42200ddfdaad5a6bed96d665fbf/src/components/static-map.js#L174-L176
But when I use this method to make changes to map instance, there's nothing happened.
The text was updated successfully, but these errors were encountered: