Combine more than one Style in a map - mapbox-gl-js

Here is what I'm trying to achieve: I want to combine more than one Style (a map built by the user in the Mapbox Studio) in a single map.
Let's say we have a Style with some base layers and tilesets, and another Style with just one tileset but with colors and other styling configuration and I want to dynamically combine them in my map.
What I have tried
I add the first Style with setStyle
Make a request to the Styles API and get the second Style json
Iterate over the sources of the second Style and add them to the map using addSource (renaming to avoid conflict)
Iterate over the layers of the second Style and add them to the map usgin addLayer
It pretty much worked, I only got errors with layers that use a "text-field" and require the style to have a "glyphs" attribute.
I then tried do dynamically change the "glyphs" attribute of the map Style but it didn't work. The error persists.
Error: "layers.state-label.layout.text-field: use of "text-field" requires a style "glyphs" property"
Why don't I add tilesets instead?
Because I want to get the all the layout options present in the Style.
Why didn't I open an issue about how to change the glyphs dynamically?
Alhtough this is the concrete problem I'm facing right now I was willing to get feedback on the general approach.
Is it something doable? Should I consider combining more than one style in the map a good idea? Is there a better way to do it?
Thanks in advance.
Leo,,

Your approach sounds generally fine, with a couple of major caveats, which you have discovered:
A style can only have a single font glyph
A style can only have a single icon sprite
If both are hosted under the same user account on Studio, I think it might work, at least for fonts. But judging from your error, that's not the case.
So what can you do? You will have to pick the font glyph from one style, then update every layer in the other style to use a font present in that style. I think that would be hard to do in the general case (I don't know how to find out what fonts are present in a glyph), so the safest option might be to create a new font glyph and remap every font to it.
FWIW, this general issue is already tracked here: https://github.com/mapbox/mapbox-gl-js/issues/4225

Related

Is there anyway to use colour picker in dart as use it fro templates

I want to design my own template by clicking on colours which I choose by myself
there is no direct way, you have to take a large colour array and then apply check on each of them which is very tedious task, better use this dependency, it will solve your problem

Multi Language Textbox in unity

I've been trying to make a project that creates Flash Cards , and i wanted to make the user be able to input any text on either sides of the card , the problem I'm facing now is that since the textbox(from TextMeshPro or regular one) has certain font whenever I try to input another languages like Japanese or Arabic it simply shows as squares, I tried the suggestion to use the textmesh pro dynamic font feature but still with no luck.
my question is , is there any way to do what I'm asking for without using fallback assets for every single language?
are there any unity plugins that do the job?
Like I said the aim is to make a textbox that displays whatever language is put in it.
any tips would be appreciated
NOTE: the solution doesn't need to use textmeshpro , it can use standard text component or any other custom ones.
I think the problem is the font. You will need a font that supports all the characters.
Perhaps you could use different fonts for different languages.
TextMeshPro creates a texture from the fonts characters. This texture will get very large if you have a lot of characters (e.g. for chinese). Because of that, the standard Text-component should be easier to work with.
(But I don't exactly know how the dynamic font feature of TextMeshPro works.)
So Since this is the first time I've worked with Fonts it appears that I didn't quite understand how fonts work and now I found the right way to approach the problem so I will give here the steps that I used to solve the multi-language issue:
1)you need a Font that supports as many languages as possible i found out that "Ariel Unicode" fits this need quite well with support to most common used languages support
2)you need to create a TextMeshPro Dynamic font asset that uses the font chosen in step one. (I tried using TextMeshPro Dynamic font before but i was mistakenly under the impression that the dynamic feature "search" for a font that has a certain character rather than we need to supply the font and it searches within the font for a character, that was a bit of a stupid assumption at my part created from the fact that I didn't understand how fonts work) .Here is a link how to use Dynamic SDF textmeshPro
I hope this helps someone with this process.

Maki icons not all displaying

I'm trying to build a map which allows users to choose icons for their geojson points. I just want to use the default map styles (streets|outdoors|light|dark|satellite) and Maki icons, however, not all icons are showing on all styles.
For example 'bicycle' and 'cafe' show on all the map styles, 'circle' only shows on satellite, and 'marker' doesn't show on any of them.
On a style I developed for another purpose, all markers show fine even though I know I didn't do anything special to 'add' them to the style.
So, my code is not the problem, my question is about the availability of maki icons on the default styles. I would have thought they'd all be available on all styles, but it seems not.
How can I tell which icons will work across all the default styles (short of trial and error)?
Is there some way I can 'enable' all the icons on a style?
Failing that, if I do have to make my own versions of the basic styles, I guess I can, but how do I ensure all the icons are loaded into the style?
The standard Mapbox styles are fairly optimised, and don't include anything that's not needed to display them. So, icons that aren't used in the style itself aren't included.
When you create a new style, I think Mapbox by default includes the whole Maki set.
If you can modify the style file (JSON) directly, you could try changing this line (for the Mapbox Streets style):
"sprite": "mapbox://sprites/mapbox/streets-v9",
to the equivalent in one of your custom styles, something like:
sprite": "mapbox://sprites/woowoowoo/htd32t6hd236t",
But it might cause problems if there are icons in Mapbox Streets that aren't in your style.
In short, I don't think there's a simple way to add "all the icons". Each style has its own set of icons.
A better way might be to use addImage/loadImage to load the custom icons you want, at run time. See this example.

How to add text outline in unity

How can i add text outline in unity over a text UI object?
I want to do it in the designer/editor view. i cant see to find any useful topic and i also cant see how to add it from the designer view.
My project is 2d and i'm using the latest unity version 5.3. I want to achieve similar effect.
Or. Alternatively to Joe's answer. To simply add a outline effect to a normal .ttf font :
Click on the text object from the Hierarchy
Click the Add Component button in the inspector
Type "outline" in the search bar.
Add the outline component.
Note! This explains how to make custom type ("sprite sheet type") in Unity.
Before reading it, check Uri's & Programmer's answer which explains using the handy new "outline" feature in .UI ! It may well be enough!
Unity does not have any fancy type handling at all.
You can drop in "normal" .ttf fonts,
or, you can drop in "image fonts", called custom fonts by Unity, where you literally make each letter on a sprite sheet.
A font sprite sheet looks something like this:
Here's exactly how to do it ...
(1) you have to use GlyphDesigner (or any similar product) to actually make your custom font sheet. Find the product you like for your Mac or PC to do this.
(2) There is a critical trick.
Unity completely forgot to include a type matcher for custom fonts. (They may fix this in Unity 6.) It's one of the stupidest things in Unity. So, fortunately there is a free and perfect script
BitmapFontImporter.cs
https://github.com/BenoitFreslon/BitmapFontImporter
There's a full and long tutorial link at that page.
You have to include that to make custom fonts work. It's just one of those weird things about Unity.
So in short, firstly you have to literally "draw" such custom fonts, letter by letter. In fact you need to use something like GlyphDesigner to do that.
Secondly in Unity you have to use the extremely handy script mentioned above or it won't work. Enjoy!
http://answers.unity3d.com/answers/1105527/view.html
TextMesh Pro from the Asset Store does the job and it can be imported for free.
This gives plenty of possibilities fort texts, including how thick the outline should be.

How does one get the font color for a run/txbody/paragraph from a presentation theme?

I'm working on a PresentationML parser, and I'm trying to implement support for themes with regard to font color. I'm working with the SDK, and I've puzzled out this monster:
Slide.SlidePart.SlideLayoutPart.SlideMasterPart.SlideMaster.SlideMasterPart.ThemePart.Theme.ThemeElements.ColorScheme
But it's still not clear where I go to get the color for a run which hasn't had it's color otherwise specified. Any help on this would be greatly appreciated.
TIA.
UPDATE: After just wading through the xml, it looks like the monster call I posted above is probably the right one...it yields an element with a "val" attribute that matches the hex code I'm looking for. But it's not clear how I would resolve the particular scheme in the color map ("Light1" in this case). I'm about 75% of the way there, I think - if someone can help me with the logic to know which scheme applies to a run, I think that's what I need.
The free ebook Open XML Explained might give some insight to aid your understanding. Under the PresentationML section, Document Content Structure it talks about how Themes and Master Layouts are used to give default values:
page 86 - 2nd Paragraph:
DrawingML theming can be used to create default values for fonts, layouts, and other branding related data and allow it to be separated from the main body of the presentation. A theme is reusable across all the Open XML markup languages. Inside a PresentationML package various themes are in use. By default each individual master, slide-, note- and hand-out masters, references a separate theme part. The presentation itself also references a default theme to be used in the presentation. This default theme shared with the slide masters by referencing the same part inside the package.
So, in the theme1.xml of your presentations SlideMaster, you will find a theme definition which is used for the slide master and your presentation. The color name Light1, Dark1, etc map to 12 required colors in the Color Scheme of the Theme Element for each theme. See schema for details.
So in the Run, you see Light1, which maps to the number defined in the theme. If the author changes a Master Layout and/or Theme, the Light1 doesn't change in the run, but the value in the theme might and that is where you get the new value from.
On Page 121, the 12 colors are mentioned in Open XML Explained:
Inside the theme element you are required to create a themeElements node which holds all the theme's data. At this level you can also apply extra information or overrides on the existing information inside the theme elements. Theme elements are built up using a set of child nodes, each node identifying a specific data item such as the fonts or colors. The clrScheme element defines a list of colors. The list of themed colors is limited to items such as 'accent1', or 'visited link'. Each of these theme colors uses a separate XML element, where the node name identifies the theme color. Inside this element you make use of the coloring mechanism discussed earlier on coloring shapes using DrawingML. In the markup sample 157 there are two theme colors defined, the 'dark-1' and 'accent-1' colors. The markup sample is not complete. You are required to define value for all the twelve theme colors.
Hope this helps...