Last active
September 27, 2017 00:00
-
-
Save tosipaulo/271cfaa7bbfaf552cd898031f2cb97fb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function initMap () { | |
| let options = { | |
| zoom: 12, | |
| center: {lat:-23.550084,lng:-46.6381307} | |
| } | |
| let map = new google.maps.Map(document.getElementById('map'), options) | |
| const ajax = (url) => $.get(url); | |
| const buscarLocalizacao = () => ajax('http://localhost:2222/data'); | |
| const markupMap = (location) => { | |
| console.log(location.nomefantasia) | |
| return (` | |
| <h1>${location.nomefantasia}</h1> | |
| `) | |
| } | |
| const renderizarLocalizacao = () => { | |
| buscarLocalizacao() | |
| .then(callbackRender) | |
| .then((locations) => { | |
| locations.map((item) => { | |
| addMaker(item) | |
| }) | |
| }) | |
| } | |
| const callbackRender = (data) => { | |
| let locations = []; | |
| data.map((item) => { | |
| let obj = {}; | |
| obj.nomefantasia = item.nomefantasia | |
| obj.coords = {}; | |
| if(typeof item.lat == 'string') { | |
| obj.coords.lat = parseFloat(item.lat, 13); | |
| } | |
| if(typeof item.lng == 'string') { | |
| obj.coords.lng = parseFloat(item.lng, 13); | |
| } | |
| locations.push(obj) | |
| }) | |
| return locations | |
| } | |
| const addMaker = (locations) => { | |
| let marker = new google.maps.Marker({ | |
| position: locations.coords, | |
| map: map, | |
| }) | |
| let infowindow = new google.maps.InfoWindow({ | |
| content: markupMap(locations) | |
| }); | |
| marker.addListener('click', function() { | |
| infowindow.open(map, marker); | |
| }); | |
| } | |
| renderizarLocalizacao() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment