Java
Java
map = L.map('map', {
crs: L.CRS.EPSG4326,
center: [23.00, 82.00],
zoom: 3,
zoomControl: false
//layers: [grayscale, cities]
});
var satellite =
L.tileLayer('https://wi.maptiles.arcgis.com/arcgis/rest/services/World_Imagery/
MapServer/tile/{z}/{y}/{x}', {
// maxZoom: 23,
attribution: 'Source: Esri, Maxar, Earthstar Geographics, CNES/Airbus DS,
USDA FSA, USGS, Getmapping, Aerogrid, IGN, IGP, and the GIS User Community'
}).addTo(map);
var hillshade =
L.tileLayer('https://whi.maptiles.arcgis.com/arcgis/rest/services/World_Hillshade/
MapServer/tile/{z}/{y}/{x}', {
//maxZoom: 19,
attribution: 'Sources: Esri, Airbus DS, USGS, NGA, NASA, CGIAR, N Robinson,
NCEAS, NLS, OS, NMA, Geodatastyrelsen, Rijkswaterstaat, GSA, Geoland, FEMA,
Intermap, and the GIS user community',
});
/*var satellite =
L.tileLayer('https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/
MapServer/tile/{z}/{y}/{x}', {
maxZoom: 23,
layerControl = L.control.layers().addTo(map);
layerControl.addBaseLayer(hillshade, "hillshade");
layerControl.addBaseLayer(satellite, "satellite");
//layerControl.addOverlay(india_state,"india_state");
//layerControl.addOverlay(india_district,"india_district");
//layerControl.add(base);
//L.control.layers().addTo(map);
/*layerControl = L.control.layers().addTo(map);
//L.control.layers.addOverlay(india_state,"test").addTo(map);
layerControl.addBaseLayer(satellite,"satellite");
layerControl.addBaseLayer(OSM,"OSM");
layerControl.addOverlay(india_state,"india_state");
layerControl.addOverlay(india_district,"india_district");
*/
// Zoom bar
var zoom_bar = new L.Control.ZoomBar({
position: 'topleft'
}).addTo(map);
//map.addControl(new L.Control.Zoomslider());
// mouse position
L.control.mousePosition({
position: 'bottomleft',
prefix: "lat : long",
}).addTo(map);
//scale
L.control.scale({
position: 'bottomleft'
}).addTo(map);
//geocoder
L.Control.geocoder({
position: 'topright'
}).addTo(map);
//line mesure
L.control.polylineMeasure({
position: 'topleft',
unit: 'kilometres',
showBearings: true,
clearMeasurementsOnStop: false,
showClearControl: true,
showUnitControl: true
}).addTo(map);
//area measure
var measureControl = new L.Control.Measure({
position: 'topleft'
});
measureControl.addTo(map);
//search
map.addControl(L.control.search({
position: 'topleft'
}));
//legend
function legend() {
$('#legend').empty();
var layers = overlays.getLayers();
//console.log(no_layers[0].options.layers);
//console.log(no_layers);
//var no_layers = overlays.getLayers().get('length');
head.appendChild(txt);
var element = document.getElementById("legend");
element.appendChild(head);
overlays.eachLayer(function (layer) {
});
legend();
// layer dropdown query
$(document).ready(function() {
$.ajax({
type: "GET",
url: "http://localhost:8080/geoserver/wfs?request=getCapabilities",
dataType: "xml",
success: function(xml) {
var select = $('#layer');
$(xml).find('FeatureType').each(function() {
//var title = $(this).find('ows:Operation').attr('name');
//alert(title);
var name = $(this).find('Name').text();
//select.append("<option/><option class='ddheader' value='"+ name
+"'>"+title+"</option>");
$(this).find('Name').each(function() {
var value = $(this).text();
select.append("<option class='ddindent' value='" + value + "'>"
+ value + "</option>");
});
});
//select.children(":first").text("please make a
selection").attr("selected",true);
}
});
});
// attribute dropdown
$(function() {
$("#layer").change(function() {
$(document).ready(function() {
$.ajax({
type: "GET",
url: "http://localhost:8080/geoserver/wfs?
service=WFS&request=DescribeFeatureType&version=1.1.0&typeName=" + value_layer,
dataType: "xml",
success: function(xml) {
$(this).find('xsd\\:element').each(function() {
var value = $(this).attr('name');
//alert(value);
var type = $(this).attr('type');
//alert(type);
if (value != 'geom' && value != 'the_geom') {
select.append("<option class='ddindent' value='" +
type + "'>" + value + "</option>");
}
});
});
}
});
});
});
});
// operator combo
$(function() {
$("#attributes").change(function() {
});
});
// function for finding row in the table when feature selected on map
function findRowNumber(cn1, v1) {
function query() {
$('#table').empty();
if (geojson) {
map.removeLayer(geojson);
//alert('jsbchdb');
var layer = document.getElementById("layer");
var value_layer = layer.options[layer.selectedIndex].value;
//alert(value_layer);
if (value_operator == 'ILike') {
value_txt = "'" + value_txt + "%25'";
//alert(value_txt);
//value_attribute = 'strToLowerCase('+value_attribute+')';
} else {
value_txt = value_txt;
//value_attribute = value_attribute;
}
//alert(value_txt);
geojson = L.geoJson(data, {
onEachFeature: onEachFeature
});
geojson.addTo(map);
map.fitBounds(geojson.getBounds());
tr = table.insertRow(-1);
// FINALLY ADD THE NEWLY CREATED TABLE WITH JSON DATA TO A CONTAINER.
var divContainer = document.getElementById("table_data");
divContainer.innerHTML = "";
divContainer.appendChild(table);
addRowHandlers();
document.getElementById('map').style.height = '71%';
document.getElementById('table_data').style.height = '29%';
map.invalidateSize();
});
layer.on('click', function(e) {
// e = event
selected = e.target;
selected.setStyle({
'color': 'red'
});
if (feature) {
console.log(feature);
$(function() {
$("#table td").each(function() {
$(this).parent("tr").css("background-color", "white");
});
});
rows[row_no].scrollIntoView({
behavior: 'smooth',
block: 'center'
});
$(document).ready(function() {
$("#table td:nth-child(" + col_no + ")").each(function() {
if ($(this).text() == feature.id) {
$(this).parent("tr").css("background-color", "grey");
}
});
});
});
};
}
for (i = 0; i < rows.length; i++) {
rows[i].onclick = function() {
return function() {
//featureOverlay.getSource().clear();
if (geojson) {
geojson.resetStyle();
}
$(function() {
$("#table td").each(function() {
$(this).parent("tr").css("background-color", "white");
});
});
var cell = this.cells[col_no - 1];
var id = cell.innerHTML;
$(document).ready(function() {
$("#table td:nth-child(" + col_no + ")").each(function() {
if ($(this).text() == id) {
$(this).parent("tr").css("background-color", "grey");
}
});
});
features = geojson.getLayers();
if (features[i].feature.id == id) {
//alert(features[i].feature.id);
//featureOverlay.getSource().addFeature(features[i]);
selected = features[i];
selected.setStyle({
'color': 'red'
});
map.fitBounds(selected.getBounds());
console.log(selected.getBounds());
}
}
//alert("id:" + id);
};
}(rows[i]);
}
}
function wms_layers() {
$("#wms_layers_window").modal({backdrop: false});
//$("#wms_layers_window").draggable();
$("#wms_layers_window").modal('show');
$(document).ready(function() {
$.ajax({
type: "GET",
url: "http://localhost:8080/geoserver/wms?request=getCapabilities",
dataType: "xml",
success: function(xml) {
$('#table_wms_layers').empty();
// console.log("here");
$('<tr></tr>').html('<th>Name</th><th>Title</th><th>Abstract</th>').appendTo('#tabl
e_wms_layers');
$(xml).find('Layer').find('Layer').each(function() {
var name = $(this).children('Name').text();
// alert(name);
//var name1 = name.find('Name').text();
//alert(name);
var title = $(this).children('Title').text();
// alert('test');
$('<tr></tr>').html('<td>' + name + '</td><td>' + title +
'</td><td>' + abst + '</td>').appendTo('#table_wms_layers');
//document.getElementById("table_wms_layers").setAttribute("class", "table-
success");
});
addRowHandlers1();
}
});
});
function addRowHandlers1() {
//alert('knd');
var rows = document.getElementById("table_wms_layers").rows;
var table = document.getElementById('table_wms_layers');
var heads = table.getElementsByTagName('th');
var col_no;
for (var i = 0; i < heads.length; i++) {
// Take each cell
var head = heads[i];
//alert(head.innerHTML);
if (head.innerHTML == 'Name') {
col_no = i + 1;
//alert(col_no);
}
}
for (i = 0; i < rows.length; i++) {
rows[i].onclick = function() {
return function() {
$(function() {
$("#table_wms_layers td").each(function() {
$(this).parent("tr").css("background-color", "white");
});
});
var cell = this.cells[col_no - 1];
layer_name = cell.innerHTML;
// alert(layer_name);
$(document).ready(function() {
$("#table_wms_layers td:nth-child(" + col_no +
")").each(function() {
if ($(this).text() == layer_name) {
$(this).parent("tr").css("background-color",
"grey");
}
});
});
//alert("id:" + id);
};
}(rows[i]);
}
}
// add wms layer to map on click of button
function add_layer() {
// alert("jd");
//alert(layer_name);
//map.removeControl(layerSwitcher);
}).addTo(map);
//layerControl.addOverlay(india_district,"india_district");
layerControl.addOverlay(layer_wms, layer_name);
overlays.addLayer(layer_wms, layer_name);
$(document).ready(function() {
$.ajax({
type: "GET",
url: "http://localhost:8080/geoserver/wms?request=getCapabilities",
dataType: "xml",
success: function(xml) {
$(xml).find('Layer').find('Layer').each(function() {
var name = $(this).children('Name').text();
// alert(name);
if (name == layer_name) {
// use this for getting the lat long of the extent
var bbox1 = $
(this).children('EX_GeographicBoundingBox').children('southBoundLatitude').text();
var bbox2 = $
(this).children('EX_GeographicBoundingBox').children('westBoundLongitude').text();
var bbox3 = $
(this).children('EX_GeographicBoundingBox').children('northBoundLatitude').text();
var bbox4 = $
(this).children('EX_GeographicBoundingBox').children('eastBoundLongitude').text();
var southWest = L.latLng(bbox1, bbox2);
var northEast = L.latLng(bbox3, bbox4);
var bounds = L.latLngBounds(southWest, northEast);
map.fitBounds(bounds);
/* $(this).find('BoundingBox').each(function(){
if ($(this).attr('CRS') != "CRS:84" ){
var bbox1 = $(this).attr('minx');
var bbox2 = $(this).attr('miny');
var bbox3 = $(this).attr('maxx');
var bbox4 = $(this).attr('maxy');
var southWest = L.latLng(bbox1, bbox2);
var northEast = L.latLng(bbox3, bbox4);
var bounds = L.latLngBounds(southWest, northEast);
map.fitBounds(bounds);
}
});*/
// alert($
(this).children('EX_GeographicBoundingBox').text());
if (bounds != undefined){alert(layer_name+" added to the
map");}
}
});
}
});
});
legend();
function close_wms_window(){
layer_name = undefined;
}
map.off('click', getinfo);
document.getElementById("info_btn").innerHTML = "☰ Activate GetInfo";
document.getElementById("info_btn").setAttribute("class", "btn btn-success
btn-sm");
}
}
// getinfo function
function getinfo(e) {
if (content) {
content = '';
}
overlays.eachLayer(function (layer) {
var url = 'http://localhost:8080/geoserver/wms?
SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&FORMAT=image
%2Fpng&TRANSPARENT=true&QUERY_LAYERS=' + layer.options.layers + '&LAYERS=' +
layer.options.layers + '&INFO_FORMAT=text%2Fhtml&X=' + x + '&Y=' + y + '&CRS=EPSG
%3A4326&STYLES=&WIDTH=' + width + '&HEIGHT=' + height + '&BBOX=' + bbox;
console.log(url);
$.get(url, function(data) {
//content.push(data);
content += data;
//console.log(content);
popup.setContent(content);
popup.setLatLng(e.latlng);
map.openPopup(popup);
});
});
// clear function
function clear_all() {
document.getElementById('map').style.height = '100%';
document.getElementById('table_data').style.height = '0%';
map.invalidateSize();
$('#table').empty();
$('#legend').empty();
//$('#table1').empty();
if (geojson) {
map.removeLayer(geojson);
}
map.flyTo([23.00, 82.00], 4);
document.getElementById("query_tab").style.width = "0%";
document.getElementById("map").style.width = "100%";
document.getElementById("map").style.left = "0%";
document.getElementById("query_tab").style.visibility = "hidden";
document.getElementById('table_data').style.left = '0%';
map.off('click', getinfo);
document.getElementById("info_btn").innerHTML = "☰ Activate GetInfo";
document.getElementById("info_btn").setAttribute("class", "btn btn-success btn-
sm");
overlays.eachLayer(function (layer) {
map.removeLayer(layer);
layerControl.removeLayer(layer);
overlays.removeLayer(layer);
});
overlays.clearLayers();
map.invalidateSize();
function show_hide_querypanel() {
if (document.getElementById("query_tab").style.visibility == "hidden") {
document.getElementById('table_data').style.left = '20%';
map.invalidateSize();
} else {
document.getElementById("query_panel_btn").innerHTML = "☰ Open Query
Panel";
document.getElementById("query_panel_btn").setAttribute("class", "btn btn-
success btn-sm");
document.getElementById("query_tab").style.width = "0%";
document.getElementById("map").style.width = "100%";
document.getElementById("map").style.left = "0%";
document.getElementById("query_tab").style.visibility = "hidden";
document.getElementById('table_data').style.left = '0%';
map.invalidateSize();
}
}
function show_hide_legend() {
if (document.getElementById("legend").style.visibility == "hidden") {
document.getElementById('legend').style.height = '38%';
map.invalidateSize();
} else {
document.getElementById("legend_btn").innerHTML = "☰ Show Legend";
document.getElementById("legend").style.width = "0%";
document.getElementById("legend").style.visibility = "hidden";
document.getElementById('legend').style.height = '0%';
map.invalidateSize();
}
}