on(dom.byId("mapshow"), "click", selectHistorical); function selectHistorical(){ var queryTask = new QueryTask(window.historicalUrl); var query = new Query(); query.returnGeometry=true; query.outFields=window.historicalOutFields; query.text = dom.byId("mydropdown").value; query.outSpatialReference = {"wkid":2236}; dojo.connect(queryTask, "onComplete", function(featureSet){ map.graphics.clear(); dojo.forEach(featureSet.features, function(feature){ var graphic = feature; map.graphics.add(graphic); }); }); queryTask.execute(query); }
Solved! Go to Solution.
function selectHistorical() { var queryTask = new QueryTask(window.historicalUrl); var query = new Query(); query.returnGeometry = true; query.outFields = window.historicalOutFields; query.where = "DeviceId = '" + dom.byId("mydropdown").value + "'"; query.outSpatialReference = { "wkid": 4326 }; dojo.connect(queryTask, "onComplete", function (featureSet) { map.graphics.clear(); dojo.forEach(featureSet.features, function (feature) { var point = new Point(feature.geometry.x, feature.geometry.y, new SpatialReference({wkid:4326})); var simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE, 10, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([0,255,0,0.25]), 1), new Color([255,0,0]) ) var graphic = new Graphic(point, simpleMarkerSymbol); map.graphics.add(graphic); }); }); queryTask.execute(query); }
//execute query queryTask.execute(query0, showResults); }; function showResults(results) { var s = "<table>"; var aliases = results.fieldAliases; var len = results.features.length; var fieldTypes = {}; //var dateI = results.fields.length; // define a variable that will hold the field type for each field name. array.forEach(results.fields, function (aField) { fieldTypes[aField.name] = aField.type; }); if (len === 0) { // if no results s = "No results for IPMS reference: " + IPMSREF } else { // if 1 or more results, display them for (var i = 0; i < len; i++) { var featureAttributes = results.features.attributes; for (var att in featureAttributes) { //var aliasesFix = aliases[att].replace("*", "") if (featureAttributes[att] == null) { featureAttributes[att] = "" } else if (fieldTypes[att] == "esriFieldTypeDate") { featureAttributes[att] = formatDate(new Date(featureAttributes[att])); } else if (fieldTypes[att] == "esriFieldTypeDouble") { featureAttributes[att] = Math.round(featureAttributes[att]*10000)/10000 } else if (att == "EDITEDBY" && "CREATEDBY") { featureAttributes[att] = featureAttributes[att].replace("IPS$",""); } s = s + "<tr><td><span style='white-space: nowrap'>" + "<b>" + (aliases.hasOwnProperty(att) && aliases[att]) + "</b>" + ": " + "</td><td style='width:100%;'>" + featureAttributes[att] + "</td></tr>"; } s = s + "<tr class='blank_row'><td></td>" } s = s + "</table><br />"; }; dom.byId("info").innerHTML = s; dojo.query("#info table tr:nth-child(odd)").addClass("odd"); dojo.query("#info table tr:nth-child(even)").addClass("even"); //get x and y from centre of results geometry = true query var polyGonGeom = results.features[0].geometry; var polyGonExt = polyGonGeom.getExtent(); map.setExtent(polyGonExt); var Polygon = new esri.geometry.Polygon(polyGonGeom, new esri.SpatialReference({ wkid: 27700 })); console.log(Polygon) if (!graphic) { addGraphic(Polygon); } else { graphic.setGeometry(Polygon); }; }; //add graphic to the map function addGraphic(Polygon) { //parameters for the symbol var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([49, 101, 156]), 2), new dojo.Color([148, 186, 231, 0.5])); // var symbol = new esri.symbol.PictureMarkerSymbol({ // "angle": 0, // "xoffset": 0, // "yoffset": 0, // "type": "esriPMS", // "url": "http://static.arcgis.com/images/Symbols/Basic/BlueShinyPin.png", // "contentType": "image/png", // "width": 24, // "height": 24 // }); var graphic = new esri.Graphic(Polygon, symbol); map.graphics.add(graphic); };
query.where = "ID =" dom.byId("mydropdown").value;instead of query.text??
Tried:query.where = "ID =" dom.byId("mydropdown").value;instead of query.text??
replace ID with your rest url attribute column name.
Do you get a result with firebug to the call?
"VehicleId" = dom.byId("mydropdown").value;
on(dom.byId("execute"), "click",execute); function execute(){ var queryTask = new QueryTask(window.historicalUrl); var query = new Query(); query.text = dom.byId("mydropdown").value; query.returnGeometry = true; query.outFields = window.historicalOutFields; queryTask.execute(query, function (results) { var data = []; var data = array.map(results.features, function (feature) { return { "Vehicleid": feature.attributes[window.historicalOutFields[0]], "Velocity": feature.attributes[window.historicalOutFields[1]], "Direction": feature.attributes[window.historicalOutFields[2]], "TimeStamp": feature.attributes[window.historicalOutFields[3]] } }); var memStore = new Memory ({data:data}); window.grid3.set("store", memStore); }); };
Hi Michelle,
Could you create a jsfiddle with your code? This will make it easier to troubleshoot.
query.where = "DeviceId = '" + dom.byId("mydropdown").value + "'";
I couldn't see if this resolved the problem since the services don't appear to be public facing, but try chaning the query to the following:query.where = "DeviceId = '" + dom.byId("mydropdown").value + "'";
do you have firebug installed? If so, check the response from the querytask and you should see the features and the geometry.
Let us know how you get on.