I am trying to get the JSON feature data which I have filtered using cql_filter.
<script>
var wmsSource = new ol.source.TileWMS({
url: 'http://localhost:9090/geoserver/ilfs/wms',
params: {'LAYERS': 'ilfs:dharani_samplevillage',
'TILED': true, 'format': 'image/png',
'VERSION': '1.1.1', 'SRS':'EPSG:4326',
"TRANSPARENT": true,
"ISBASELAYER": true,
"RATIO": 1,
"TILED": true,
"CQL_FILTER": "bhucode=11223344444555 and kid=243"
//kid = 237, 236, 78, 241, 243
},
serverType: 'geoserver',
transition: 0
//crossOrigin: 'anonymous'
});
var wmsLayer = new ol.layer.Tile({
source: wmsSource,
opacity: 0.7,
visible: true
});
var view = new ol.View({
projection: 'EPSG:4326',
//Longiture first, then latitude
//center: ol.proj.transform([76.63612, 16.94924], 'EPSG:4326', 'EPSG:3857'),
//center: [76.63612,16.94924],
center: [0, 0],
zoom: 18
});
var map = new ol.Map({
layers: [wmsLayer],
target: 'map',
view: view,
renderer: 'canvas'
});<script>
With the above code displaying the filtered map, but I need to retrieve feature data with the format of JSON, and that should be in load into browser console.
Best Answer
Whilst you may be able to get some sort of JSON from a WMS GetFeatureInfo request for a point location in a map provided by a WMS (not all WMS providers have this configured), you should be mindful that the purpose of a WMS is give you map images.
A WMS does not expose the input data (or features) it gives an image representation of the features.
If you want to access features using OpenLayers through an OGC service then you'll be needing a WFS.