map.on('singleclick', function (evt) {
document.getElementById('info').innerHTML = "Looks like you need to redo this :) !!!";
var view = map.getView();
var viewResolution = view.getResolution();
var source = hcm.getSource();
var url = source.getFeatureInfoUrl(
evt.coordinate, viewResolution, view.getProjection(),
{ 'INFO_FORMAT': 'application/json', 'FEATURE_COUNT': 50 });
if (url) {
$.ajax({
type: "POST",
url: url,
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (n) {
var content = "<table>";
for (var i = 0; i < n.features.length; i++) {
var feature = n.features[i];
var featureAttr = feature.properties;
content += "<tr><td>District Name:" + featureAttr["name_2"]
+ "</td><td>District ID:" + featureAttr["id_2"]
+"</td></tr>"
}
content += "</table>";
$("#info").html(content);
}
});
}
});
This is my attempt at retrieving features.
I am facing an issue with my code. I am trying to create a WebGIS using the OpenLayers library and GeoServer. However, I am encountering difficulties while attempting to retrieve features from layers. I am unable to resolve this problem on my own. Can someone please assist me?