AnsweredAssumed Answered

Accessing Geoserver WMS with popup using ArcGIS Javascript API 4.7

Question asked by humpy1252 on May 22, 2018
Latest reply on Aug 12, 2018 by humpy1252

I have been building a map interface that loads road networks from ArcGIS Server. One of the requirements is to display current road works.

 

We have an existing application that records locations and extent of road works. This road works app uses Geoserver as the layer repository.

 

I have added the roadworks to my ArcGIS Javascript using the WMSLayer. I was having some issues getting the popup to work. This error was showing in thedeveloper window:

dojo.js:249 [esri.widgets.FeatureViewModel] error loading template SyntaxError: Unexpected number in JSON at position 1
at JSON.parse (<anonymous>)
at b (dojo.js:258)
at Object.<anonymous> (dojo.js:263)
at dojo.js:42
at String.replace (<anonymous>)
at Object.replace (dojo.js:44)
at Object.substitute (dojo.js:263)
at Object.c._compileText (FeatureViewModel.js:12)
at Object.c._compileContent (FeatureViewModel.js:8)
at FeatureViewModel.js:22

 

I finally tracked it down to a style element within the html of the popup created in Geoserver. This was defined in the content.ftl of the layer as follows:

<style>
.even{
   background-color: rgba(178, 125, 32, 1);
}
</style>

 

Changing the style to this:

.even{
   background-color: #e1ffed;
}

Resolves the issue.

 

Tracing through the code dojo is attempting to parse the value rgba(178, 125, 32, 1); as JSON. A regular expression within the code was stripping the rgba text and parentheses leaving 178 as the first key/value pair which is subsequently rejected as invalid.

 

This brings me to the reason for posting this. I spent several days trying to find information about this problem with no success. so hopefully it might be usefull for someone else trying to add non ArcGIS WMS layers.

 

Outcomes