127 lines
3.5 KiB
Plaintext
127 lines
3.5 KiB
Plaintext
<% include partials/navBar %>
|
|
|
|
<div class="row center-align">
|
|
<div id="floating-panel">
|
|
<input id="address" type="textbox" value="">
|
|
<input id="submit" type="button" value="Trazi">
|
|
</div>
|
|
<div id="map"></div>
|
|
</div>
|
|
<form method="POST" id="form-map-output">
|
|
<div class="row center-align">
|
|
<div class="col s6 push-s3">
|
|
<a id="btnsubmit" 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 />
|
|
</form>
|
|
<script>
|
|
|
|
|
|
var map;
|
|
var municipality = "<%= municipality%>";
|
|
var defaultAddress = document.getElementById('address');
|
|
var latLngRestrictions = [];
|
|
|
|
var BOSNIA_BOUNDS = {
|
|
north: 45.70,
|
|
south: 41.69,
|
|
west: 15.55,
|
|
east: 20.77,
|
|
};
|
|
|
|
function initMap() {
|
|
var geocoder = new google.maps.Geocoder();
|
|
|
|
document.getElementById('submit').addEventListener('click', function () {
|
|
geocodeAddress(geocoder, map, false, latLngRestrictions);
|
|
});
|
|
|
|
|
|
|
|
defaultAddress.value = municipality;
|
|
geocodeAddress(geocoder, map, true);
|
|
|
|
$(document).ready(() => {
|
|
$("#btnsubmit").click(() => {
|
|
var bounds = map.getBounds();
|
|
|
|
$("#north").val(map.getBounds().getNorthEast().lat());
|
|
$("#south").val(map.getBounds().getSouthWest().lat());
|
|
$("#east").val(map.getBounds().getNorthEast().lng());
|
|
$("#west").val(map.getBounds().getSouthWest().lng());
|
|
|
|
$("#form-map-output").submit();
|
|
});
|
|
});
|
|
|
|
|
|
}
|
|
|
|
function geocodeAddress(geocoder, resultsMap, isInit, geocoderRestrictions) {
|
|
|
|
|
|
|
|
var address = document.getElementById('address').value;
|
|
let geocoderOptions = geocoderRestrictions
|
|
? { 'address': address, 'bounds': geocoderRestrictions }
|
|
: { 'address': address }
|
|
|
|
geocoder.geocode(geocoderOptions, function (results, status) {
|
|
if (status === 'OK') {
|
|
|
|
var bounds = results[0].geometry.bounds;
|
|
|
|
var resultBounds = new google.maps.LatLngBounds(
|
|
|
|
results[0].geometry.viewport.getSouthWest(),
|
|
results[0].geometry.viewport.getNorthEast()
|
|
);
|
|
|
|
if (isInit) {
|
|
map = new google.maps.Map(document.getElementById('map'), {
|
|
zoom: 11,
|
|
});
|
|
resultsMap = map
|
|
}
|
|
|
|
// map.fitBounds(resultBounds);
|
|
resultsMap.setCenter(results[0].geometry.location);
|
|
|
|
if (isInit) {
|
|
|
|
latLngRestrictions = new google.maps.LatLngBounds(
|
|
new google.maps.LatLng(bounds.getSouthWest().lat(), bounds.getSouthWest().lng()),
|
|
new google.maps.LatLng(bounds.getNorthEast().lng(), bounds.getNorthEast().lng()));
|
|
|
|
|
|
let latLngRestrictionsa = {
|
|
west: bounds.getSouthWest().lng(),
|
|
east: bounds.getNorthEast().lng(),
|
|
north: bounds.getNorthEast().lat(),
|
|
south: bounds.getSouthWest().lat()
|
|
}
|
|
map.setOptions({
|
|
restriction: {
|
|
latLngBounds: latLngRestrictionsa,
|
|
strictBounds: false,
|
|
}
|
|
})
|
|
} else {
|
|
resultsMap.setZoom(17);
|
|
}
|
|
|
|
} else {
|
|
alert('Geocode was not successful for the following reason: ' + status);
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAna8ohfV2HBMcxGk_29vqxU5Z_bDickqg&callback=initMap" async
|
|
defer></script>
|
|
</div> |