I have a function to search from layer. I got the desired results, so I want to zoom-in and highlight the results I found. How can I do that?
This is my code:
var sothuaMap = document.getElementById('sothuaMap');
var sotoMap = document.getElementById('sotoMap');
var phuongMap = document.getElementById('phuongMap');
var searchButton = document.getElementById('search');
var resultSpan = document.getElementById('span');
function search(sothuaGet, sotoGet, phuongMap) {
resultSpan.innerHTML = 'Searching...';
fetch('http://localhost:8081/geoserver/vietnam/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=vietnam%3Ahtgovap&maxFeatures=50000&outputFormat=application%2Fjson&q=' + sothuaGet)
.then(function (response) {
return response.json();
})
.then(function (json) {
var results = json.features;
// console.log(results);
if (results && results.length > 0) {
for (let i = 0, ii = results.length; i < ii; i++) {
const result = results[i];
if(result){
var props = result.properties; //get properties
var geom = result.geometry; //get geometry
var sothua = props.shthua;
var soto = props.shbando;
var phuong = props.xaphuong;
var dientich = props.dientich;
var coordinate = geom.coordinates;
if(sothua == sothuaGet && soto == sotoGet && phuong == phuongMap){
setProjection(sothua,soto,dientich,coordinate);
return;
}
}
}
}
// setProjection(null, null, null);
});
}
function setProjection(sothua, soto, dientich, coordinate){
//
if(sothua == null || soto == null){
resultSpan.innerHTML = 'Not found, try again...!'
return
}
resultSpan.innerHTML = 'ST: ' + sothua + ' '
+ 'SHBD: ' + soto +' '
+ 'DT: ' + dientich + '<br>'
+ 'Geom: ' + coordinate;
}
searchButton.onclick = function (event) {
if(sotoMap.value != '' && sothuaMap.value != '' && phuongMap.value != ''){
search(sothuaMap.value, sotoMap.value, phuongMap.value);
event.preventDefault();
}else{
alert('Input data empty!');
event.preventDefault();
}
};
"Highlight" the same this:
setProjection
function, so zoom should happen there. Is this correct? Also what do you mean by "highligh result"? Please edit your question and add info about that.setProjection
function. I meanhighlight
means make it stand out