Ticket #3499 (closed bug: fixed)

Opened 21 months ago

Last modified 15 months ago

OpenLayers Custom Build _getScriptLocation not working properly

Reported by: ckreuzbe Owned by:
Priority: minor Milestone: 2.12 Release
Component: general Version: 2.10
Keywords: images getScriptLocation custom build filename different Cc:
State: Review

Description

OpenLayers/SingleFile.js, Line 27:

    _getScriptLocation: (function() {
        var r = new RegExp("(^|(.*?\\/))(OpenLayers\.js)(\\?|$)"),

This function tries to find the OpenLayers.js file in the html elements that are including javascript resources. However, when trying to do a custom build like this:

python build.py -c closure mainMap ../OpenLayers-mainMap.js

(yes the closer compiler is installed properly)

while mainMap.cfg looks like this:

[first]

[last]

[include]
OpenLayers/SingleFile.js
OpenLayers/Control.js
OpenLayers/Control/ZoomPanel.js
OpenLayers/Control/MousePosition.js
OpenLayers/Control/Navigation.js
OpenLayers/Control/Permalink.js
OpenLayers/Control/Attribution.js
OpenLayers/Control/PanZoomBar.js
OpenLayers/Control/SelectFeature.js
OpenLayers/Control/NavigationHistory.js
OpenLayers/Rule.js
OpenLayers/Icon.js
OpenLayers/Marker.js
OpenLayers/Projection.js
OpenLayers/Feature/Vector.js
OpenLayers/Feature/WFS.js
OpenLayers/Format/JSON.js
OpenLayers/Format/GeoJSON.js
OpenLayers/Filter.js
OpenLayers/Filter/FeatureId.js
OpenLayers/Filter/Function.js
OpenLayers/Filter/Spatial.js
OpenLayers/Protocol/HTTP.js
OpenLayers/Protocol/WFS.js
OpenLayers/Protocol/WFS/v1_0_0.js
OpenLayers/Strategy/Fixed.js
OpenLayers/Map.js
OpenLayers/Renderer/SVG.js
OpenLayers/Renderer/VML.js
OpenLayers/Renderer/Canvas.js 
OpenLayers/Layer.js
OpenLayers/Layer/SphericalMercator.js
OpenLayers/Layer/XYZ.js
OpenLayers/Layer/WMS.js
OpenLayers/Layer/Vector.js
OpenLayers/Layer/Markers.js
OpenLayers/Layer/TMS.js
OpenLayers/Layer/Google/v3.js



[exclude]

you will not see any control images on your website, because getScriptLocation will NOT find OpenLayers.js at all (because the file is called OpenLayers-mainMap.js).

One might ask: Why do you not just rename OpenLayers-mainMap.js to OpenLayers.js? Because I want to have a few different custom build profiles. so yeah, I could start playing around with symbolic links and other hacks, but that's not the point. The library should be able to find itself easily. I do understand that it is not possible to support every possible filename, however it is possible to come up with a clever way of how to do this.

a) look for OpenLayers*.js

b) look for OpenLayers.js first, if you can't find it, look for OpenLayers*.js (so you will not break compatibility)

c) give the user a way to specify the actual javascript filename in the source code (e.g. OpenLayers.ScriptFileName='OpenLayers-mainMap.js'; ), and, if possible, include this in the python build script so it sets the default value according to the output-file-name option of build.py.

While option a (and maybe even b) might break compability with other things that are out there, option c should not break anything, and therefor I highly recommend implementing option c).

ideas, objections, other solutions that I have not mentioned?

Change History

  Changed 21 months ago by ckreuzbe

  • state set to Review

I found that this regexp will work for me:

    _getScriptLocation: (function() {
        var r = new RegExp("(^|(.*?\\/))(OpenLayers)([\-0-9a-zA-Z]*)(\\.js)(\\?|$)"),

in reply to: ↑ description   Changed 21 months ago by jorix

I think this is not a bug (is a feature), this is normal behavior. The name should only be OpenLayers.js.

In my case I have the same problem, since I have several compilations: lite and custom.

To change the behavior just add after:

<script src="/Your-location-for-OpenLayers/OpenLayers-mainMap.js" type="text/javascript"></script>

this line:

<script>
OpenLayers._getScriptLocation = function(){return "/Your-location-for-OpenLayers/"};
</script>

But this is not a "medicine" supported by the APIs. It would be nice to be so!

... c) give the user a way to specify the actual javascript filename in the source code (e.g. OpenLayers.ScriptFileName='OpenLayers-mainMap.js'; ), and, if possible, include this in the python build script so it sets the default value according to the output-file-name option of build.py.

instead of OpenLayers.ScriptFileName='OpenLayers-mainMap.js'; I like:

OpenLayers.setScriptLocation="/Your-location-for-OpenLayers/";

NOTE: I'm not a member of the team OpenLayers.

  Changed 15 months ago by ahocevar

  • status changed from new to closed
  • resolution set to fixed

Fixed by better documentation of what has to be included in the html page and how:  https://github.com/openlayers/docs/commit/d56372996c12214d3700d5a5b9c697733f8e92e9

Note: See TracTickets for help on using tickets.