var ib;
var ir;
//var geocoder = new google.maps.Geocoder();
var map;
var popis_vysilac;
var chart = null;
//var geocoderService = null;
var mousemarker = null;
var markers_elevace = [];
var marker_wifibod = [];
var markers_wifibody = [];
var marker_kdomy = [];
var markers_kdomy = [];
var marker_reklama = [];
var markers_klienti = [];
var markers_klient = [];
var marker_klienti_sektor = [];
var markers_klienti_sektor = [];
var markers_reklama = [];
var cityCircles = [];
var diamonds = [];
var polyline = null;
var diamond = null;
var cityCircle = null;
var elevations = null;
var SAMPLES = 500;
var image;
var infoWindows = [];
//var propustnost_wb;
var q;
var central_div;
var infowi;
var elevationService;
var directionsService;
// HLAVNÍ SKRIPT VSTUP
///////////////////////////////////
// Load the Visualization API and the piechart package.
//google.load("visualization", "1", {packages: ["columnchart"]});
google.charts.load('current', {packages: ['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
//google.charts.setOnLoadCallback(initMap);
function initMap() {
var initCenter = new google.maps.LatLng(50.569712, 15.067168);//By default MH
map = new google.maps.Map(document.getElementById('googlemaps'), {
zoom: 11,
maxZoom:20,
center: initCenter,
//mapTypeId: google.maps.MapTypeId.ROADMAP
mapTypeId: 'terrain'
});
elevationService = new google.maps.ElevationService;
directionsService = new google.maps.DirectionsService;
infowi = new google.maps.InfoWindow()
image = new google.maps.MarkerImage('wifibod-icon.png',null, null, new google.maps.Point(10, 20), new google.maps.Size(20, 20));
//chart = new google.charts.Bar(document.getElementById('chart_div'));
load_wifibody("wifibody");
// Vložit Marker
map.addListener("rightclick", (event) => {
var gps =event.latLng;
//alert (gps);
var outgps = String(gps).replace("(","").replace(")","");
add_marker_search_item(outgps,'popis',"");
//if($('#elevace').not(':checked').length) { }
});
map.addListener("dblclick", (event) => {
var gps =event.latLng;
var zoom = map.getZoom();
//alert (zoom);
if (zoom==18) {
var outgps = String(gps).replace("(","").replace(")","");
add_marker_search_item(outgps,'popis',"");
}
//if($('#elevace').not(':checked').length) { }
});
loadExample();
// Elevace nahlášení pozice
var q = document.getElementById('search_address');
if (q.value!="") {searchit();}
}
function load_wifibody(zdroj) {
$.ajax( {
url : "gmap.php?zdroj="+zdroj,
type : "GET",
success : function(data) {
// get the data string and convert it to a JSON object.
var jsonData = JSON.parse(data);
var latitude = new Array();
var longitude = new Array();
var propustnost_wb = new Array();
var name = new Array();
var logo = new Array();
var pokryti = new Array();
var idw = new Array();
var rozsah = new Array();
var pauza;
var i = 0;
var j = 0;
var k = 0;
var l = 0;
var u = 0;
var w = 0;
var r = 0;
$.each(jsonData, function(Idx, Value) {
$.each(Value, function(x, y) {
//Creating an array of latitude, logitude
if(x == 'Lat') { i = i + 1; latitude[i] = y; }
if(x == 'Lng') { j = j + 1; longitude[j] = y; }
if(x == 'Name') { k = k + 1; name[k] = y; }
if(x == 'pokryti') { l = l + 1; pokryti[l] = y; }
if(x == 'idw') { u = u + 1; idw[u] = y; }
if(x == 'propustnost_wb') { w =w+1; propustnost_wb[w] = y; }
if(x == 'rozsah') { r =r+1; rozsah[r] = y; }
if (latitude[i]<50.417269 && longitude[j]<15.029640) {
//$('.cannotfind').append(name[k]+" "+latitude[i]+" / "+longitude[j]+"
");
}
});
});
//$("#googlemaps").html('');
//passing the array to initialize function, where our map will be formed
for(var a = 1; a < idw.length; ++a) {
createMarkers( idw[a], map, name[a], latitude[a], longitude[a], ib, propustnost_wb[a], rozsah[a], zdroj, pokryti[a], a * 0);
}
}
});
}
function loadExample() {
reset();
//map.setMapTypeId(google.maps.MapTypeId.TERRAIN);
var bounds = new google.maps.LatLngBounds();
updateElevation();
google.maps.event.addListener(map, 'click', function(event) {
console.log(event.latLng);
addMarker(event.latLng, true);
});
}
// Clear all overlays, reset the array of points, and hide the chart
function reset() {
if (polyline) {
polyline.setMap(null);
}
for (var i in markers_elevace) {
markers_elevace[i].setMap(null);
}
markers_elevace = [];
document.getElementById('chart_div').style.display = 'none';
}
function updateElevation() {
if (markers_elevace.length > 1) {
var travelMode = document.getElementById("mode").value;
if (travelMode != 'direct') {
calcRoute(travelMode);
} else {
var latlngs = [];
for (var i in markers_elevace) {
latlngs.push(markers_elevace[i].getPosition())
}
elevationService.getElevationAlongPath({
path: latlngs,
samples: SAMPLES
}, plotElevation);
}
}
}
// Takes an array of ElevationResult objects, draws the path on the map
// and plots the elevation profile on a GViz ColumnChart
function plotElevation(results) {
elevations = results;
var path = [];
for (var i = 0; i < results.length; i++) {
path.push(elevations[i].location);
}
if (polyline) {
polyline.setMap(null);
}
var lineSymbol = {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW
};
polyline = new google.maps.Polyline({
path: path,
zIndex: 300,
strokeColor: "#000000",
icons: [{
icon: lineSymbol,
offset: '100%'
}],
map: map});
var data = new google.visualization.DataTable();
//var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
data.addColumn('string', 'Sample');
data.addColumn('number', 'elevace');
for (var i = 0; i < results.length; i++) {
data.addRow(['', elevations[i].elevation], 'fill-color: #800080; stroke-width: 0');
}
//alert(screen.width-150);
var vzdalenost = google.maps.geometry.spherical.computeDistanceBetween(markers_elevace[0].getPosition(), markers_elevace[1].getPosition());
var azimut = google.maps.geometry.spherical.computeHeading(markers_elevace[0].getPosition(), markers_elevace[1].getPosition());
document.getElementById('chart_div').style.display = 'block';
chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, {
width: screen.width-150,
height: 190,
bar: {groupWidth: '90%'},
titleFontSize: 14,
legend: 'none',
titleY: 'elevace (m)',
title: Math.round(vzdalenost)+' m'+ ', azimut '+Math.round(azimut)+'°',
focusBorderColor: '#FFD800'
});
google.visualization.events.addListener(chart, 'onmouseover', function(e) {
if (mousemarker == null) {
mousemarker = new google.maps.Marker({
position: elevations[e.row].location,
map: map });
} else {
infowi.open(map, mousemarker);
mousemarker.setPosition(elevations[e.row].location);
var el = Math.round(elevations[e.row].elevation);
var vzd = google.maps.geometry.spherical.computeDistanceBetween(markers_elevace[0].getPosition(), mousemarker.getPosition());
infowi.setContent(Math.round(vzd)+" m, "+el+" n.m.");
}
});
}
// Remove the green rollover marker when the mouse leaves the chart
function clearMouseMarker() {
if (mousemarker != null) {
mousemarker.setMap(null);
mousemarker = null;
}
}
// Add a marker and trigger recalculation of the path and elevation
function addMarker(latlng, doQuery) {
if ($(".ui.icon.orange.resize.horizontal")[0]) {
var marker_elevace = new google.maps.Marker({
position: latlng,
map: map,
zIndex: 300,
draggable: true
})
google.maps.event.addListener(marker_elevace, 'dragend', function(e) {
updateElevation();
});
markers_elevace.push(marker_elevace);
if (doQuery) {
updateElevation();
}
}
}
function calcRoute(travelMode) {
var origin = markers_elevace[0].getPosition();
var destination = markers_elevace[marker_elevace.length - 1].getPosition();
var waypoints = [];
for (var i = 1; i < markers_elevace.length - 1; i++) {
waypoints.push({
location: markers_elevace[i].getPosition(),
stopover: true
});
}
var request = {
origin: origin,
destination: destination,
waypoints: waypoints
};
switch (travelMode) {
case "bicycling":
request.travelMode = google.maps.DirectionsTravelMode.BICYCLING;
break;
case "driving":
request.travelMode = google.maps.DirectionsTravelMode.DRIVING;
break;
case "walking":
request.travelMode = google.maps.DirectionsTravelMode.WALKING;
break;
}
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
elevationService.getElevationAlongPath({
path: response.routes[0].overview_path,
samples: SAMPLES
}, plotElevation);
} else if (status == google.maps.DirectionsStatus.ZERO_RESULTS) {
alert("Could not find a route between these points");
} else {
alert("Directions request failed");
}
});
}
function cuhel (uhel) {
if (uhel>360) {uhel=parseFloat(uhel)-360;}
if (uhel<0) {uhel=360+parseFloat(uhel);}
return uhel;
}
function add_sector(map, info, latitude, longitude, uhel, azimut, dosah, color, sektor_id, typ_pristup) {
var center = new google.maps.LatLng(latitude, longitude);
azimut = parseFloat(azimut);
var leftuhel = cuhel(azimut-(uhel/2));
var rigtuhel = cuhel(azimut+(uhel/2));
var u1 = cuhel(azimut-(uhel/4));
var u2 = cuhel(azimut);
var u3 = cuhel(azimut+(uhel/4));
var sektor_zindex = 100;
var leftBorder = google.maps.geometry.spherical.computeOffset(center, dosah, leftuhel);
var m1 = google.maps.geometry.spherical.computeOffset(center, dosah, u1);
var m2 = google.maps.geometry.spherical.computeOffset(center, dosah, u2);
var m3 = google.maps.geometry.spherical.computeOffset(center, dosah, u3);
var rightBorder = google.maps.geometry.spherical.computeOffset(center, dosah, rigtuhel);
var corners = [ center, leftBorder,m1,m2,m3,rightBorder ];
if (typ_pristup=="60 GHz sektor") {sektor_zindex=200;}
var diamond = new google.maps.Polygon({
paths: corners,
strokeColor: '#FFFFFF',
strokeOpacity: 0.8,
strokeWeight: 1,
fillColor: color,
fillOpacity: 0.3,
zIndex: sektor_zindex,
map: map
});
diamonds.push(diamond);
function showArrays(event) {
// Since this polygon has only one path, we can call getPath() to return the
// MVCArray of LatLngs.
// Replace the info window's content and position.
if ($(".ui.icon.orange.resize.horizontal")[0]) {
addMarker(event.latLng, true);}
else {
infoWindow.setContent(info);
infoWindow.setPosition(event.latLng);
infoWindow.open(map);
infoWindows.push(infoWindow);
add_marker_klienti_sektor(sektor_id);
}
}
//google.maps.event.addListener(diamond, 'click', onMarkerClick);
//
diamond.addListener('click', showArrays);
infoWindow = new google.maps.InfoWindow;
// }
}
function createMarkers(idw, map, name, latitude, longitude, ib, propustnost_wb, rozsah, zdroj, pokryti, pauza) {
var marker_show_prijem = function() {
marker_wifibod = this;
var latLng = marker_wifibod.getPosition();
$.ajax( {
url : "gmap.php?idw="+idw+"&prijem=ano&zdroj=prijemwb",
type : "GET",
success : function(data) {
var jsonData = JSON.parse(data);
var prijem_gps = new Array();
$.each(jsonData, function(Idx, Value) {
$.each(Value, function(x, y) {
//Creating an array of latitude, logitude
if(x == 'Lat') { latitude = parseFloat(y); }
if(x == 'Lng') { longitude = parseFloat(y); }
});
});
// Vytvoř propoj
$(".ui.icon.resize.horizontal").addClass("orange")
// Bod Příjem
console.log("lat:"+latitude);
reset();
var rd_interest = new google.maps.Marker({map: map,optimized: false,position: {lat: latitude, lng: longitude}, title: "Příjem" });
addMarker(rd_interest.position, true)
// Bod Tento vysílač
addMarker(marker_wifibod.position, true)
}
})
}
//Setting the onclick marker function
var onMarkerClick = function() {
reset_vysilace();
marker_wifibod = this;
var latLng = marker_wifibod.getPosition();
$.ajax( {
url : "gmap.php?idw="+idw+"&zdroj=wifibody_so",
type : "GET",
success : function(data) {
var jsonData = JSON.parse(data);
var nazev = new Array();
var polarizace = new Array();
var propustnost = new Array();
var uhel = new Array();
var azimut = new Array();
var dosah = new Array();
var rozsah_ssid = new Array();
var info = new Array();
var infot ="";
var typ_pristup = new Array();
var barva = new Array();
var sektor_id = new Array();
var i = 0; var j = 0; var k = 0; var l = 0; var u = 0;
var m = 0; var n = 0; var o = 0; var p = 0; var q = 0;
var s = 0; var t = 0;var u = 0;var w = 0;
//console.log(rozsah);
$.each(jsonData, function(Idx, Value) {
$.each(Value, function(x, y) {
//Creating an array of latitude, logitude
if(x == 'nazev') { i =i+1; nazev[i] = y; }
if(x == 'polarizace') { j =j+1; polarizace[j] = y; }
if(x == 'propustnost') { k =k+1; propustnost[k] = y; }
if(x == 'uhel') { l =l+1; uhel[l] = y; }
if(x == 'azimut') { m =m+1; azimut[m] = y; }
if(x == 'dosah') { n =n+1; dosah[n] = y; }
if(x == 'rozsah') { o =o+1; if(y=="") {rozsah_ssid[o]==rozsah} else {rozsah_ssid[o] = y;} }
if(x == 'info') { q =q+1; info[q] = y; }
if(x == 'typ_pristup') { s =s+1; typ_pristup[s] = y; }
if(x == 'barva') { t =t+1; barva[t] = y; }
if(x == 'sektor_id') { u =u+1; sektor_id[u] = y; }
});
});
if (zdroj=="wifibody_itb") {
// Info window
infoWindow = new google.maps.InfoWindow;
infoWindow.setContent(""+name+"
"+propustnost_wb+"
"+rozsah+pokryti);
infoWindow.setPosition(marker_wifibod.latLng);
infoWindow.setOptions({maxWidth: 270});
infoWindow.open(map,marker_wifibod);
infoWindows.push(infoWindow);
if (nazev.length > 0) {
for(var a = 1; a < nazev.length; ++a) {
infot = ""+nazev[a]+"" +"
Typ: "+typ_pristup[a]+"
Dosah: "+dosah[a]+"m
Propustnost: "+propustnost[a]+"Mb
Info: "+info[a]+"
IP klienti: "+rozsah_ssid[a]+"";
if (nazev[a]=='NA') {infot = "Pokrytí vysílačem" +"
pokrytí je orientační, pro přesné informace
o pokrytí volejte 608 964 464,
rádi sdělíme";}
//console.log(infot);
// vsersmery
if (uhel[a]=='360') {
//console.log(lat+"....."+ lng+"....."+ parseFloat(dosah[a])+"....."+ barva[a]+"....."+ infot+"....."+ sektor_id[a]);
add_circle(lat, lng, parseFloat(dosah[a]), barva[a], infot, sektor_id[a])
}
// sektory
if (uhel[a]!='360') {
add_sector(map, infot, lat, lng, uhel[a], azimut[a],dosah[a], barva[a], sektor_id[a], typ_pristup[a] ) ;
}
}
} else {}
}
}
});
// Najdi všechny sektory
};
google.maps.event.addListener(map, 'click', function() {
// ib.close();
});
//In array lat long is saved as an string, so need to convert it into int.
var lat = parseFloat(latitude);
var lng = parseFloat(longitude);
var img_pozice_x = 10;
var img_pozice_y = 20;
var propustnost_wb = parseInt(propustnost_wb);
var image_src="wifi_ap_blue.png";
if (propustnost_wb<=100 || propustnost_wb=='') {image_src="wifi_ap_blue.png";}
if (propustnost_wb>100 && propustnost_wb<=500 ) {image_src="wifi_ap_violet.png";}
if (propustnost_wb>500 && propustnost_wb<1000) {image_src="wifi_ap_orange.png";}
if (propustnost_wb>=1000 ) {image_src="wifi_ap_yellow.png";}
if (propustnost_wb!=0) {propustnost_wb='\nMax: '+propustnost_wb+'Mb';}
window.setTimeout(function() {
image = new google.maps.MarkerImage(image_src,null, null, new google.maps.Point(img_pozice_x, img_pozice_y), new google.maps.Size(20, 20));
var marker_wifibod = new google.maps.Marker({
map: map,
icon: image,
position: new google.maps.LatLng(lat, lng),
animation: google.maps.Animation.DROP,
title: name
});
markers_wifibody.push(marker_wifibod);
google.maps.event.addListener(marker_wifibod, 'click', onMarkerClick);
google.maps.event.addListener(marker_wifibod, 'rightclick', marker_show_prijem);
}, pauza);
// Add the circle for this city to the map.
function add_circle (lat, lng, dosah, barva, info, sektor_id) {
function info_circle_click(event) {
infoWindow.setContent(info);
infoWindow.setPosition(event.latLng);
infoWindow.open(map);
infoWindows.push(infoWindow);
add_marker_klienti_sektor(sektor_id);
}
// body...
var cityCircle = new google.maps.Circle({
strokeColor: barva,
strokeOpacity: 0.4,
strokeWeight: 1,
fillColor: barva,
fillOpacity: 0.3,
map: map,
center: {lat: lat, lng: lng},
radius: dosah
});
cityCircles.push(cityCircle);
cityCircle.addListener('click', info_circle_click);
infoWindow = new google.maps.InfoWindow;
}
}
function reset_circle() {
for (var i in cityCircles) {
cityCircles[i].setMap(null);
}
cityCircles = [];
}
function reset_sector() {
for (var i in diamonds) {
diamonds[i].setMap(null);
}
diamonds = [];
}
function reset_infowindows() {
for (var i in infoWindows) {
infoWindows[i].close();
}
infoWindows = [];
}
function reset_vysilace() {
reset_sector();
reset_circle();
reset_infowindows()
}
function searchit() {
var addressField = document.getElementById('search_address');
geokoduj();
};
function geokoduj(e, elm) { /* Voláno při odeslání */
/* JAK.Events.cancelDef(e); Zamezit odeslání formuláře */
var query = JAK.gel("search_address").value;
new SMap.Geocoder(query, odpoved);
}
function odpoved(geocoder) { /* Odpověď */
if (!geocoder.getResults()[0].results.length) {
alert("Tohle neznáme.");
return;
}
var vysledky = geocoder.getResults()[0].results;
var data = [];
var pocet = 0;
var sell= "selected";
data.push('
"+item.label +" |