130 lines
3.9 KiB
Plaintext
130 lines
3.9 KiB
Plaintext
<% include partials/navBar %>
|
|
|
|
<div class="row center-align">
|
|
Područje na mapi će biti uključeno u pretragu. Namjestite mapu na ulice
|
|
koje želite da budu vidljive.
|
|
</div>
|
|
<div class="row center-align">
|
|
<div class="col s9 m10 l11 xl11">
|
|
<input id="autocompleteInput" placeholder="Lokacija..." type="text" />
|
|
</div>
|
|
<div class="col s1 m1 l1 xl1">
|
|
<a id="locateMe" class="btn-floating waves-effect waves-light"><i class="material-icons right">gps_fixed</i></a>
|
|
</div>
|
|
</div>
|
|
<div class="row center-align">
|
|
<div class="col s12">
|
|
<div id="map"></div>
|
|
</div>
|
|
</div>
|
|
<br/>
|
|
</div>
|
|
<form method="POST" id="form-map-output">
|
|
<div class="row center-align">
|
|
<div class="col s6 push-s3">
|
|
<a id="submit" href="#" class="welcome-center-button waves-effect waves-light btn">Dalje</a>
|
|
</div>
|
|
</div>
|
|
<input type="hidden" name="north" id="north" />
|
|
<input type="hidden" name="south" id="south" />
|
|
<input type="hidden" name="east" id="east" />
|
|
<input type="hidden" name="west" id="west" />
|
|
<input type="hidden" name="locationInput" id="locationInput" />
|
|
<input type="hidden" name="locationInputData" id="locationInputData" />
|
|
</form>
|
|
<script>
|
|
let autocomplete;
|
|
let map;
|
|
let places;
|
|
let geocoder;
|
|
|
|
function locateMe() {
|
|
if (navigator.geolocation) {
|
|
|
|
const onLocationSuccess = (position) => {
|
|
const coordinates = position && position.coords ? position.coords : null;
|
|
if (coordinates){
|
|
const longitude = coordinates.longitude || null;
|
|
const latitude = coordinates.latitude || null;
|
|
|
|
if (longitude && latitude && map){
|
|
map.setCenter({lat: latitude, lng: longitude});
|
|
map.setZoom(16);
|
|
}
|
|
}
|
|
};
|
|
|
|
navigator.geolocation.getCurrentPosition(onLocationSuccess);
|
|
}
|
|
}
|
|
|
|
function initMap() {
|
|
const BOSNIA_BOUNDS = {
|
|
north: 45.70,
|
|
south: 41.69,
|
|
west: 15.55,
|
|
east: 20.77,
|
|
};
|
|
const SARAJEVO_COORDINATES = {
|
|
lat: 43.85,
|
|
lng: 18.41,
|
|
};
|
|
|
|
const mapElement = document.getElementById('map');
|
|
const restrictMapPanningToBosniaOnly = {
|
|
latLngBounds: BOSNIA_BOUNDS,
|
|
strictBounds: true,
|
|
};
|
|
const initialMapParams = {
|
|
center: SARAJEVO_COORDINATES,
|
|
zoom: 12,
|
|
restriction: restrictMapPanningToBosniaOnly,
|
|
mapTypeControl: false,
|
|
panControl: false,
|
|
zoomControl: true,
|
|
streetViewControl: false
|
|
};
|
|
map = new google.maps.Map(mapElement, initialMapParams);
|
|
|
|
const inputElement = document.getElementById('autocompleteInput');
|
|
const restrictAutocompleteResultsToBosniaOnly = {'country': 'ba'};
|
|
const initialAutocompleteParams = {
|
|
types: ['geocode'],
|
|
componentRestrictions: restrictAutocompleteResultsToBosniaOnly,
|
|
fields: ['geometry', 'types', 'address_components']
|
|
};
|
|
|
|
autocomplete = new google.maps.places.Autocomplete(inputElement, initialAutocompleteParams);
|
|
autocomplete.bindTo('bounds', map);
|
|
autocomplete.addListener('place_changed', onPlaceChanged);
|
|
}
|
|
|
|
function onPlaceChanged() {
|
|
const place = autocomplete.getPlace();
|
|
if (place.geometry) {
|
|
map.fitBounds(place.geometry.viewport);
|
|
map.setZoom(map.getZoom() + 1);
|
|
$("#locationInputData").val(JSON.stringify(place));
|
|
}
|
|
}
|
|
|
|
$(document).ready(() => {
|
|
$("#submit").click(() => {
|
|
const mapBounds = map.getBounds();
|
|
|
|
$("#north").val(mapBounds.getNorthEast().lat());
|
|
$("#south").val(mapBounds.getSouthWest().lat());
|
|
$("#east").val(mapBounds.getNorthEast().lng());
|
|
$("#west").val(mapBounds.getSouthWest().lng());
|
|
|
|
$("#locationInput").val(document.getElementById('autocompleteInput').value);
|
|
|
|
$("#form-map-output").submit();
|
|
});
|
|
document.getElementById("locateMe").addEventListener("click", locateMe);
|
|
});
|
|
</script>
|
|
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAna8ohfV2HBMcxGk_29vqxU5Z_bDickqg&language=bs&libraries=places&callback=initMap" async
|
|
defer></script>
|
|
</div>
|