Hi Derek,
hmmm this is rather embarrassing but it was the spatial reference code that was wrong ie 27700 rather than 2770!
One more quick question, do you have any idea why the variable uprn returns as undefined? I am trying to get the value of the field "Polling_Station_UPRN" so that I can use it as an input in another application but for some reason the value comes back as undefined outside of the function it is called in. I have created it as a global variable but it's still undefined. Any ideas?
Thanks
Cameron
Code:
<script type="text/javascript">$.loadSite('http://cms.esriuk.com/TowerHamlets/', 'ab066578-6325-495c-ac12-da7a9696ac02', '#mygaz', configLoaded);
dojo.require("esri.tasks.query");
dojo.require("esri.tasks.geometry");
dojo.require("dojo.parser");
dojo.require("esri.map");
var queryTask;
var uprn;
function configLoaded(config /* site config */) {
config = config;
$("#lhDiv").bind({
"locatorhub.pickList": function (evt, locatorhub, picklist) {
// added to fix bug in release 6 (SP5) of LVF. Will be fixed in release 7
$(".jquery-locatorhub-picklistrow").removeAttr("href");
$(".jquery-locatorhub-results").css("display", "block");
},
"locatorhub.searchDialogLocationFound": function (evt, locatorhub, match) {
// Insert what you want to do with an address match here!!!!
AddressFound(match)
},
"locatorhub.matchedLocationClick": function (evt, locatorhub, match) {
// Insert what you want to do with an address match here!!!!
AddressFound(match);
},
"locatorhub.addressSearchError": function () {
alert("Address Search error");
},
"locatorhub.error": function (evt, error) {
alert("locator hub error")
}
})
}
function AddressFound(match) {
x = match.Point.x;
y = match.Point.y;
sr = match.Point.spatialReference.wkid; ;
queryTask = new esri.tasks.QueryTask("http://thgistest01/ArcGIS/rest/services/PollingDistrict/MapServer/1");
//Can listen for onComplete event to process results or can use the callback option in the queryTask.execute method.
//dojo.connect(queryTask, "onComplete", showResults);
//build query filter
query = new esri.tasks.Query();
var XY = new esri.geometry.Point (x,y, new esri.SpatialReference({ wkid: 27700 }));
query.geometry = XY;
query.outFields = ["Polling_Station_UPRN"];
//query.text = "Bow East 2";
queryTask.execute(query);
dojo.connect(queryTask, "onComplete", function (myFeatureSet) {
var s = "";
for (var i=0, il=myFeatureSet.features.length; i<il; i++) {
var featureAttributes = myFeatureSet.features[i].attributes;
for (att in featureAttributes) {
s = s + "<strong>" + att + ": </strong>" +
featureAttributes[att] + "<br />";
}
}
dojo.byId("info").innerHTML = s;
uprn = featureAttributes[att];
}
);
alert (uprn)
}
Bookmarks