Var Map, CachedGeoJson;
var promise = that.map.data.loadGeoJson('https://api.myjson.com/bins/31e3j');
promise.then(function(data) {
cachedGeoJson = data;
map.data.addGeoJson(
'https://api.myjson.com/bins/31e3j',
{ idPropertyName: "id"}
);
答案 0 :(得分:0)
您需要关闭您的功能,修复如下语法:
Var Map, CachedGeoJson;
var promise = that.map.data.loadGeoJson('https://api.myjson.com/bins/31e3j');
promise.then(function(data) {
cachedGeoJson = data;
map.data.addGeoJson(
'https://api.myjson.com/bins/31e3j',
{ idPropertyName: "id"}
);
});
答案 1 :(得分:0)
您可以尝试创建一个不同的函数来创建promise对象,因为google loadGeoJson
不会返回promise对象。
function loadGeoJson(url, options) {
var promise = new Promise(function (resolve, reject) {
try {
that.map.data.loadGeoJson(url, options, function (features) {
resolve(features);
});
} catch (e) {
reject(e);
}
});
return promise;
}
var promise = loadGeoJson('studs.json');
promise.then(function (features) {
map.data.addGeoJson(
'https://api.myjson.com/bins/31e3j',
{ idPropertyName: "id"}
);
});
答案 2 :(得分:0)
您可以查看承诺中存在哪些属性。
for (var property in promise) {
if (promise.hasOwnProperty(property)){
alert(property);
}
}