传单 属性-导入时不存在路由类型
leaflet Property-Routing-does-not-exist-on-type-typeof-import
我已经发了 post 但没有收到任何回复。我是传单的新手,不知道发生了什么或为什么。我相信我添加了文档中说要添加的所有内容,但我仍然遇到错误。
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.4/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.3.4/dist/leaflet.js"></script>
import L from 'leaflet';
ERROR TypeError: Cannot read property 'control' of undefined
我的代码在这里:
var polylineRouteB = L.Routing.control({...});
为了使您的 L.Routing class 不被未定义,您需要获取对地图的引用并在加载地图时在那里使用它,但在此步骤之前您需要配置 angular.json 在资产文件夹中搜索标记图标,否则 this issue arises。
import {
latLng,
tileLayer,
Icon, icon, Marker
} from 'leaflet';
import 'leaflet';
import 'leaflet-routing-machine';
declare let L;
...
// Override default Icons
private defaultIcon: Icon = icon({
iconUrl: 'assets/marker-icon.png',
shadowUrl: 'assets/marker-shadow.png'
});
ngOnInit() {
Marker.prototype.options.icon = this.defaultIcon;
}
onMapReady(map: L.Map) {
L.Routing.control({
waypoints: [
L.latLng(57.74, 11.94),
L.latLng(57.6792, 11.949)
],
routeWhileDragging: true
}).addTo(map);
}
模板
<div style="height: 800px;"
leaflet
[leafletOptions]="options"
(leafletMapReady)="onMapReady($event)">
</div>
另请注意,他的库 不允许对服务器进行无限请求 因此它 returns 经常有 429 个 HTTP 响应。
我已经发了 post 但没有收到任何回复。我是传单的新手,不知道发生了什么或为什么。我相信我添加了文档中说要添加的所有内容,但我仍然遇到错误。
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.4/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.3.4/dist/leaflet.js"></script>
import L from 'leaflet';
ERROR TypeError: Cannot read property 'control' of undefined
我的代码在这里:
var polylineRouteB = L.Routing.control({...});
为了使您的 L.Routing class 不被未定义,您需要获取对地图的引用并在加载地图时在那里使用它,但在此步骤之前您需要配置 angular.json 在资产文件夹中搜索标记图标,否则 this issue arises。
import {
latLng,
tileLayer,
Icon, icon, Marker
} from 'leaflet';
import 'leaflet';
import 'leaflet-routing-machine';
declare let L;
...
// Override default Icons
private defaultIcon: Icon = icon({
iconUrl: 'assets/marker-icon.png',
shadowUrl: 'assets/marker-shadow.png'
});
ngOnInit() {
Marker.prototype.options.icon = this.defaultIcon;
}
onMapReady(map: L.Map) {
L.Routing.control({
waypoints: [
L.latLng(57.74, 11.94),
L.latLng(57.6792, 11.949)
],
routeWhileDragging: true
}).addTo(map);
}
模板
<div style="height: 800px;"
leaflet
[leafletOptions]="options"
(leafletMapReady)="onMapReady($event)">
</div>
另请注意,他的库 不允许对服务器进行无限请求 因此它 returns 经常有 429 个 HTTP 响应。