function showResults(featureSet) { //remove all graphics on the maps graphics layer map.graphics.clear(); //******* add this console.log(featureSet); console.log(featureSet.length); //******* //QueryTask returns a featureSet. Loop through features in the featureSet and add them to the map. //Performance enhancer - assign featureSet array to a single variable. var resultFeatures = featureSet.features; //****** add this console.log(resultFeatures); // im guessing this may be undefined. or an unexpected value console.log(resultFeatures.length); //****** for (var i=0, il=resultFeatures.length; i<il; i++) { //Get the current feature from the featureSet. //Feature is a graphic var graphic = resultFeatures; graphic.setSymbol(symbol); //Set the infoTemplate. graphic.setInfoTemplate(infoTemplate); //Add graphic to the map graphics layer. map.graphics.add(graphic); } }
queryTask.execute(query,showResults);
queryTask.execute(query,showResults,showErr);
function showErr(){ console.log('error in query execution'); }
function showResults(featureSet) { //remove all graphics on the maps graphics layer map.graphics.clear(); //******* add this console.log(featureSet); console.log(featureSet.length); //******* ///all the rest of your code
Hi lowgas,
Thanks for the replay!
I tried your code. But that does not display the attributes and geometry. And Firefox Firebug shows me no errors.
I do not understand what the problem is. I saw many examples in internet.
and I downloaded one of they and tried without the images.
e.g. http://resources.esri.com/arcgisserver/apis/javascript/arcgis/index.cfm?fa=codeGalleryDetails&script....
I just wanted to try with attrubutes and geometry.
I published the file PhotoLocations.mxd to my arcgisserver as map service and used for javascript code. I think basically this shoud work.
I see the map, but no infowindow with attributes as before. I wonder....
if this example works right with you, I pehaps have problem with the publishing of map service.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>QueryTask with geometry, results as an InfoWindow onHover containg image</title>
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.2/js/dojo/dijit/themes/tundra/tundra.css">
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.2"></script>
<script type="text/javascript" language="Javascript">
dojo.require("esri.map");
dojo.require("esri.tasks.query");
function init() {
var startExtent = new esri.geometry.Extent(-117.197, 34.035, -117.183, 34.045, new esri.SpatialReference({wkid:4326}));
//create map
var map = new esri.Map("mapDiv",{extent:startExtent});
//listen for when map is loaded and then add query functionality
dojo.connect(map, "onLoad", initFunctionality);
//create and add new layer
var layer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer");
map.addLayer(layer);
var overlaymap=new esri.layers.ArcGISDynamicMapServiceLayer("http://myserver/ArcGIS/rest/services/PhotoLocations/MapServer");
map.addLayer(overlaymap);
}
function initFunctionality(map) {
//build query task
var queryTask = new esri.tasks.QueryTask("http://myserver/ArcGIS/rest/services/PhotoLocations/MapServer/0");
//build query filter
var query = new esri.tasks.Query();
query.returnGeometry = true;
query.outFields = ["OID", "EXIF_ImageDescription", "EXIF_Copyright", "SourceFileName"];
query.where = "OID >= 0";
var infoTemplate = new esri.InfoTemplate();
infoTemplate.setTitle("${SourceFileName}");
infoTemplate.setContent("<b>Description: </b>${EXIF_ImageDescription}<br/>"
+ "<b>Copyrights: </b>${EXIF_Copyright}<br/>");
map.infoWindow.resize(225,350);
//Can listen for onComplete event to process results or can use the callback option in the queryTask.execute method.
dojo.connect(queryTask, "onComplete", function(featureSet) {
map.graphics.clear();
var highlightSymbol = new esri.symbol.PictureMarkerSymbol("images/i_camera.png", 40, 40);
var symbol = new esri.symbol.PictureMarkerSymbol("images/i_camera.png", 40, 40);
//QueryTask returns a featureSet. Loop through features in the featureSet and add them to the map.
for (var i=0, il=featureSet.features.length; i<il; i++) {
//Get the current feature from the featureSet.
//Feature is a graphic
var graphic = featureSet.features;
graphic.setSymbol(symbol);
graphic.setInfoTemplate(infoTemplate);
//Add graphic to the map graphics layer.
map.graphics.add(graphic);
}
map.graphics.enableMouseEvents();
dojo.connect(map.graphics, "onMouseOver", function(evt) {
var content = evt.graphic.getContent();
map.infoWindow.setContent(content);
var title = evt.graphic.getTitle();
map.infoWindow.setTitle(title);
evt.graphic.setSymbol(highlightSymbol);
map.infoWindow.show(evt.screenPoint,map.getInfoWindowAnchor(evt.screenPoint));
});
dojo.connect(map.graphics, "onMouseOut", function(evt) {
map.infoWindow.hide();
evt.graphic.setSymbol(symbol);
});
});
queryTask.execute(query);
}
dojo.addOnLoad(init);
</script>
</head>
<body class="tundra">
Hover over a camera icon to see image thumbnail and image description.
<div id="mapDiv" style="width:1000px; height:800px; border:1px solid #000;"></div>
</body>
</html>