2015-10-18 84 views
1

使用聚合物Web組件時,我正在尋找Google地圖標記的單擊事件。我已經看過這個SO question ,但是我的代碼有一些細微的差別,可能會導致問題。我在我的標記中使用了一個模板is =「dom-repeat」,以便我可以使用places API進行搜索。這是我的代碼<map-element></map-element>。問題是我怎樣才能讓markerClicked開火? on-google-map-marker-click似乎並不奏效:聚合物Google地圖標記單擊事件

<dom-module id="map-element"> 
<style> 
    google-map { 
    height: 200px; 
    width: 100%; 

    } 
</style> 
<template> 
<iron-icon icon="icons:search"></iron-icon> 
<input is="iron-input" bind-value="{{bindValue}}" value=" {{value::input}}"> 
<google-map-search map="[[map]]" query="[[bindValue]]" results="{{results}}"></google-map-search> 
<google-map map="{{map}}" latitude="37.77493" disableZoom="true" longitude="-122.41942" fit-to-markers> 
<template is="dom-repeat" items="{{results}}" as="marker"> 
    <google-map-marker latitude="{{marker.latitude}}" longitude="{{marker.longitude}}" clickEvents="true" on-google-map-marker-click="{{markerClicked}}"> 
    <h2>{{marker.name}}</h2> 
     <span>{{marker.formatted_address}}</span> 
    </google-map-marker> 
</template> 
</google-map> 
</template> 
<script> 
    Polymer({ 
    is: "map-element", 

    markerClicked: function(e, detail, sender) { 

     console.log('google_map_marker_click'); 


    } 
}); 
</script> 

</dom-module> 

回答

6

變化clickEventsclick-events。 camelCase的屬性轉換爲帶有破折號的屬性(docs)。

另外,從事件偵聽器中刪除大括號。該語法用於0.5,但不再用於1.0(docs)。

<google-map-marker click-events="true" on-google-map-marker-click="markerClicked">