I am having trouble calling the ajax-jquery function for the leaflet-search function. Everytime I search it returns 'undefined'....Can someone help me with this? Is it because I have it ordered wrong? Here is the code:function searchByAjax(uwi, callResponse){$.ajax({type: 'GET',data: {bc_well_data_wgs: uwi},dataType: 'json',success: function(json) {callResponse(json);}});}map.addControl( new L.Control.Search({callData: searchByAjax, text:'UWI...', markerLocation: true}) );
Sooo the bc_well_data_wgs is the table and the 'uwi' is the field I want to search on geoserver. Is this the correct layout?Thanks,Mitch
var url = "http://localhost:8085/geoserver/WellKnown/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=WellKnown:bc_well_data_wgs&maxFeatures=10&outputFormat=application/json&filter=<filter><PropertyIsEqualTo><PropertyName>uwi</PropertyName><Literal>";var endUrl = "</Literal></PropertyIsEqualTo></filter>";
function searchByAjax(text, callResponse)//callback for 3rd party ajax requests { $.ajax({ url: url + text + endUrl, type: 'GET', dataType: 'json', success: function(searchData){ searchCoord.addData(searchData); map.fitBounds(searchCoord.getBounds()); } })};
var searchCoord = new L.GeoJSON(searchData, { pointToLayer: function(feature, layer) { return new L.marker([feature.properties.lat, feature.properties.lon], {icon: bcWellIcon}); }, onEachFeature: function (feature, layer) { var popupContent = ''; if (feature.properties && feature.properties.uwi) { popupContent = "<strong>UWI:</strong>" + " " + feature.properties.uwi + "<br/>" + "<strong>OPERATOR:</strong>" + " " + feature.properties.oper_abbre + "<br/>"; } layer.bindPopup(popupContent + '<a href="report/bcwellReport.html?" target="_blank"><i class="fa fa-info-circle fa-2x"></i></a>'); } }).addTo(map);
map.addControl( new L.Control.Search({callData: searchByAjax, text:'UWI...', markerLocation: true}) );var searchData = '';