Reputation: 1
I am trying to load a geoserver wms layer to a WMSLayer using Esri JS API 4.x, thought the code below loads ok using Esri JS API 3.x
require(["esri/layers/WMSLayer","esri/layers/WMSLayerInfo"],function(WMSLayer,WMSLayerInfo){
var wmsinfo = new WMSLayerInfo();
var resourceInfo = {
extent: Map.extent,
layerInfos: [wmsinfo],
spatialReference: {
wkid: 4326
}
};
var name = "HTM:name_of_layer_on_geoserver.tif";
var url = "www.geoserver.local:8080/geoserver/HTM/wms?";
layer = new WMSLayer(url, {
id: "tempid",
spatialReference: new SpatialReference({ wkid: 3857 }),
resourceInfo: resourceInfo,
visibleLayers: name,
customLayerParameters: {CRS: 'EPSG:3857'}
});
Map.addLayer(layer);
});
now im trying to convert it.
require(["esri/layers/WMSLayer"],function(WMSLayer){
//var wmsinfo = new WMSLayerInfo(); //<-this is deprecated, what would be the equivalent.
var resourceInfo = {
extent: View.extent,
layerInfos: [],
spatialReference: {
wkid: 4326
}
};
var name = "HTM:name_of_layer_on_geoserver.tif";
var url = "www.geoserver.local:8080/geoserver/HTM/wms?";
//moved url to properties, instead of inline argument
layer = new WMSLayer({
id: "tempid",
url:url,
spatialReference: new SpatialReference({ wkid: 3857 }),
resourceInfo: resourceInfo, //this doesnt seem to be available
visibleLayers: name,
customLayerParameters: {CRS: 'EPSG:3857'}
});
layer.load().then(()=>{
Map.addLayer(layer);
});
});
i tried replacing visiblelayer property with sublayer but doesnt seem to work. if i just add it to Map without the load(), it will be white screen, if i do call load(), it will stuck in getcapabilities request. i where lost that a specific class doesnt have equivalent or samples that will load a single layer rather than the all layers available in the server.
what am i missing?
Upvotes: 0
Views: 64
Reputation: 5270
The sublayers
property indicates the collection of layers to be displayed, objects of class WMSSubLayer
(ArcGIS JS API - WMSSublayer). That is the class you are looking for, the one that "replace" WMSLayerInfo
of api 3.
Once you load
, you can play with the layers of the resource and their properties. There are a couple of examples both in the specification of WMSSubLayer
(link above), and on WMSLayer
(ArcGIS JS API- WMSLayer sublayers)
Upvotes: 1