【问题标题】:Leaflet: How to add a number to the center of a circle?传单:如何在圆的中心添加一个数字?
【发布时间】:2017-09-03 09:12:51
【问题描述】:

我目前正在从事一项涉及数字化旅游地图的志愿项目。现在,我需要在其中添加带有数字的圆圈(例如,当您有多个阶段时)。为了了解它的外观,我还附上了带有地图的 pdf。1

所以,目前我的测试圈的脚本是这样的:

var circle = L.circle([48.2353227, 9.6436585],{ color: 'blue', fillColor: 'white', fillOpacity: 1.0, radius: 6 }).addTo(mymap);

我必须在代码中添加什么才能获得例如圆圈内部空白处的“1”?非常感谢!

多米尼克

PS:我很抱歉代码的显示方式。暂时不要这样……

【问题讨论】:

  • 将弹出窗口绑定到标记?并定制它?

标签: javascript dictionary numbers leaflet geometry


【解决方案1】:

您可以将数字放置在样式为圆形的 divIcon 中,而不是矢量圆形。

var icon = L.marker([23.41,79.12], {
  icon: L.divIcon({
      className: 'my-custom-icon',
      html: "5"
  })
});

icon.addTo(map);

图标的一些 CSS:

.my-custom-icon{
  width: 24px !important;
  height: 24px !important;
  margin-left: -12px;
  margin-top: -12px;
  border-radius: 18px;
  border: 2px solid #3F51B5;
  text-align: center;
  color: #3F51B5;
  background-color: #fff;
  font-size: 16px;
}

【讨论】:

  • 完美解决方案!非常感谢! :)
猜你喜欢
  • 2023-03-22
  • 2023-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多