问题描述
我正在尝试通过leaflet
在Angular
的{{1}}项目中进行一切工作,但是找不到使它们正常工作的方法。
ngx-angular
正如您在此快照上看到的那样,这行不通,zoomControl = {position: 'bottomright'};
readonly drawOptions = {
position: 'topright',draw: {
circle: false,circlemarker: false
},edit: {
featureGroup: this.drawItems,remove: false
}
};
参数被忽略,position
属性也被忽略。
当然,它们包含在具有circle and circlemarker
属性调用的div
地图标记中,我想知道是否有可能在不使用纯JS的情况下使它们工作。
解决方法
使用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
}
};
这里是guide,说明如何安装ngx-leaflet-draw
,下面是demo,以了解其实时运行。不必担心图形图标不可见。在您的应用中应该没问题。它与codeandbox有关。