WMS Open BC Data - with ResourceInfo (Non Proxy)

960
3
Jump to solution
08-08-2018 01:06 PM
DouglasLong
Occasional Contributor

Hey Folks,

having trouble adding a WMS from BC open data, into my application that is not using a proxy.

An example layer is here on the BC government website.

Correctional Facilities - WMS getCapabilities request - Data Catalogue 

this example works fine with the following code. however since their sandbox uses a proxy, it works fine and no 'ResourceInfo' object is needed.

<script>
var map;

require(["esri/map", "esri/layers/WMSLayer", "esri/config", "dojo/domReady!"],
function(Map, WMSLayer, esriConfig) {

esriConfig.defaults.io.proxyUrl = "/proxy/";
esriConfig.defaults.io.corsEnabledServers.push("openmaps.gov.bc.ca");

map = new Map("map", {
basemap: "streets",
center: [-98, 37],
zoom: 5
});

var wmsLayer = new WMSLayer("https://openmaps.gov.bc.ca/geo/pub/WHSE_IMAGERY_AND_BASE_MAPS.GSR_CORRECTNL_FACILITIES_SV/ows", {
format: "png",
visibleLayers: [0]
});

map.addLayer(wmsLayer);
});
</script>

however in my application this simply won't work, as I don't have a proxy. I am a bit clueless what I should add for resource info and have tried many other combinations.

Anyone have any luck with this? 

0 Kudos
1 Solution

Accepted Solutions
DouglasLong
Occasional Contributor

Alright. this was dumb. I am using ESRI Identity Manager to register my (NODE JS/Express) generated token.

after registering the Arc Server I am using, it adds the following to my list of cors enabled servers. "null/undefined".

anyways long story short, just loop the array of cors enabled servers, and remove the "null/undefined" item.

here is my code.

MapURL = sesh_inf.SERVER_URL + 'arcgis/rest/services';

IdentityManager.registerToken({
      server: MapURL,
      token: sesh
});

var a = esriConfig.defaults.io.corsEnabledServers.indexOf("null://undefined");
if (a > -1) {
   esriConfig.defaults.io.corsEnabledServers = "http://localhost:1337";
}

View solution in original post

0 Kudos
3 Replies
DouglasLong
Occasional Contributor

I have been trying both MapServiceLayer and WMSLayer but no luck, tried with resource Info as well.

var temp_wms = new ArcGISDynamicMapServiceLayer("https://openmaps.gov.bc.ca/geo/pub/WHSE_BASEMAPPING.FWA_STREAM_NETWORKS_SP/ows?service=WMS&request=G...",
{
visibleLayers: [1]
}
);
temp_wms.id = "bc data";

also tried this

var temp_wms = new WMSLayer("https://openmaps.gov.bc.ca/geo/pub/WHSE_BASEMAPPING.FWA_STREAM_NETWORKS_SP/ows?service=WMS&request=G...",
{
visibleLayers: [1]
}
);
temp_wms.id = "bc data";

map.addLayers([temp_wms]);

will post more as I go. note I am using 3.25 esri js

0 Kudos
DouglasLong
Occasional Contributor

Also, when I run it with resource Info I continuously get the same error.

I went to the sandbox for the WMS layer, and I can load it no problem, just not in my application.

var layer1 = new WMSLayerInfo({
name: 'pub:WHSE_IMAGERY_AND_BASE_MAPS.GSR_CORRECTNL_FACILITIES_SV',
title: "DataBC Public Web Map Service"
});

var resourceInfo = {
extent: new Extent(-139.0522011144567, 47.632141441632584, -110.42769916022715, 60.59852435568218, {
wkid: 4326
}),
layerInfos: [layer1],
copyright: "NONE",
description: "A compliant implementation of WMS plus most of the SLD extension (dynamic styling). Can also generate PDF, SVG, KML, GeoRSS",
featureInfoFormat: "text/html",
getFeatureInfoURL: "https://openmaps.gov.bc.ca/geo/pub/WHSE_IMAGERY_AND_BASE_MAPS.GSR_CORRECTNL_FACILITIES_SV/ows",
getMapURL: "https://openmaps.gov.bc.ca/geo/pub/WHSE_IMAGERY_AND_BASE_MAPS.GSR_CORRECTNL_FACILITIES_SV/ows",
spatialReferences: [3857, 4326],
version: "1.3.0"
};

var temp_wms = new WMSLayer('https://openmaps.gov.bc.ca/geo/pub/WHSE_IMAGERY_AND_BASE_MAPS.GSR_CORRECTNL_FACILITIES_SV/ows', {
resourceInfo: resourceInfo,
visibleLayers: ["pub:WHSE_IMAGERY_AND_BASE_MAPS.GSR_CORRECTNL_FACILITIES_SV"],
format: "png"
});

0 Kudos
DouglasLong
Occasional Contributor

Alright. this was dumb. I am using ESRI Identity Manager to register my (NODE JS/Express) generated token.

after registering the Arc Server I am using, it adds the following to my list of cors enabled servers. "null/undefined".

anyways long story short, just loop the array of cors enabled servers, and remove the "null/undefined" item.

here is my code.

MapURL = sesh_inf.SERVER_URL + 'arcgis/rest/services';

IdentityManager.registerToken({
      server: MapURL,
      token: sesh
});

var a = esriConfig.defaults.io.corsEnabledServers.indexOf("null://undefined");
if (a > -1) {
   esriConfig.defaults.io.corsEnabledServers = "http://localhost:1337";
}

0 Kudos