I'd be grateful if someone could help me with the following query. I have an application that runs a queryTask on a map service layer and returns various feature results in a div when they click on a table of contents. However, I'd like it to automatically update when the user zooms in or out of the current map extent - is this possible to do by amending the queryTask code?My code at the moment:
function addFields(layerURL, layerids, fields) { var mapExtent = map.extent; var currentScale = map.getScale(); if (currentScale > 200000) { $('#show2').empty(); $('#show2').html('No data at this scale. Zoom in to view data'); $('#show3').empty(); $('#show3').html('No data at this scale. Zoom in to view data'); } else { $('#show3').empty(); //query the fields in extent var query3 = new Query(); query3.returnGeometry = true; query3.outFields = [fields]; query3.geometry = mapExtent; var queryTask3 = new QueryTask(layerURL + '/' + layerids); //resultItems.push("Before process"); queryTask3.execute(query3, function (results3) { ////resultItems.push("Before"); if (results3.features.length < 1) { $('#show2').empty(); $('#show3').empty(); $('#show3').html('No results are available in this area, zoom out to explore further...') $('#show2').html('No results are available in this area, zoom out to explore further...') } else { for (var k = 0; k < results3.features.length; k++) { //debugger; for (var j = 0; j < fields.length; j++) { var checkForLink = results3.features[k].attributes[fields[j]]; if (checkForLink.indexOf('http://') == 0) { $('#show3').append($('Find out more...')); } else { $('#show3') .append(checkForLink); } $('#show3').append($('
')); } $('#show3').append($('')); } } });Any help would be appreciated!
أكثر...
function addFields(layerURL, layerids, fields) { var mapExtent = map.extent; var currentScale = map.getScale(); if (currentScale > 200000) { $('#show2').empty(); $('#show2').html('No data at this scale. Zoom in to view data'); $('#show3').empty(); $('#show3').html('No data at this scale. Zoom in to view data'); } else { $('#show3').empty(); //query the fields in extent var query3 = new Query(); query3.returnGeometry = true; query3.outFields = [fields]; query3.geometry = mapExtent; var queryTask3 = new QueryTask(layerURL + '/' + layerids); //resultItems.push("Before process"); queryTask3.execute(query3, function (results3) { ////resultItems.push("Before"); if (results3.features.length < 1) { $('#show2').empty(); $('#show3').empty(); $('#show3').html('No results are available in this area, zoom out to explore further...') $('#show2').html('No results are available in this area, zoom out to explore further...') } else { for (var k = 0; k < results3.features.length; k++) { //debugger; for (var j = 0; j < fields.length; j++) { var checkForLink = results3.features[k].attributes[fields[j]]; if (checkForLink.indexOf('http://') == 0) { $('#show3').append($('Find out more...')); } else { $('#show3') .append(checkForLink); } $('#show3').append($('
')); } $('#show3').append($('')); } } });Any help would be appreciated!
أكثر...