django-leaflet-admin-list icon indicating copy to clipboard operation
django-leaflet-admin-list copied to clipboard

Modify marker icon, color or size

Open saraivajp opened this issue 2 years ago • 1 comments

Hi,

Thanks for developing this library, very useful. I am just starting to use it and I am also a Django beginner. Could you give an example on how could I modify the marker icon / color / size.

For example, I am trying to modify the marker, but I get a 'non-readable image' icon.

class modelAdmin(LeafletAdminListMixin, LeafletGeoAdminMixin, admin.ModelAdmin):
    ....

    def get_geojson_feature_icon_style(self, request, name, o, queryset):
        return {
            'iconUrl': '.static/piles/images/icon.png',
            'iconSize': [32, 32], 
            'iconAnchor': [16, 32], 
            'popupAnchor': [0, -32], 
        } 

Thanks!

saraivajp avatar Dec 14 '23 13:12 saraivajp

Hi @saraivajp you wrote the proper code, but probably you didn't refer the iconUrl properly, using relative URL. Start the URL from the slash / to have a reference relative from the root of your domain, for example:

  • '/static/piles/images/icon.png' to refer to http://your.domain.name/static/piles/images/icon.png
  • '/.static/piles/images/icon.png' to refer to http://your.domain.name/.static/piles/images/icon.png, etc.

BTW you can press Ctrl-Shift-I to see the browser console, select the Network tab and see, what URLs were success, and failed. You will find there the URL constructed from your reference by the browser.

See some learning matherials about relative URLs to understand details.

nnseva avatar Dec 15 '23 12:12 nnseva