【问题标题】:Why this ngx-leaflet params are not working properly?为什么这个 ngx-leaflet 参数不能正常工作?
【发布时间】:2020-10-27 09:38:57
【问题描述】:

我正在尝试在Angularngx-angular 中的leaflet 项目中尽可能地完成所有工作,但找不到使它们正常工作的方法。

这是我的参数代码:

zoomControl = {position: 'bottomright'};

readonly drawOptions = {
position: 'topright',
draw: {
  circle: false,
  circlemarker: false
},
edit: {
  featureGroup: this.drawItems,
  remove: false
  }
};

正如您在此快照中所见,这不起作用,position 参数被忽略,circle and circlemarker 属性也被忽略。

当然,它们包含在具有ngx-leaflet 属性调用的div 映射标记中,我想知道是否有可能在不使用纯JS 的情况下使它们工作。

【问题讨论】:

  • 请堆叠闪电战
  • @alessandro 不知道谁使用 stackblitz 以及是否可以安装 npm 库,抱歉
  • 我建议在这里玩:stackblitz.com/edit/angular-9-starter 对你有很大帮助 一切顺利
  • 好吧,我会试试@alessandro
  • 对不起@alessandro 但不能在那里实现它,这让我很紧张

标签: angular typescript leaflet ngx-leaflet ngx-leaflet-draw


【解决方案1】:

使用ngx-leaflet-draw 库可以实现您的目标。

在此处包含 leafletDrawOptions 以等于在您的组件上定义的变量 drawOptions

<div
  leaflet
  style="height: 400px;"
  leafletDraw
  [leafletOptions]="options"
  [leafletDrawOptions]="drawOptions"
  (leafletDrawCreated)="onDrawCreated($event)"
>
  <div [leafletLayer]="drawnItems"></div>
</div>

在您的组件中,您可以定义哪些选项将是可见的,就像您在上面的示例中尝试的那样:

{
    position: "topleft",
    draw: {
      ...,
      polyline: false,
      circle: false,
      circlemarker: false,
      rectangle: {
        shapeOptions: {
          color: "#85bb65"
        }
      }
    },
    edit: {
      featureGroup: this.drawnItems,
      remove: false
    }
  };

这里是关于如何安装 ngx-leaflet-drawguide 和这里是 demo 来观看它。不要担心绘图图标不可见。在您的应用程序中应该没问题。它与codesandbox有关。

【讨论】:

  • 谢谢你的回答,我昨天解决了,但正如你所说的
猜你喜欢
  • 2021-01-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-30
  • 2023-02-20
  • 1970-01-01
  • 2022-10-23
相关资源
最近更新 更多