map hang after click during first data load

882
5
09-06-2017 07:06 AM
RobertDawidziuk1
New Contributor

I have an issue during map load.

At the begining when map is waiting for the data from arcgis server (data for feature layer) and I click on map on feature map hang and do not pan. It is in moment when layer widget display progress.

In console:

   

TypeError: Cannot read property 'position' of undefined
at Object.b.hitTest (js.arcgis.com/4.4/esri/views/MapView.js:699)
at Object.c.hitTest (js.arcgis.com/4.4/esri/views/MapView.js:694)
at js.arcgis.com/4.4/esri/views/MapView.js:735
at Array.map (<anonymous>)
at Object.c.hitTest (js.arcgis.com/4.4/esri/views/MapView.js:735)
at Object._clickHandler (js.arcgis.com/4.4/init.js:2063)
at js.arcgis.com/4.4/init.js:49
at a._callback (js.arcgis.com/4.4/esri/views/MapView.js:625)
at c._handleEvent (js.arcgis.com/4.4/esri/views/MapView.js:560)
at Object.eventCallback (js.arcgis.com/4.4/esri/views/MapView.js:556)
at Object.b._doNewPropagation (js.arcgis.com/4.4/esri/views/MapView.js:540)
at Object.b._emitInputEvent (js.arcgis.com/4.4/esri/views/MapView.js:540)
at Object.emit (js.arcgis.com/4.4/esri/views/MapView.js:532)
at Object.onEmit (js.arcgis.com/4.4/esri/views/MapView.js:558)
at a.emit (js.arcgis.com/4.4/esri/views/MapView.js:561)

I use 4.4 , osm with feature layers.

I need to refresh page to work.

When I wait until progress above layerList widget stops and than pan and click it is ok, map do not hang.

Is it a bug or I can prevent hitTest before first load is finished ?

Do You know any workaround ?

Regards,

Robert

5 Replies
ThomasSolow
Occasional Contributor III

I can replicate this.  Seems like a bug to me.

You should be able to fix by wrapping your hitTest in a promise that resolves when the view loads, ie: 

view.on('click', e => {
  view.then(v => {
    v.hitTest({x: e.x, y: e.y}).then(results => console.log(results));
  });
});

// another option would be to only add the click event when the view has loaded

view.then(v => {
  view.on('click', e => {
    v.hitTest({x: e.x, y: e.y}).then(results => console.log(results));
  });
});

Either way, I believe the intended behavior is for the view to warn the user that it's not ready when this happens.

ThomasSolow
Occasional Contributor III

I'm actually not sure if either of these will fix the issue, looking into this further.

May have to do with clicking on the map when the view has loaded, but the layerView for the layer in question is still loading.

ThomasSolow
Occasional Contributor III

To follow up, this is caused by a layer view not being entirely set up when hitTest is called.  I don't know of a simple way to get around this error.  It's an edge case that probably hasn't been noticed because there's only a small ms window when it will occur.

You could check the layerView for each layer and make sure each layerView has a controller before proceeding with the hitTest.  That's not really ideal, but it would look like this:

view.on('click', e => {
  e.stopPropagation();
  const lyrsReady = view.layerViews.toArray().every(lv => lv.controller);
  if (lyrsReady){
    view.hitTest(e).then(r => console.log(r)); 
  }
});

The other thing to note is that hitTest is used as part of the popup logic, so it's entirely possible that you'll run into this error even when you're not manually using hitTest, in which case this won't help.

williampreston
New Contributor II

This bug has not been addressed for months. Would love for ESRI to gain some courage and get it fixed. Another way to replicate this issue is when a layer fails to load anywhere in the application, then hitTest(..) fails, and it crashes down the whole application. 

ThomasSolow
Occasional Contributor III

Please post a sample or provide steps to reproduce.  My current understanding is that this bug will only occur when the layer loads, the layerView loads, but then the layer's controller fails to load.  So this shouldn't be an issue if the layer itself doesn't load.

0 Kudos