angularesriarcgis-js-apiweather-api

Unable to show weather information on map using ArcGIS Js api


I am getting this error after adding weather service layer I have added traffic layer as well in the same way only the url is different
[esri.views.2d.layers.MapImageLayerView2D] TypeError: Cannot read properties of null (reading 'supportsDynamicLayers') at l.fetchImage (MapImageLayer.js:5:4430) at l.fetchImage (MapImageLayerView2D.js:5:2577) at l._export (ExportStrategy.js:5:2787) at l._singleExport (ExportStrategy.js:5:3092) at ExportStrategy.js:5:2011 at l.s [as update] (promiseUtils.js:5:2854) at l.update (MapImageLayerView2D.js:5:1184) at l.processUpdate (LayerView2D.js:5:2547) at a._updateLayerView (FrameTask.js:5:1982) at Array.forEach ()

const weatherLayer = new MapImageLayer({     url:"https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/NWS_Watches_Warnings_v1/FeatureServer",
                         sublayers: [
                            {
                              id: 0,
                              visible: true
                            },
                            {
                              id: 1,
                              visible: true
                            },
                            {
                              id: 2,
                              visible: false
                            },
                            {
                              id: 3,
                              visible: false
                            },
                            {
                              id: 4,
                              visible: false
                            },
                            {
                              id: 5,
                              visible: false
                            },
                            {
                              id: 6,
                              visible: false
                            },
                            {
                              id: 8,
                              visible: false
                            },
                            {
                              id: 9,
                              visible: false
                            },
                            {
                              id: 10,
                              visible: false
                            },
                            {
                              id: 11,
                              visible: false
                            },
                            {
                              id: 12,
                              visible: false
                            }
                          ] })
                
                        this.map = new Map({
                                basemap: "streets-vector",
                                layers: [trafficLayer,weatherLayer]
                              });
                
                        this.mapView = new MapView({
                                map: this.map,
                                center: [US_LON_CENTER, US_LAT_CENTER],
                                zoom: ZOOM_LEVEL,
                                container: this.mapViewElement.nativeElement
                              });
    

Solution

  • The URL you are using is a "FeatureLayer". Note the end of the URL that says "FeatureServer" -- https://services9.arcgis.com/RHVPKKiFTONKtxq3/arcgis/rest/services/NWS_Watches_Warnings_v1/FeatureServer

    So instead of the MapImageLayer class, you need to use a FeatureLayer. That also means you need to remove the sublayers parts which seems to be a copy-paste from somewhere else and not related to that NWS_Watches_Warnings_v1 service.