<legend id='eInW0'><style id='eInW0'><dir id='eInW0'><q id='eInW0'></q></dir></style></legend>

    1. <tfoot id='eInW0'></tfoot>
      <i id='eInW0'><tr id='eInW0'><dt id='eInW0'><q id='eInW0'><span id='eInW0'><b id='eInW0'><form id='eInW0'><ins id='eInW0'></ins><ul id='eInW0'></ul><sub id='eInW0'></sub></form><legend id='eInW0'></legend><bdo id='eInW0'><pre id='eInW0'><center id='eInW0'></center></pre></bdo></b><th id='eInW0'></th></span></q></dt></tr></i><div id='eInW0'><tfoot id='eInW0'></tfoot><dl id='eInW0'><fieldset id='eInW0'></fieldset></dl></div>

      <small id='eInW0'></small><noframes id='eInW0'>

        <bdo id='eInW0'></bdo><ul id='eInW0'></ul>
      1. 更改传单标记群集图标颜色,继承其余默认 CSS

        时间:2023-08-09

            <legend id='3oNWz'><style id='3oNWz'><dir id='3oNWz'><q id='3oNWz'></q></dir></style></legend>
                  <tbody id='3oNWz'></tbody>
              • <i id='3oNWz'><tr id='3oNWz'><dt id='3oNWz'><q id='3oNWz'><span id='3oNWz'><b id='3oNWz'><form id='3oNWz'><ins id='3oNWz'></ins><ul id='3oNWz'></ul><sub id='3oNWz'></sub></form><legend id='3oNWz'></legend><bdo id='3oNWz'><pre id='3oNWz'><center id='3oNWz'></center></pre></bdo></b><th id='3oNWz'></th></span></q></dt></tr></i><div id='3oNWz'><tfoot id='3oNWz'></tfoot><dl id='3oNWz'><fieldset id='3oNWz'></fieldset></dl></div>
                <tfoot id='3oNWz'></tfoot>
                  <bdo id='3oNWz'></bdo><ul id='3oNWz'></ul>
                • <small id='3oNWz'></small><noframes id='3oNWz'>

                  本文介绍了更改传单标记群集图标颜色,继承其余默认 CSS 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  所以,我正在尝试更改传单地图中标记群集图标的颜色.我只想更改继承其余默认属性(即形状、文本属性等)的颜色.

                  在这个

                  我知道我必须自定义 iconCreateFunction.我正在尝试这种方式:

                  CSS

                  .foo { 背景颜色:红色;}.bar { 背景颜色:蓝色;}

                  JavaScript

                  var 标记 = L.markerClusterGroup({iconCreateFunction:函数(集群){//这里有一段代码决定了变量 'class_name' 的值是 foo 还是 barreturn L.divIcon({ className: "marker-cluster-medium "+class_name});}});

                  不幸的是,该解决方案不起作用并导致图标呈现丑陋.

                  我怎样才能改变默认markercluster图标的颜色?

                  解决方案

                  你的 iconCreateFunction 应该是这样的

                  iconCreateFunction: function (cluster) {var childCount = cluster.getChildCount();var c = 'marker-cluster-';if (childCount < 10) {c += '小';}否则 if (childCount < 100) {c += '中等';}别的 {c +='大';}return new L.DivIcon({ html: '<div><span>' + childCount + '</span></div>',className: 'marker-cluster' + c, iconSize: new L.Point(40, 40) });}

                  给 css 一些类似的东西

                  .marker-cluster-small {背景颜色:rgba(218, 94, 94, 0.6);}.marker-cluster-小 div {背景颜色:rgba(226, 36, 36, 0.6);}.marker-cluster-medium {背景色:rgba(241, 211, 87, 0.6);}.marker-cluster-medium div {背景颜色:rgba(240, 194, 12, 0.6);}.marker-cluster-large {背景色:rgba(253, 156, 115, 0.6);}.marker-cluster-大 div {背景色:rgba(241, 128, 23, 0.6);}

                  完整的工作示例请参见下面的 plunker

                  https://plnkr.co/edit/GvDbB1rzIZ4bvIkQjM0p?p=preview

                  So, I'm trying to change the color of the markercluster icons in a leaflet map. I just want to change the color inheriting the rest of the default properties (i.e., shape, text properties, etc...).

                  In this an example, there is something similar to what I want to get, but they define a brand new CSS class without using the default icons styling. What I need is something like this but with custom colors:

                  I do know that I have to customize iconCreateFunction. I'm trying in this way:

                  CSS

                  .foo { background-color: red;}
                  .bar { background-color: blue;}
                  

                  JavaScript

                  var markers = L.markerClusterGroup({
                      iconCreateFunction: function(cluster) {
                          // here there is a piece code that determines the value of the variable 'class_name' is either foo or bar
                          return L.divIcon({ className: "marker-cluster-medium "+class_name});
                      }
                  });
                  

                  Unfortunately, that solution does not work and leads to a ugly icon rendering.

                  How can I just change the color of the default markercluster icons?

                  解决方案

                  your iconCreateFunction should look some thing like this

                  iconCreateFunction: function (cluster) {
                   var childCount = cluster.getChildCount();
                   var c = ' marker-cluster-';
                   if (childCount < 10) {
                     c += 'small';
                   } 
                   else if (childCount < 100) {
                     c += 'medium';
                   } 
                   else {
                     c += 'large';
                   }
                  
                   return new L.DivIcon({ html: '<div><span>' + childCount + '</span></div>', 
                    className: 'marker-cluster' + c, iconSize: new L.Point(40, 40) });
                   }
                  

                  and give css some thing like this

                  .marker-cluster-small {
                  background-color: rgba(218, 94, 94, 0.6);
                  }
                  .marker-cluster-small div {
                  background-color: rgba(226, 36, 36, 0.6);
                  }
                  .marker-cluster-medium {
                  background-color: rgba(241, 211, 87, 0.6);
                  }
                  .marker-cluster-medium div {
                  background-color: rgba(240, 194, 12, 0.6);
                  }
                  
                  .marker-cluster-large {
                  background-color: rgba(253, 156, 115, 0.6);
                  }
                  .marker-cluster-large div {
                  background-color: rgba(241, 128, 23, 0.6);
                  }
                  

                  see the below plunker for complete working example

                  https://plnkr.co/edit/GvDbB1rzIZ4bvIkQjM0p?p=preview

                  这篇关于更改传单标记群集图标颜色,继承其余默认 CSS 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:触发点击传单标记 下一篇:检查一个多边形点是否在传单中的另一个内部

                  相关文章

                  最新文章

                • <tfoot id='knPsN'></tfoot>
                  • <bdo id='knPsN'></bdo><ul id='knPsN'></ul>
                  <legend id='knPsN'><style id='knPsN'><dir id='knPsN'><q id='knPsN'></q></dir></style></legend>

                    <small id='knPsN'></small><noframes id='knPsN'>

                    <i id='knPsN'><tr id='knPsN'><dt id='knPsN'><q id='knPsN'><span id='knPsN'><b id='knPsN'><form id='knPsN'><ins id='knPsN'></ins><ul id='knPsN'></ul><sub id='knPsN'></sub></form><legend id='knPsN'></legend><bdo id='knPsN'><pre id='knPsN'><center id='knPsN'></center></pre></bdo></b><th id='knPsN'></th></span></q></dt></tr></i><div id='knPsN'><tfoot id='knPsN'></tfoot><dl id='knPsN'><fieldset id='knPsN'></fieldset></dl></div>