n0d*_*aft 5 leaflet typescript webpack leaflet-routing-machine angular
我用这个种子开始使用Angular 2 Typescript和Webpack:https://github.com/haoliangyu/angular2-leaflet-starter.
我是大多数使用过的工具和技术的新手(Angular 2,Typescript,Webpack).虽然我越来越了解这些,但似乎我还没有掌握如何包含第三方非类型的JS库:
我想将leaflet-routing-machine.js包含到我的项目中.据我所知,虽然确实存在传单的类型,但是传单路由机并不存在.
我安装了包,npm install
并添加了所需的快速启动代码,以显示路径.
map.service.ts
/// <reference path="../../typings/leaflet/leaflet.d.ts"/>
import {Injectable} from 'angular2/core';
import {Map} from 'leaflet';
Injectable()
export class MapService {
map: Map; // holds reference to the normal leaflet map object
showRoute(){
L.Routing.control({
waypoints: [
L.latLng(47.569198, 7.5874886),
L.latLng(47.5685418, 7.5886755)
]
}).addTo(this.map);
}
}
Run Code Online (Sandbox Code Playgroud)
我遇到的错误npm start
是:
ERROR in ./app/services/map.service.ts
(56,11): error TS2339: Property 'Routing' does not exist on type 'typeof L'.
Run Code Online (Sandbox Code Playgroud)
据我了解,我不应该在index.html中包含JS文件,因为这应该由webpack自动完成.接下来的事实,我通常不知道该如何包括但分型(答案像第三方库这并没有帮助)似乎我的情况有点不同,因为L
对象是标准的小册子,不知道Routing
属性.我以某种方式理解,因为我没有看到路由机器库如何扩展传单库.
有什么建议?
我没有使用过 Angular 2,也没有使用过 TypeScript,但我怀疑 TypeScript 不喜欢 LRM 将自身附加到L
对象/命名空间。
请注意,LRM 还将自身导出为普通的 CommonJS 模块,因此您可以执行类似的操作而不是使用L.Routing.Control
:
var L = require('leaflet');
var Routing = require('leaflet-routing-machine');
var map = L.map(...);
var routingControl = Routing.control({ ... });
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2765 次 |
最近记录: |