2015-05-30 151 views
0

在我的索引文件中,我使用了兩種定製聚合物元素;地理位置和gis服務。第一個目的是獲取用戶的當前位置,然後將緯度和經度輸入到gis-service。索引文件的 部分:聚合物:確保一種聚合物元素先於另一種聚合物元素執行

<geo-location watchpos></geo-location> 
<template is="auto-binding"> 
    <gis-service id="gservice" latitude="{{latitude}}" longitude="{{longitude}}">Use lat and long here</gis-service> 
</template> 

我通過更新GIS服務的緯度和經度:

var t = document.querySelector('template'); 
var geolocation = document.querySelector('geo-location'); 
geolocation.addEventListener('geo-response', function(e) { 
      t.latitude = this.latitude.toFixed(6); 
      t.longitude = this.longitude.toFixed(6); 
}); 

然而,當緯度和經度被傳遞到GIS服務就說明他們是不確定的。我懷疑在分配緯度和經度之前調用/執行gis-service。所以我的問題是,如何確保在將地理位置元素分配給gis-service元素之前調用地理位置元素(以獲取經度和緯度)?

回答

0

您可以使用conditional template來檢查是否存在某個值。

所以,這將是爲:

<template if="{{latitude}}"> 
    <template if="{{longitude}}"> 
    <gis-service id="gservice" latitude="{{latitude}}" longitude="{{longitude}}">Use lat and long here</gis-service> 
    </template></template>