angular - Leaflet Draw'无法绑定到'LeafletDrawOptions'
问题描述
我正在与 Angular 合作,试图让 OpenStreetMaps 使用 @asymmetrik/ngx-leaflet-draw 工作。但是,由于以下错误,我无法使这些选项起作用,并且无法弄清楚。
Error: src/app/app.component.html:7:16 - error NG8002: Can't bind to 'leafletDrawOptions' since it isn't a known property of 'div'.
[leafletDrawOptions]="drawOptions"
我的 app.module
..
import { LeafletModule } from '@asymmetrik/ngx-leaflet';
import { LeafletDrawModule } from '@asymmetrik/ngx-leaflet-draw';
@NgModule({
..
imports: [
..
LeafletModule,
LeafletDrawModule
],
..
})
export class AppModule { }
和component.ts
import { Component } from '@angular/core';
import { tileLayer, latLng, circle, polygon } from 'leaflet';
import * as L from 'leaflet';
import 'leaflet-draw';
leafletOptions: any;
leafletLayers: any;
mapCenter: any;
zoomLevel: any;
layersControl: any;
drawOptions: any;
constructor() {
}
ngOnInit() {
this.leafletLayers = [tileLayer(
'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{ maxZoom: 7, attribution: '...' })];
this.mapCenter = latLng(64.805606, 9.910027);
this.zoomLevel = 5;
this.layersControl = {
baseLayers: {
'Open Street Map': tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 25, maxNativeZoom: 19 }),
}
};
this.drawOptions = {
position: 'topright',
draw: {
marker: {
icon: L.icon({
iconSize: [25, 41],
iconAnchor: [13, 41],
iconUrl: 'assets/marker-icon.png',
shadowUrl: 'assets/marker-shadow.png'
})
},
polyline: false,
circle: {
shapeOptions: {
color: '#aaaaaa'
}
}
}
};
}
似乎与这个问题相似,但从未解决过;https://gis.stackexchange.com/questions/273200/importing-leaflet-draw-ngx-for-angular-4
解决方案
就我而言,我忘记将指令添加leafletDraw
到 div 元素。这是我的 HTML:
<div class="map-container"
leaflet
leafletDraw
[leafletOptions]="options"
(leafletMapReady)="onMapReady($event)"
(leafletMapZoomEnd)="onMapZoomEnd($event)"
[leafletDrawOptions]="drawOptions"
(leafletDrawCreated)="onDrawCreated($event)">
<div [leafletLayer]="drawnItems"></div>
</div>
推荐阅读
- react-native - ListView 已从 ReactNative 中移除
- python - Apache Beam / Dataflow 作业中是否可以有非并行步骤?
- javascript - 如何设置 Atom 编辑器以仅使用 react-native-community eslint-config?
- angularjs - 将 Vue 应用程序集成到 Angular js 应用程序中
- javascript - 使用 Javascript 处理 HTML 和 Swift 之间的交互
- c# - 如何比较两个文本并识别哪些词被添加和哪些被删除
- html - 我想将页脚设置到窗口底部,但它与我的其他 div 重叠?
- mongodb - MongoDB,NodeJs。由于目标机器主动拒绝,无法建立连接。:
- sql - 我需要将 SQL 中的所有活动分配给一个 ID,但目前每个活动都有三个 ID
- php - 如何制作显示所选 ID 的视图?