DK7686

Mark Point to get Coordinates, then identify.

Discussion created by DK7686 on Aug 20, 2013
Latest reply on Aug 28, 2013 by ZachLiu
Hi

I'm using a MarkPoint function which gives me some coords in a pop up. I'm trying to send them to an identify function.

The identify function would normally work 'onClick' as per below.

function mapReady(map){
       dojo.connect(map,"onClick",executeIdentifyTask); 

My alerts show that the script runs through the mapReady function, then does nothing once it reaches the fucntion executeIdentifyTask itself.

It's not being fed the identify parameters (normally this would be evt.mapPoint). Does anyone know how I pass my original MarkPoint throught to my identify. What I'm after if for the end user to gen get attributes and coordinates fro a click on the map.

function executeIdentifyTask(evt) {
        identifyParams.geometry = evt.mapPoint;


Using version 3.6 by the way - the script is below if anyone can spot the clanger I'd love to know.

Cheers
Dave

:::::::::::::::::::::::::::::::::::::::::::::::::::::

  <script>
      dojo.require("esri.map");
      dojo.require("esri.tasks.geometry");
   dojo.require("esri.dijit.Popup");

      var map = null;
      var gsvc = null;
      var pt = null;
   var identifyTask, identifyParams;

      function initialize() {
  
       var popup = new esri.dijit.Popup({
          fillSymbol: new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.25]))
        }, dojo.create("div"));
 
        map = new esri.Map("map");

var background = new esri.layers.ArcGISTiledMapServiceLayer("http://bl-arcgis-1/ArcGIS/rest/services/Basemaps/MapServer");
        map.addLayer(background);
        map.setExtent(new esri.geometry.Extent(450000, 500000, 480000, 530000, new esri.SpatialReference({wkid: 27700}))); 
 

        gsvc = new esri.tasks.GeometryService("http://bl-arcgis-1/ArcGIS/rest/services/Geometry/GeometryServer");
        dojo.connect(map, "onClick", markpoint);
  //dojo.connect(map, "onLoad", mapReady);
      };

      function markpoint(evt) {
  
        map.graphics.clear();
       
        var point = evt.mapPoint;
        var symbol = new esri.symbol.SimpleMarkerSymbol().setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND);
        var graphic = new esri.Graphic(point, symbol);
        var outSR = new esri.SpatialReference({ wkid: 27700});
       
        map.graphics.add(graphic);
        gsvc.project([ point ], outSR, function(projectedPoints) {
          pt = projectedPoints[0];
          graphic.setInfoTemplate(new esri.InfoTemplate("HERE?",
            "<p> X: " + pt.x +
            "<br/> Y: " + pt.y +
            "</p>"  +
            "<input type='button' value='CONFIRM' onclick='mapReady(map);' />" +
            "<div id='latlong'></div>"));
          map.infoWindow
            .setTitle(graphic.getTitle())
            .setContent(graphic.getContent())
            .show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));
        });
    }


function mapReady(map){
//function executeIdentifyTask(){
alert("line 87");
       dojo.connect(map,"onLoad",executeIdentifyTask);
       //create identify tasks and setup parameters 
       identifyTask = new esri.tasks.IdentifyTask("http://bl-arcgis-1/ArcGIS/rest/services/CRM/MapServer");
       
       identifyParams = new esri.tasks.IdentifyParameters();
    identifyParams.tolerance = 3;
       identifyParams.returnGeometry = false;
       identifyParams.layerIds = [1,2,3,4];
       identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
       identifyParams.width  = map.width;
       identifyParams.height = map.height;
     alert("Line 98") }
    
      function executeIdentifyTask(evt) {
        identifyParams.geometry = evt.mapPoint;
    // identifyParams.geometry = evt.screenPoint;
        identifyParams.mapExtent = map.extent;
       
        var deferred = identifyTask.execute(identifyParams);

        deferred.addCallback(function(response) {     
          // response is an array of identify result objects    
          // Let's return an array of features.
          return dojo.map(response, function(result) {
            var feature = result.feature;
            feature.attributes.layerName = result.layerName;
            if(result.layerName === 'Adopted Highways'){
             // console.log(feature.attributes.PMH);
              var template = new esri.InfoTemplate("DKDKDKDKDK","PMH:${PMH}");
              feature.setInfoTemplate(template);
            }
            else if (result.layerName === 'Council Owned'){
              var template = new esri.InfoTemplate("BCO","BCO:${BCO}");
              feature.setInfoTemplate(template);
            }
   else if (result.layerName === 'LSVT'){
              var template = new esri.InfoTemplate("LSVT","LSVT:${LSVT}");
              feature.setInfoTemplate(template);
            }
   else if (result.layerName === 'Ward'){
              var template = new esri.InfoTemplate("NAME","NAME:${NAME}");
              feature.setInfoTemplate(template);
            }
            return feature;
          });
        });

      
        // InfoWindow expects an array of features from each deferred
        // object that you pass. If the response from the task execution 
        // above is not an array of features, then you need to add a callback
        // like the one above to post-process the response and return an
        // array of features.
        map.infoWindow.setFeatures([ deferred ]);
        map.infoWindow.show(evt.mapPoint);
      }
      dojo.ready(initialize);
    </script>

Outcomes