Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load icon #5

Open
dixitt5 opened this issue Aug 18, 2023 · 8 comments
Open

Unable to load icon #5

dixitt5 opened this issue Aug 18, 2023 · 8 comments

Comments

@dixitt5
Copy link

dixitt5 commented Aug 18, 2023

I'm able to load leaflet map onto my next js app because of this, thank you for that.

only one problem i'm facing is the marker icon is not showing up, rather looks like this:

image
@dixitt5
Copy link
Author

dixitt5 commented Aug 18, 2023

I would be grateful if you help me overcome this :)

@colbyfayock
Copy link
Owner

hey @dixitt5 i just loaded up the application and am unable to reproduce this issue. are you getting any errors aside from the missing image?

@dixitt5
Copy link
Author

dixitt5 commented Aug 29, 2023

@colbyfayock No, everything is working fine besides the marker icon.

@sebastiancrossa
Copy link

running into the same issue

@colbyfayock
Copy link
Owner

@sebastiancrossa are you simply spinning up the starter from scratch? are you doing anything else? what browser?

@acdoussan
Copy link

I had the same problem, I pulled code out of here into my own project, and the icon wasn't loading.

What i was missing is the webpack config in the next.config.js file. ref:

to: path.resolve(__dirname, 'public', 'leaflet', 'images')

For whatever reason my next config was a mjs file, so I had to make a couple of tweaks to get it to work. Pasted below. Hope this helps.

import * as path from 'path';
import { fileURLToPath } from 'url';
import CopyPlugin from 'copy-webpack-plugin';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
/**
 * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful
 * for Docker builds.
 */
await import("./src/env.mjs");

/** @type {import("next").NextConfig} */
const config = {
  webpack: (config) => {
    config.plugins.push(
      new CopyPlugin({
        patterns: [
          {
            from: 'node_modules/leaflet/dist/images',
            to: path.resolve(__dirname, 'public', 'leaflet', 'images')
          },
        ],
      }),
    )
    return config
  }
};

export default config;

@colbyfayock
Copy link
Owner

oooo @dixitt5 @sebastiancrossa can you see if this resolves your issues as well?

perhaps it makes sense for me to add a comment near where the images are being referenced to help point to this

@p0zi
Copy link

p0zi commented Feb 8, 2024

Since we request images from public dir, paths should start with "/" in file "src/components/Map/DynamicMap.js":

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants