简体   繁体   English

QGIS2web 中的标签不可编辑

[英]Labels in QGIS2web are not editable

I want to have my labels visible and customizable in QGIS2web plugin.我想让我的标签在 QGIS2web 插件中可见和可定制。

My code look like this:我的代码如下所示:

 var size = 0;
 var placement = 'point';
 function categories_Area5chamber_14(feature, value, size, resolution, labelText,
                   labelFont, labelFill, bufferColor, bufferWidth,
                   placement) {
            switch(value.toString()) {case 'BT':
                return [ new ol.style.Style({
    stroke: new ol.style.Stroke({color: 'rgba(35,35,35,1.0)', lineDash: null, lineCap: 'butt', 
  lineJoin: 'miter', width: 0}),fill: new ol.style.Fill({color: 'rgba(0,0,0,1.0)'}),
    text: createTextStyle(feature, resolution, labelText, labelFont,
                          labelFill, placement, bufferColor,
                          bufferWidth)
})];
                break;
 case 'Voneus':
                return [ new ol.style.Style({
    stroke: new ol.style.Stroke({color: 'rgba(35,35,35,1.0)', lineDash: null, lineCap: 'butt', 
  lineJoin: 'miter', width: 0}),fill: new ol.style.Fill({color: 'rgba(252,0,0,1.0)'}),
    text: createTextStyle(feature, resolution, labelText, labelFont,
                          labelFill, placement, bufferColor,
                          bufferWidth)
})];
                break;}};

  var style_Area5chamber_14 = function(feature, resolution){
    var context = {
    feature: feature,
    variables: {}
   };
var value = feature.get("Chamber Type");
var labelText = "";
size = 1;
var labelFont = "15px, sans-serif";
var labelFill = "#787878";
var bufferColor = "";
var bufferWidth = 0;
var textAlign = "left";
var offsetX = 0;
var offsetY = 0;
var placement = 'point';
  if (feature.get("Chamber No") !== null) {
    labelText = String(feature.get("Chamber No"));
}

  var style = categories_Area5chamber_14(feature, value, size, resolution, labelText,
                      labelFont, labelFill, bufferColor,
                      bufferWidth, placement);

   return style;
 };

The elements defining the text don't work at all.定义文本的元素根本不起作用。 only labelFill is valid.只有labelFill有效。

I found some solution here:我在这里找到了一些解决方案:

https://gis.stackexchange.com/questions/374510/how-to-make-labels-be-center-justified-in-an-openlayers-web-map https://gis.stackexchange.com/questions/374510/how-to-make-labels-be-center-justified-in-an-openlayers-web-map

but it doesn't really match my example, because I have:但它并不真正符合我的例子,因为我有:

     var style = categories_Area5chamber_14(feature, value, size, resolution, labelText,
                      labelFont, labelFill, bufferColor,
                      bufferWidth, placement);

     return style;

How can I solve this problem?我怎么解决这个问题? I want to change the font, offset and colour but only the colour labelFill is working.我想更改字体、偏移量和颜色,但只有颜色labelFill有效。

In the image below you can see my 2 cases listed in the code.在下图中,您可以看到我在代码中列出的 2 个案例。 One corresponds to the red box with no text (I don't know why?) and another one to black box with a label, which is not editable apart from the colour.一个对应于没有文本的红色框(我不知道为什么?),另一个对应于带有 label 的黑框,除了颜色之外无法编辑。

在此处输入图像描述

The soluton for similar issue is here:类似问题的解决方案在这里:

https://github.com/tomchadwin/qgis2web/issues/627 https://github.com/tomchadwin/qgis2web/issues/627

If the labelFont doesn't return the funt result, we can add it after the feature.get in our labelText .如果 labelFont 没有返回有趣的结果,我们可以在labelText中的feature.get之后添加它。

  var style_Area5chamber_14 = function(feature, resolution){
    var context = {
    feature: feature,
    variables: {}
   };
  var value = feature.get("Chamber Type");
  var labelText = "";
  size = 0;
  var labelFont = "15px \'MS Shell Dlg 2\', sans-serif";
  var labelFill = "#787878";
  var bufferColor = "";
  var bufferWidth = 0;
  var textAlign = "center";
  var offsetX = 0;
  var offsetY = 0;
  var placement = 'point';
    if (feature.get("Chamber No") !== null) {
       labelText = String(feature.get("Chamber No")); labelFont = "15px \'MS Shell Dlg 
 2\', sans-serif";    //adding our font properties again ;
   }


    var style = categories_Area5chamber_14(feature, value, size, resolution, 
 labelText,
                      labelFont, labelFill, bufferColor,
                      bufferWidth, placement);
                
     return style;

    };

In order to text disappear, we must be aware of our zoom level, which we set for our map. If the string is too long, it might be not displayed when exceeds the text bound (assuming, that it's the red box size).为了文本消失,我们必须知道我们为 map 设置的缩放级别。如果字符串太长,当超过文本边界时可能无法显示(假设是红色框大小)。 It happens, when you decide to set a smaller zoom level .当您决定设置较小的缩放级别时,就会发生这种情况。 In the QGIS2web plugin, the maximum zoom level for our map can be 28. If you reduce it to ie 21 or 22, then longer strings might not be visible for us.在QGIS2web 插件中,我们的map 的最大缩放级别可以是28。如果将它缩小到ie 21 或22,那么更长的字符串对我们来说可能不可见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM