2

I run the sample code at here: http://jsfiddle.net/1a948faa/2/.

When I add the ol-debug.js to sample, it run successfully. But when I add ol.js file to sample, it does not work properly. What's the problem?

what's difference between ol.debug.js and ol.js files?

3

You second question about the difference between ol.js and ol-debug.js got resolved pretty nicely by @MappaGnosis, however your main question still waits for an explanation.

In the fiddle, you have used the goog class. It is a native class of Google's Closure Library, which is OpenLayers 3 built with. It has tons of convenience functions, making sure everything will be cross-browser compliant in the finish. This way, the developers can concentrate on the OpenLayers 3 specific parts. In the compiled version, the Closure specific parts get removed, therefore using goog will create an error.

On the other hand, the source version, ol-debug.js has to work without compiling the library with Closure. The only way to achieve this, is to concatenate the required parts (Closure specific ones included) in a single file. This way, with the debug version, the Closure functions starting with goog, will be perfectly viable. However, using them is not recommended, as the code will break in production mode.

| improve this answer | |
  • With this interpretation: I can's use goog in my code when I add ol.js, yes? – itsme Jul 23 '15 at 10:50
  • 1
    Exactly! You can only use goog with ol-debug.js. – Gabor Farkas Jul 23 '15 at 11:48
  • But how can I do for this question – itsme Jul 23 '15 at 12:19
  • Would the code in the fiddle work for you aside from the goog part? If yes, just replace the goog.isDef(g) part with g instanceof ol.geom.Polygon. – Gabor Farkas Jul 23 '15 at 13:46
4

In simple terms, ol.debug.js is a verbose form of the ol.js file. ol.js should just be a minified version, so there should be no substantive difference in the execution of the code. I have used both and found them to work equally well so I suspect there is a problem in your code or your reference to the ol.js file. One thing to check in your case is that you taged this post for both ol3 and ol2. The api is different between ol3 and ol2 and so ol2 code will not work with the ol3 ol.js file and vice versa.

The point of the minified ol.js is to reduce bandwidth as all comments are removed, variables are reduced to single letters and whitespace is stripped from the file. The downside is that this makes it very hard to debug, hence the availability of the debug version.

| improve this answer | |
  • I tagged openlayers-2 for mistake. thanks for your answer. – itsme Jul 23 '15 at 8:05
  • Great answer! One note though: when the code gets minified in the build process, variables signed with @api get exported unchanged. The unused "classes" get deleted along with the comments. In the debug version, every object, function, and method is available. Therefore it is great to test otherwise obfuscated, or deleted parts of the library before compiling a custom build. – Gabor Farkas Jul 23 '15 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.