Created
July 20, 2018 11:52
-
-
Save nwrox/ed906de2b7ea093295f29fcff7d9bcc9 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
watch: { | |
isFetching (isFetching) { | |
const { | |
google, | |
googleProps, | |
point, | |
$refs: { | |
input, | |
map | |
} | |
} = this | |
if (!isFetching && google) { | |
const { | |
addListener, | |
TOP_LEFT, | |
trigger | |
} = googleProps() | |
map.$mapPromise | |
.then(map => { | |
const searchBox = google && new google.maps | |
.places | |
.SearchBox(input) | |
map.controls[TOP_LEFT] | |
.push(input) | |
this.markers = [] | |
addListener(searchBox, 'places_changed', () => { | |
const bounds = google && new google.maps | |
.LatLngBounds() | |
const fakePlace = {} | |
const places = searchBox.getPlaces() | |
if (places.length === 0) { | |
return | |
} | |
this.markers = [] | |
places.forEach(place => { | |
const { | |
geometry, | |
geometry: { | |
location, | |
viewport | |
} | |
} = place | |
if (!geometry) { | |
return | |
} | |
// para ter uma ref fora do loop | |
Object.assign(fakePlace, place) | |
viewport | |
? bounds.union(viewport) | |
: bounds.extend(location) | |
}) | |
map.fitBounds(bounds) | |
// Aqui é emulado o evento de fim de arrasto e verifica-se | |
// se o bounds do marcador está presente na visualização | |
// atual do mapa | |
trigger(map, 'dragend') | |
const { | |
geometry: { location } | |
} = fakePlace | |
const marker = { | |
position: location | |
} | |
const mapContains = !map.getBounds() | |
.contains(bounds.getCenter()) | |
if (mapContains) { | |
// limpaMarcadores(arrMarkers) | |
// invalidSearch(input) | |
return | |
} | |
// if (!checkPositionInPolygon(location)) { | |
// limpaMarcadores(arrMarkers) | |
// invalidSearch(input) | |
// | |
// return | |
// } | |
// iframe | |
this.$emit('coordinatesChanged', { | |
latitude: marker.position | |
.lat() | |
.toString(), | |
longitude: marker.position | |
.lng() | |
.toString() | |
}) | |
this.$set(this.markers, 0, marker) | |
}) | |
}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment