I am new to both Polymer and Leaflet's web component.
I would like to have a button that toggles the geolocation function given by Leaflet. Using Leaflet in a Javascript/HTML/css application I would know how to do this but I can't get it to work using Polymer 1.0.
Here is my map element. My attempt to call map.locate is commented out in the element registration:
<dom-module id="my-maps">
<style>
...
</style>
<template>
<leaflet-map id="thismap" latitude="{{latitude}}" longitude="{{longitude}}" zoom="14">
<leaflet-geolocation enable-high-accuracy latitude="{{latitude}}" longitude="{{longitude}}" watch="true">
</leaflet-geolocation>
<template is="dom-if" if="{{latitude}}">
<leaflet-marker latitude="{{latitude}}" longitude="{{longitude}}">
</leaflet-marker>
</template>
</leaflet-map>
</template>
<script>
Polymer({
is: "my-maps",
ready: function () {
L.Icon.Default.imagePath="../../bower_components/leaflet/dist/images";
// **this.$.thismap.locate({setView: true}); // not working**
}
});
</script>
</dom-module>
For this example I get this error: Cannot read property 'thismap' of undefined
If I refer to 'this' directly (this.locate()), the error returned is: this.locate is not a function
(this snippet is just a test; ideally the locate function would be called by a click event from the 'geoButton' element) :
<div flex>
<ir-maps id="mymap" class="basemap" flex></ir-maps>
<ir-geoButton class="geoButton" ></ir-geoButton>
</div>