Snapping with SketchViewModel for JimuLayerView Layer

196
2
Jump to solution
3 weeks ago
Labels (1)
VenkataSrikanthDasari
Frequent Contributor

Hi all & @RobertScheitlin__GISP @JeffreyThompson2  ,

I was trying to apply snapping functionality in the SketchViewModel using experience builder custom widget. Here is the code I was using.

this.sketchViewModel=new SketchViewModel({
           view:this.state.jimuMapView.view,
           layer:this.GraphicsLayer,
           pointSymbol: jsonUtils.fromJSON(defaultSnapSymbol) as any,
})
this.sketchViewModel.snappingOptions= {
           enabled: true, // global snapping is turned on
           selfEnabled: true,
           featureEnabled: true,
           featureSources: this.getDefaultSnapSources(this.state.jimuMapView,["dataSource_1-name_6192-48"])
}

getDefaultSnapSources = (jimuMapView: JimuMapView, defaultSnapLayers) => {
             if (!jimuMapView) return []
             //await jimuMapView.whenAllJimuLayerViewLoaded()
             if (!jimuMapView?.jimuLayerViews) return []
                          const allViewLayerKeys = Object.keys(jimuMapView.jimuLayerViews)
                          const snapLayersSources = allViewLayerKeys.filter(layerViewId => {
                          return                                                    defaultSnapLayers?.includes(jimuMapView.jimuLayerViews[layerViewId].layerDataSourceId)
             }).map(lvId => {
             return {
                          layer: jimuMapView.jimuLayerViews[lvId].layer,
                          enabled: true
                          }
             })
             return snapLayersSources
}

 

Thanks

Srikanth

0 Kudos
1 Solution

Accepted Solutions
VenkataSrikanthDasari
Frequent Contributor

Thanks for responding.

I identified the root cause of the issue: JimuLayerView should not be used, and snapping is only supported on FeatureLayer, GraphicsLayer, and a few others. To resolve this, I created a new FeatureLayer and added it to the map.

View solution in original post

0 Kudos
2 Replies
Allen_Zhang
Frequent Contributor

Code seems good.

Error messages and snapshots will help.

0 Kudos
VenkataSrikanthDasari
Frequent Contributor

Thanks for responding.

I identified the root cause of the issue: JimuLayerView should not be used, and snapping is only supported on FeatureLayer, GraphicsLayer, and a few others. To resolve this, I created a new FeatureLayer and added it to the map.

0 Kudos