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