-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Description
The regex used to determine the prefix for the path to an icon's default image in src/layer/marker/Icon.Default.js breaks when there's another JavaScript source file included which has leaflet as part of a preceding script tag's src attribute.
Take a look at the following code fragment ...
<script type="text/javascript" src="https://raw.github.com/mapstraction/mxn/release-2.1/source/mxn.leaflet.core.js"></script>
<script type="text/javascript" src="http://cdn.leafletjs.com/leaflet-0.5/leaflet.js"></script>When L.Icon.Default.imagePath runs the regex /\/?leaflet[\-\._]?([\w\-\._]*)\.js\??/ over all instances of the script tag, it should ignore the first script tag and act on the second, matching /leaflet.js and returning http://cdn.leafletjs.com/leaflet-0.5 which is then used to construct the path to marker-shadow.png and marker-icon.png, such as http://cdn.leafletjs.com/leaflet-0.5/images/marker-icon.png.
But what's actually happening is that the regex acts on the first instance of the script tag, as it matches leaflet.core.js and returns the path as https://raw.github.com/mapstraction/mxn/release-2.1/source/mxn., which means the using the default Marker results in a 404 for https://raw.github.com/mapstraction/mxn/release-2.1/source/mxn./images/marker-icon.png, which of course, doesn't exist (ditto for marker-shadow.png).
My regex expertise is shabby to say the least, but from experimenting and assuming that the Leaflet root directory will always be called leaflet, changing the regex to /\/leaflet[\-\._]?([\w\-\._]*)\.js\??/ seems to work (note the dropping of the ? metacharacter) when using a local install of Leaflet cloned from GitHub
At best, this is a temporary workaround fix, but this looks like a bug to me; but don't take my regex for granted ... I don't have the insight to say whether the above assumption is valid or not.