question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

data-urls in L.Icon.Default

See original GitHub issue
  • I’ve looked at the documentation to make sure the behavior is documented and expected
  • I’m sure this is a Leaflet code issue, not an issue with my own code nor with the framework I’m using (Cordova, Ionic, Angular, React…)
  • I’ve searched through the issues to make sure it’s not yet reported

Steps to reproduce

Steps to reproduce the behavior:

  var myIcon = L.Icon.Default.extend({options: {
    iconUrl: 'data:image/png;base64,iVBORw...'
  }});

Expected behavior There is nothing special in data url, so I expect this code to work flawlessly.

Current behavior Unfortunately there is path-guessing magic in code (#4605) which fails to deal with data-url.

Environment

  • Leaflet version: 1.4.0
  • Browser (with version): Google Chrome Version 71.0.3578.98 (Official Build) (32-bit)
  • OS/Platform (with version): Windows 8.1 (32-bit)

Additional context Current workaround:

  L.Icon.Default.imagePath = ' ';

But better to improve magic to take into account data-urls here: https://github.com/Leaflet/Leaflet/blob/61ef1776ac3c7afc5dec5ce4dfab8986ff9f5376/src/layer/marker/Icon.Default.js#L45-L59

Or here: https://github.com/Leaflet/Leaflet/blob/61ef1776ac3c7afc5dec5ce4dfab8986ff9f5376/src/layer/marker/Icon.Default.js#L33-L43

Minimal example reproducing the issue

I haven’t got simple example, but will make if it will be necessary.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

3reactions
jaythomascommented, Oct 9, 2019

@ghybs I originally tried all the suggestions on that thread but couldn’t comment because the thread was locked. With my code verbatim to the code snippet suggested:

import L from 'leaflet';
delete L.Icon.Default.prototype._getIconUrl;

L.Icon.Default.mergeOptions({
  iconRetinaUrl: require('leaflet/dist/images/marker-icon-2x.png'),
  iconUrl: require('leaflet/dist/images/marker-icon.png'),
  shadowUrl: require('leaflet/dist/images/marker-shadow.png'),
});

The icon url strings are being mutated after being passed to the options objects. The only solution I didn’t try was the leaflet-defaulticon-compatibility third-party library and was exploring other possible solutions first.

Edit: Just went back and loaded the leaflet-defaulticon-compatibility library and it works. (Thanks for that link.) I would make a PR to update the readme to suggest this solution so others like me don’t have to hunt through github issues but it seems odd to have the readme link to an unofficial repo to wrap their own library’s css to fix the styling.

0reactions
ghybscommented, Oct 2, 2019

Hi @jaythomas,

The situation you describe is duplicate of #4968.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Alter Leaflet L.Icon.Default - GIS Stack Exchange
Let me quote the Leaflet documentation: In order to change the default icon, just change the properties of L.Icon.Default.prototype.options ...
Read more >
How to use the leaflet.icon function in leaflet - Snyk
To help you get started, we've selected a few leaflet.icon examples, based on popular ways ... delete L.Icon.Default.prototype._getIconUrl; L.Icon.Default.
Read more >
How to change the default icon pin on leaflet directive?
In order to change the default icon, just change the properties of L.Icon.Default.prototype.options (which is a set of Icon options ).
Read more >
Data URIs | CSS-Tricks
(It's equally correct to say “Data URL”, which I think I prefer.) ... This is very useful for small images, e.g. icons, for...
Read more >
embed graphics inline with data uri scheme
The resulting image is a folder icon (cropped screenshot):. folder icon. CSS and Inline Images. Embedded in XHTML files, data URL images are ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found