Select to view content in your preferred language

Print widget does not print latest layer changes until zooming/panning occurs

815
6
Jump to solution
04-18-2024 11:15 PM
tamasoz
Emerging Contributor

Hi,

I have noticed a rather odd behavior within Experience Builder - though this might be related to the actual JavaScript API.


I created a custom widget - this is all fine works as expected. With the widget I programmatically create several Feature Layers, add it to the map, enabling users to add and remove features from this layer - this also works as expected. When I add the layer from the code the legend and layer widget automatically get updated as expected - so that also works.


Everything is fine - but when we try to print the odd behavior was encountered. If the user adds to polygon shapes to the feature layer with the custom-made tool- it works fine. Then if the user pans/zooms away and prints out the map using a print widget and the associated print service - again it is fine, printing how it should.

However - if the user adds/deletes a feature and clicks the print button again without any panning and zooming - the print tool does not print out the these changes untill panning/zooming occurs. My code logic uses the standard way of operating on feature layer using the applyEdit() function.


For instance - the delete function from the widget as follows:


  removeCircuitArea = (evt=>

        if (this.mapView.view.map.layers.filter(c => c.title === 'Scraper Circuit Area').length !== 0)
           this.scraperCircuitAreaLayer.queryFeaturesgeometry: evt.mapPointspatialRelationship: "intersects"returnGeometry: trueoutFields: ["*"] ).then((featureset=>
                let delfeatures: any[] = [];
                featureset.features.forEach(f => delfeatures.push(f));
                const deleteEdits = deleteFeatures: delfeatures
                this.scraperCircuitAreaLayer.applyEdits(deleteEdits);
            )

As far as I can see my code follows up recommended routines.


But somehow it seems like something is not being refreshed - so the print widget does not pick up the changes.

Can anyone tell me what are those object(s) that needs to be looked at and refreshed/reloaded/revisited?

PS calling the featureLayer.refresh() method does not make any changes in this case. Also - using the Edit widget on a real feature layer does not have this issue - removing a feature using Edit tool immediately gets reflected in a printout without any additional panning/zooming.

Thanks

0 Kudos
1 Solution

Accepted Solutions
JeffreyThompson2
MVP Regular Contributor

I suspect that the Print Widget is storing the current appearance of the map into its internal state and printing from that version. My cheaty suggestion to fix it without having to modify the Print Widget is to try to trigger whatever useEffect() function in the Print Widget tracks the map extent. I would first try capturing the current map extent and feeding directly back into the gotTo() function like this...

const extent = mapView.view.extent
mapView.view.goTo(extent)
GIS Developer
City of Arlington, Texas

View solution in original post

0 Kudos
6 Replies
JeffreyThompson2
MVP Regular Contributor

I suspect that the Print Widget is storing the current appearance of the map into its internal state and printing from that version. My cheaty suggestion to fix it without having to modify the Print Widget is to try to trigger whatever useEffect() function in the Print Widget tracks the map extent. I would first try capturing the current map extent and feeding directly back into the gotTo() function like this...

const extent = mapView.view.extent
mapView.view.goTo(extent)
GIS Developer
City of Arlington, Texas
0 Kudos
tamasoz
Emerging Contributor

Jeffrey, Thanks for the reply - regrettably this hack didn't do much - the printout still shows up the deleted polygon. 

0 Kudos
JeffreyThompson2
MVP Regular Contributor

Expanding on the idea above. Maybe you could change the extent slightly.

const extent = mapView.view.extent
//Should create an extent 1% larger than the original size.
const newExtent = extent.expand(1.01)
mapView.view.goTo(newExtent)

//optional: reset extent
setTimeout(()=> {
   mapView.view.goTo(extent)
}, 3000)

https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-Extent.html#expand

GIS Developer
City of Arlington, Texas
0 Kudos
BolanChen
Occasional Contributor

Please confirm whether the features you want to delete in the Map have been deleted when you click Print. If the corresponding features in the Map widget have not been deleted when printing, then the phenomenon you see is in line with expectations.

0 Kudos
tamasoz
Emerging Contributor

Thanks for the reply BolanChen,

Well I did a quick check by sending the this.scraperCircuitAreaLayer.queryFeatureCount() promise to the console immediately after issuing the applyEdits with the deletefetaures - when the Promise is fulfilled it then shows the same number of features before the delete - but I suspect this is not a significant issue - probably this promise is executed faster than the actual delete.

If I delete another feature then this feature count number indeed decreased by one - so technically the applyEdits() with the delete payload does work and I indeed see these features disappearing from the map. But no matter how many I delete - if I don't zoom or pan these deleted ones are still in the printout.

But if you have any other ideas what I should check please let me know.

 

0 Kudos
tamasoz
Emerging Contributor

Since I don't have more time to carry on looking for the needle in the haystack I accept @JeffreyThompson2 recommendations - whilst that code doesn't yield any result as it doesn't kick off a map reload/redraw cycle but technically I hack my solution to work in this way.

I have hidden a small zoomout event in the user's workflow that doesn't compromise the user experience yet ensures that the printout reflects everything that is in the feature layers.

I'm still not sure if I made the mistake in the code or this is some very obscure bug that has been worked around in the Edit widget (that works fine with a real Feature Layer coming from Enterprise). Alas I leave this issue behind now and thanks for the help.

0 Kudos