diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2022-01-11 12:35:47 +0100 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2022-01-11 12:35:47 +0100 |
commit | 19985dbb8c0aa66dc4bf7905abc1148de909097d (patch) | |
tree | 2cd5a5d20d7e80fc2a51adf60d838d8a2c40999e /main/survey/js/Maps/SearchBox.js | |
download | 1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.tar 1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.tar.gz 1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.tar.bz2 1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.tar.lz 1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.tar.xz 1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.tar.zst 1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.zip |
Diffstat (limited to '')
-rw-r--r-- | main/survey/js/Maps/SearchBox.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/main/survey/js/Maps/SearchBox.js b/main/survey/js/Maps/SearchBox.js new file mode 100644 index 0000000..e71b6ea --- /dev/null +++ b/main/survey/js/Maps/SearchBox.js @@ -0,0 +1,78 @@ +// Author: Uroš Podkrižnik (25.6.2016)
+// Tip vprasanja = 26
+
+// SEARCH BOX
+
+/**
+ * Skripta, ki ustvari in nastavi iskalno polje za zemljevid
+ * @param {type} spremenljivka - int - id spremenljivke
+ * @returns {undefined}
+ */
+function searchBox(spremenljivka, doOnPlacesChanged){
+ //pridobi mapo spremenljivke
+ var map;
+ if(document.getElementById("map_"+spremenljivka))
+ map = document.getElementById("map_"+spremenljivka).gMap;
+ else if(document.getElementById("br_map_"+spremenljivka)){
+ map = document.getElementById("br_map_"+spremenljivka).gMap;
+ }
+ else{
+ map = document.getElementById("maza_map_geofencing").gMap;
+ }
+
+ // Create the search box and link it to the UI element.
+ var input = document.getElementById('pac-input_'+spremenljivka);
+ input.style.display='inline-block';
+ var searchBox = new google.maps.places.SearchBox(input);
+ map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
+
+ // Bias the SearchBox results towards current map's viewport.
+ map.addListener('bounds_changed', function() {
+ searchBox.setBounds(map.getBounds());
+ });
+
+ // Listen for the event fired when the user selects a prediction and retrieve
+ // more details for that place.
+ searchBox.addListener('places_changed', function() {
+ var places = searchBox.getPlaces();
+
+ if (places.length == 0)
+ return;
+
+ //first place has data of geometry
+ if(places[0].geometry){
+ //pozicija v latitude in longitude, ki jo najde
+ var pos = {
+ lat: places[0].geometry.location.lat(),
+ lng: places[0].geometry.location.lng()
+ };
+
+ doOnPlacesChanged(pos, places[0].formatted_address);
+ }
+ //first place does not have data of geometry, do a geocoding from adress
+ else{
+ findPlace(places[0].name, function(pos, formatted_address){
+ doOnPlacesChanged(pos, formatted_address);
+ });
+ }
+ });
+}
+
+/**
+ * Find place from addres
+ * @param {type} address - address to geocode
+ * @param {type} doAfterPlaceFound - callback function to call when place is found
+ * @returns {undefined}
+ */
+function findPlace (address, doAfterPlaceFound){
+ geocoderFromAddress(address, function(place){
+ if(place){
+ var pos = {
+ lat: place.geometry.location.lat(),
+ lng: place.geometry.location.lng()
+ };
+
+ doAfterPlaceFound(pos, place.formatted_address);
+ }
+ });
+}
|