Created
July 4, 2014 02:49
-
-
Save novascreen/3ace14e1df538c2eaa43 to your computer and use it in GitHub Desktop.
designer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="import" href="../google-map/google-map.html"> | |
<link rel="import" href="../core-list/core-list.html"> | |
<link rel="import" href="../paper-input/paper-input.html"> | |
<link rel="import" href="../core-icon-button/core-icon-button.html"> | |
<link rel="import" href="../speech-mic/speech-mic.html"> | |
<link rel="import" href="../google-map/google-map-search.html"> | |
<polymer-element name="my-element"> | |
<template> | |
<style> | |
:host { | |
position: absolute; | |
width: 100%; | |
height: 100%; | |
box-sizing: border-box; | |
} | |
#google_map { | |
width: 100%; | |
height: 100%; | |
display: block; | |
position: static; | |
} | |
#core_card { | |
position: absolute; | |
width: 300px; | |
max-height: 50%; | |
overflow-y: auto; | |
border-top-left-radius: 2px; | |
border-top-right-radius: 2px; | |
border-bottom-right-radius: 2px; | |
border-bottom-left-radius: 2px; | |
box-shadow: rgba(0, 0, 0, 0.0980392) 0px 2px 4px, rgba(0, 0, 0, 0.0980392) 0px 0px 3px; | |
right: 10px; | |
top: 10px; | |
padding: 10px 20px; | |
background-color: rgb(255, 255, 255); | |
} | |
h3 { | |
position: relative; | |
} | |
core-icon-button { | |
position: absolute; | |
top: -10px; | |
right: 0; | |
} | |
</style> | |
<google-map disabledefaultui id="google_map" | |
on-google-map-ready="{{ initMap }}" | |
latitude="{{ center.latitude }}" | |
longitude="{{ center.longitude }}"> | |
<template repeat="{{m, i in markers}}"> | |
<google-map-marker latitude="{{m.latitude}}" longitude="{{m.longitude}}" title="{{ i + 1 }}" | |
icon="http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld={{ i + 1 }}|FE6256|000000"></google-map-marker> | |
</template> | |
</google-map> | |
<core-card id="core_card"> | |
<h2>Address</h2> | |
<div id="div1" horizontal layout> | |
<paper-input label="Search for an address..." value="{{ $.speech_mic.transcript }}" id="address_input"></paper-input> | |
<speech-mic id="speech_mic"></speech-mic> | |
<google-map-search map="{{ $.google_map.map }}" query="{{ $.address_input.value }}" id="google_map_search"></google-map-search> | |
</div> | |
<div id="div" horizontal layout> | |
<paper-input label="Latitude" floatinglabel inputvalue="{{ center.latitude }}" value="{{ center.latitude }}" id="input_latitude"></paper-input> | |
<paper-input label="Longitude" floatinglabel inputvalue="{{ center.longitude }}" value="{{ center.longitude }}" id="input_longitude"></paper-input> | |
</div> | |
<h2>Markers</h2> | |
<template if="{{ markers.length == 0 }}"> | |
<p>Add markers by clicking on the map</p> | |
</template> | |
<template repeat="{{m, i in markers }}"> | |
<div> | |
<h3> | |
Marker {{ i + 1 }} | |
<core-icon-button icon="remove" id="core_icon_button" theme="core-light-theme" on-click="{{ removeMarker }}" title="Remove"></core-icon-button> | |
</h3> | |
<div id="div" horizontal layout> | |
<paper-input label="Latitude" floatinglabel value="{{ m.latitude }}" id="paper_input" readonly></paper-input> | |
<paper-input label="Longitude" floatinglabel value="{{ m.longitude }}" id="paper_input1" readonly></paper-input> | |
</div> | |
</div> | |
</template> | |
</core-card> | |
</template> | |
<script> | |
Polymer('my-element', { | |
center: { | |
latitude: 1, | |
longitude: 1 | |
}, | |
markers: [], | |
observe: { | |
'$.google_map_search.result': 'updateCenter' | |
}, | |
updateCenter: function (oldValue, newValue) { | |
this.center = newValue | |
}, | |
initMap: function (e, detail, sender) { | |
var self = this | |
this.mapEl = sender | |
// get API object | |
this.mapsApi = this.mapEl.shadowRoot.querySelector('google-maps-api').api | |
// get Map object | |
this.map = this.mapEl.map | |
// add Marker when Map is clicked | |
this.mapsApi.event.addListener(this.map, 'click', function (e) { | |
self.addMarker.call(self, e.latLng.lat(), e.latLng.lng()) | |
}) | |
// set center to current location | |
window.navigator.geolocation.getCurrentPosition(function (result) { | |
self.center = result.coords | |
}) | |
}, | |
addMarker: function (latitude, longitude) { | |
this.markers.push({ | |
latitude: latitude, | |
longitude: longitude | |
}) | |
}, | |
removeMarker: function (e, detail, sender) { | |
//var index = e.target.templateInstance.model.m.index0 | |
//var index = sender.getAttribute('data-index') | |
var index = e.target.templateInstance.model.i | |
var marker = this.mapEl.querySelectorAll('google-map-marker')[index] | |
console.dir(marker) | |
// hide Marker from Map | |
marker.marker.setMap(null) | |
// remove Marker from array (triggers update in Markers list view and on the Map itself) | |
this.markers.splice(index, 1) | |
} | |
}); | |
</script> | |
</polymer-element> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment