Ticket #3499 (closed bug: fixed)
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?
