Select to view content in your preferred language

IdentifyTask + InfoWindow 'Zoomto' button using wrong spatial reference

3957
13
Jump to solution
05-16-2014 08:43 AM
MS
by
Occasional Contributor
Hi

I'm using the following parameters in an identify task:

            var identifyParams = new IdentifyParameters();             identifyParams.tolerance = this.identifyTolerance;             identifyParams.returnGeometry = true;             identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_VISIBLE;             identifyParams.geometry = evt.mapPoint;             identifyParams.mapExtent = this.map.extent;          identifyParams.spatialReference = this.map.spatialReference;             identifyParams.width = this.map.width;             identifyParams.height = this.map.height;


Problem is, when I get the infoWindow when clicking on the map, I receive the following error:

Map: Geometry (wkid: 4326) cannot be converted to spatial reference of the map (wkid: 2151)

I'm struggling to understand where the wkid 4326 is coming from, as everything to and from the identifyTask is in 2151.  I've debugged the code to note that yes, 'this.map.spatialReference' is of wkid 2151.  I've logged the network traffic going to our ArcGIS Server, and yes, the request being sent includes a spatial reference of wkid 2151 in the URL.  I've looked at the MapService that it's doing the identify on, and the MapService is of wkid 2151.  I tried going right to the identify task right on the ArcGIS Server via a web browser, put in my variables at performed an Identify there, and it gave me back the right spatial reference as well.

Anyone have any idea where the 'geometry of wkid 4326' is coming from?
0 Kudos
1 Solution

Accepted Solutions
MS
by
Occasional Contributor
Just updating this now that I have it working.  I had to set the spatial reference of each individual feature coming from the result set right before adding it to the infotemplate, ie

result.feature.geometry.spatialReference = this.map.spatialReference;

Annoying that I have to do it as my map and all my layers are of the same wkid, but at least it now works!

View solution in original post

13 Replies
BenFousek
Deactivated User
Are you using map.graphics for your results? If so, does map.graphics.spatialReference = 4326?

How are you setting the sr of the map? With an extent, center & zoom, or the first layer added?
0 Kudos
MS
by
Occasional Contributor
Are you using map.graphics for your results? If so, does map.graphics.spatialReference = 4326?

How are you setting the sr of the map? With an extent, center & zoom, or the first layer added?


Hi Ben, thank you for your reply.

I'm pretty sure the answer to your first question is no, though I've put my code below for the Identify functionality I'm using - it was taken from the Configurable Viewer template from David Spriggs.  I considered posting the problem over there, but to me this doesn't seem to have anything to do with the template code, so I thought this forum would be more appropriate.

For your second question, I performed a search through all of my code for '4326' and nothing was found.  I also tried 'graphics.spatialReference' which came up with nothing as well.

As for setting the spatial reference of the map, I am using the first layer (I checked that all layers are of wkid 2151).  I did also try setting the spatial reference manually when the map is first created (using extent), and that did not help either.

