[英]Openlayers javascript library in typescript
we are working on a project using typescript. 我们正在使用打字稿进行项目。 This is out first project with typescript.
这是第一个带有打字稿的项目。 In this project we need to connect to a WFS server and this returns GML to us.
在这个项目中,我们需要连接到WFS服务器,这会将GML返回给我们。 Now to parse GML, we think of using the OpenLayers javascript library.
现在解析GML,我们考虑使用OpenLayers javascript库。 I know there is a DefinitelyTyped version of Openlayers, but the GML parsing isn't ready yet.
我知道有Openlayers的DefinitelyTyped版本,但是GML解析尚未准备好。
So we tried to the javascript files. 所以我们尝试了javascript文件。 But i think we are missing something, because we are getting an error: Openlayers is undifined.
但是我认为我们缺少了一些东西,因为我们遇到了一个错误:Openlayers没有定义。
This is our code: 这是我们的代码:
module PP.Data {
declare var OpenLayers: any;
export class WebRequest {
public GetGML(url: string): XMLDocument {
var retour: XMLDocument;
var _this = this;
$.ajax({
url: url,
type: 'GET',
crossDomain: true,
cache: false,
async: false,
dataType: 'xml'
}).done(function (data) {
var format = new OpenLayers.Format.GML();
retour = format.read(data);
});
return retour;
}
}
}
So the error starts when we try to create an instance of GML. 因此,当我们尝试创建GML实例时,该错误开始。
Any ideas? 有任何想法吗?
Thanks! 谢谢!
OpenLayers is undefined.
OpenLayers未定义。
Make sure OpenLayers is included (eg using a script tag) before you try to use it from typescript 在尝试从打字稿中使用OpenLayers 之前,请确保其中已包含OpenLayers(例如,使用脚本标签)
You are effectively returning undefined
here (as retour isn't assigned before its returned). 您实际上在这里返回的是
undefined
(因为retour在返回之前未分配)。
.done(function (data) {
var format = new OpenLayers.Format.GML();
retour = format.read(data);
});
return retour;
You should return the promise ie. 您应该退还诺言 。 the return value of the
.done
function OR have a callback. .done
函数的返回值,或者具有回调。 It needs to be async all the way down. 它需要一直保持异步状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.