QT QML-更改Mapbox字体大小 [英] QT QML - Changing Mapbox font size

查看:81
本文介绍了QT QML-更改Mapbox字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将QT 5.12.4与MapboxGl插件一起使用,并且试图弄清楚如何以更大的字体显示街道名称,但是我对如何指定文本大小感到非常困惑.我需要动态更改大小,以便使用预定义样式无法满足要求.

I'm using QT 5.12.4 with the MapboxGl plugin and I'm trying to figure out how to make the street names display in a larger font but I'm very confused about how to specify a text size. I need to change the size dynamically so using a predefined style is not going to meet the requirements.

两个令人困惑的方面是,对于QML,必须将Mapbox的文档翻译为"MapParameters",而对于更改文本大小的确切要求我一无所知.在通读文档和使用mapbox Studio之间,似乎需要修改道路标签"层.如果有人有一些如何更改文本大小的示例代码,如果可以共享,我将不胜感激.

The two confusing aspects are that Mapbox's documentation has to be translated into "MapParameters" for QML and I'm clueless as to what exactly is needed to change the text size. Between reading through the documentation and playing with the mapbox studio it seems like I need to modify the "road-label" layer. If anyone has some sample code of how to change the text size I would really appreciate it if you could share.

https://docs.mapbox.com/mapbox-gl-js/style-spec/#layout-symbol-text-size

  MapParameter 
  {
      type: "layout"

      property var layer: "road-label"
      property var textSize: 20
  }

推荐答案

我解决了这个问题,关键是获取了我正在使用的预定义样式(navigation-preview-day-v2)的JSON.这篇文章向我展示了如何获取预定义的sytle:

I solved the problem and the key was getting the JSON for the predefined style that I was using (navigation-preview-day-v2). This post showed me how to get the pre-defined sytle:

Mapbox样式表JSON的URL

对于navigation-preview-day-v2样式,URL为:> https://api.mapbox.com/styles/v1/mapbox/navigation-preview-day-v2?access_token =(您在这里的令牌)

For the navigation-preview-day-v2 style, the URL would be: https://api.mapbox.com/styles/v1/mapbox/navigation-preview-day-v2?access_token=(your token here)

通过格式化程序运行JSON,以便您可以读取它并找到呈现街道名称的图层.在这种情况下,分为四层:

Run the JSON through a formatter so you can read it and find the layer(s) where the street names are rendered. In this case, there are four layers:

  • road-label-small
  • road-label-medium
  • road-label-large
  • road-label-extra-large

这是一个如何在QML中形成字体大小的MapParameter的示例:

Here is an example of how to form the MapParameter in QML for the font size:


MapParameter
{
    type: "layout"
    property var layer: "road-label-large"
    property var textSize:
    {
       "base": 1,
       "stops":
       [
          [9, 10],
          [20, 16]
       ]
    }
}

您还可以将JSON导入Mapbox Studio中以查看或操纵样式.就我而言,我想动态缩放字体大小,因此在我的QML中,我添加了一个缩放因子,结果MapParameter为:

You can also import the JSON into Mapbox Studio to review or manipulate the style. In my case I wanted to dynamically scale the font size so in my QML I added a scale factor and the resulting MapParameter is:


MapParameter
{
    type: "layout"
    property var layer: "road-label-large"
    property var textSize:
    {
       "base": 1,
       "stops":
       [
          [9, Math.floor(10 * fontScaleFactor)],
          [20, Math.floor(16 * fontScaleFactor)]
       ]
    }
}

这篇关于QT QML-更改Mapbox字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