define([
    'dojo/_base/declare',
    'dijit/_WidgetBase',
    'dojo/_base/lang',
    'dojo/_base/array',
    'esri/lang',
    'esri/tasks/IdentifyTask',
    'esri/tasks/IdentifyParameters',
    'esri/dijit/PopupTemplate',
    'dojo/on',
    'dojo/promise/all',
    './Identify/config'
], function(declare, _WidgetBase, lang, array, esriLang, IdentifyTask, IdentifyParameters, PopupTemplate, on, all, config) {

    var Identify = declare([_WidgetBase], {
        declaredClass: 'gis.dijit.Identify',
        postCreate: function() {
            this.inherited(arguments);
            this.layers = [];
            array.forEach(this.map.layerIds, function(layerId) {
                var layer = this.map.getLayer(layerId);
                if (layer.declaredClass === 'esri.layers.ArcGISDynamicMapServiceLayer') {
                    this.layers.push({
                        ref: layer,
                        identifyTask: new IdentifyTask(layer.url)
                    });
                }
            }, this);
            this.map.on('click', lang.hitch(this, function(evt) {
                if (this.mapClickMode.current === 'identify') {
                    this.executeIdentifyTask(evt);
                }
            }));
        },
        executeIdentifyTask: function(evt) {
            this.map.infoWindow.hide();
            this.map.infoWindow.clearFeatures();
            this.map.infoWindow.setTitle('Identifing...');
            this.map.infoWindow.setContent('<img src="images/loading.gif" style="height:20px;width:20px;margin-top:5px"></img>');
            this.map.infoWindow.show(evt.mapPoint);

            var identifyParams = new IdentifyParameters();
            identifyParams.tolerance = this.identifyTolerance;
            identifyParams.returnGeometry = true;
            identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_VISIBLE;
            identifyParams.geometry = evt.mapPoint;
            identifyParams.mapExtent = this.map.extent;
            identifyParams.width = this.map.width;
            identifyParams.height = this.map.height;

            var identifies = [];
            var identifiedlayers = [];
            array.forEach(this.layers, function(layer) {
                if (layer.ref.visible && layer.ref.visibleLayers.length !== 0 && layer.ref.visibleLayers[0] !== -1) {
                    var params = lang.clone(identifyParams);
                    params.layerIds = layer.ref.visibleLayers;
                    identifies.push(layer.identifyTask.execute(params));
                    identifiedlayers.push(layer);
                }
            });

            all(identifies).then(lang.hitch(this, 'identifyCallback', identifiedlayers), function(err) {
                console.log('identify tasks error: ', err);
            });
        },
        identifyCallback: function(identifiedlayers, responseArray) {
            var fSet = [];
            array.forEach(responseArray, function(response, i) {
                var layerId = identifiedlayers.ref.id;
                array.forEach(response, function(result) {
                    // see if we have a Popup config defined for this layer
                    if (config.hasOwnProperty(layerId)) {
                        if (config[layerId].hasOwnProperty(result.layerId)) {
                            result.feature.setInfoTemplate(new PopupTemplate(config[layerId][result.layerId]));
                        }
                    }
                    // if no Popup defined output all attributes
                    if (result.feature.infoTemplate === undefined) {
                        result.feature.setInfoTemplate(new PopupTemplate({
                            title: result.layerName,
                            description: esriLang.substitute(result.feature.attributes)
                        }));
                    }
                    fSet.push(result.feature);
                }, this);
            }, this);
            this.map.infoWindow.setFeatures(fSet);
        }
    });

    return Identify;
});
0 Kudos
BenFousek
Deactivated User
For your second question, I performed a search through all of my code for '4326' and nothing was found.  I also tried 'graphics.spatialReference' which came up with nothing as well.


What does
map.graphics.spatialReference.wkid
return in console?
0 Kudos
MS
by
Occasional Contributor
What does
map.graphics.spatialReference.wkid
return in console?


Well you're right, it logged 4326 when I started throwing console.log commands in the js file that I posted above.

I tried setting map.graphics.spatialReference to be 2151 right after the initial map event of 'layers-add-result', and the console.log commands in the identify task code then show the correct value, but...It still gives me the exact same error when trying to zoom:

Map: Geometry (wkid: 4326) cannot be converted to spatial reference of the map (wkid: 2151)
0 Kudos
BenFousek
Deactivated User
map.graphics should match the sr of the map (expect in the case of web mercator where map.graphics is 4326). I'm not sure why yours does not. My guess it's because you are using a layer to set map sr. map.graphics is created when the map is constructed, i.e. before you add the first layer. Try an extent of your sr in the map constructor.

In general I try to avoid using map.graphics. Try creating a graphics layer just for your id results.
0 Kudos
MS
by
Occasional Contributor
Just updating this now that I have it working.  I had to set the spatial reference of each individual feature coming from the result set right before adding it to the infotemplate, ie

result.feature.geometry.spatialReference = this.map.spatialReference;

Annoying that I have to do it as my map and all my layers are of the same wkid, but at least it now works!
ToddAtkins
Frequent Contributor
Just updating this now that I have it working.  I had to set the spatial reference of each individual feature coming from the result set right before adding it to the infotemplate, ie

result.feature.geometry.spatialReference = this.map.spatialReference;

Annoying that I have to do it as my map and all my layers are of the same wkid, but at least it now works!


Thank you for this. I've spent way too much time the last couple of days trying to figure out why this wasn't working.

I even copy/pasted the code from here which works fine in the demo but no matter what I did it wouldn't work correctly for any other service--I'd get the infowindow just fine with the correct info but the graphic and "Zoom To" were both broken. For what it's worth, all our services and features are in wkid 102100.
0 Kudos
RoyJackson1
Deactivated User
result.feature.geometry.spatialReference = this.map.spatialReference;



This fixed the zoom to button going to random spot, as well as the graphic selection from being seen.  THanks!
0 Kudos
deleted-user-Jie3eyjOl9XM
Deactivated User

Using the 3.10 JSAPI, I experienced the same problem, where the geometries being returned were in 4326 rather than the WKID of the map. Even when I set the SpatialReference of the IdentifyParams. Like M S , I resorted to manually setting the spatial reference of the returned geometries. Using Fiddler, I could see that no spatial ref was on the geometries coming back from server, so it seems like an issue with the JSAPI. Since it doesn't always happen, there's probably a special set of circumstances, like a map declared without a basemap, and then adding a non-webmercator basemap.

0 Kudos