-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Ability to show map icons for geolocation sources #23247
Ability to show map icons for geolocation sources #23247
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be part of label_mode
and label_mode
should just override the entity picture
Unified the option with label_mode to make it constant, I think everything works but I didn't add entity-registry based icon support for non-geolocation entities at this time as I'm not sure if it's really a useful usecase, I think it's more practical for autogenerated entities than the standard ones. |
I think this should support the entity registry. Users expect consistency and can assign icons to entities like cars or people that are displayed on maps. Documentation would also be more complicated if this isn't supported |
@@ -26,7 +29,9 @@ class HaEntityMarker extends LitElement { | |||
"background-image": `url(${this.entityPicture})`, | |||
})} | |||
></div>` | |||
: this.entityName} | |||
: this.entityIcon | |||
? html`<ha-icon .icon=${this.entityIcon}></ha-icon>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cant we just use ha-state-icon
? That will handle it all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kinda tried this once but didn't get it to work.
ha-state-icon
needs hass
, and I think the way the marker is constructed in ha-map and the html template is passed to map.addLayer()
makes that not work for some reason (currently everything to ha-entity-marker is passed as an attribute instead of a property?), when I tried to add a hass property to the marker it always ended up being undefined when that item rendered.
Probably need some advanced JS I don't understand to make that work correctly?
If you think that should work without anything special I can try again and see if I missed something obvious...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should kinda work, it will not update hass
when it changes though (except if the icon is recreated when hass
changes ofc), but that could also be added if needed:
const entityMarker = document.createElement("ha-entity-marker");
entityMarker.hass = this.hass;
entityMarker.entityId = getEntityId(entity);
entityMarker.entityName = entityName;
entityMarker.entityPicture = entityPicture
? this.hass.hassUrl(entityPicture)
: "";
if (typeof entity !== "string") {
entityMarker.entityColor = entity.color;
}
// create marker with the icon
const marker = Leaflet.marker([latitude, longitude], {
icon: Leaflet.divIcon({
html: entityMarker,
iconSize: [48, 48],
className: "",
}),
title: title,
});
Another option would be to extend Leaflet.divIcon
with lit-html
support, so we can write lit-html
templates in the html
option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this suggestion seems to work well.
Now have working icons for all entities 👍 (even updates correctly when the state changes)
Proposed change
Add a mode to show geolocation entities on the map as icons instead of their current name. The current behavior seems to just produce an unintelligible letter-salad, so I think seeing the icons would be quite a bit cleaner. Perhaps it should even be made the default mode, but for now it's just backward-compatible optional mode. Most geolocation sources I've seen tend to include a nice icon as part of the entity (typically for natural disasters).
Current:

Proposed:

Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: