Apologies in advance, I am far from a developer; however, I modified the js in two places to allow for what @PeterHant77 wanted (since I wanted it too).
Added the below around line 150
this._setConfigWithDefault(inputConfig, "focus_entity", "none");
setConfig(inputConfig) {
this.config = {};
this._setConfigWithDefault(inputConfig, "x");
this._setConfigWithDefault(inputConfig, "y");
this._setConfigWithDefault(inputConfig, "focus_entity", "none");
this._setConfigWithDefault(inputConfig, "zoom", 12);
this.config["title"] = inputConfig["title"];
this._setConfigWithDefault(inputConfig, "card_size", 5);
this._setConfigWithDefault(inputConfig, "entities", []);
//this._setConfigWithDefault(inputConfig, "css_id", "map-card-" + (new Date()).getTime());
this._setConfigWithDefault(inputConfig, "wms", []);
this._setConfigWithDefault(inputConfig, "tile_layer_url", "https://tile.openstreetmap.org/{z}/{x}/{y}.png");
this._setConfigWithDefault(inputConfig, "tile_layer_attribution", '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>');
}
Then added an if statement when setting the latitude/longitude for the first map render at around line 192
/** @returns {[Double, Double]} */
_getLatLong() {
if (this.config.focus_entity === 'none') {
return [this.config.x, this.config.y];
} else {
// Assuming this.hass.states contains the states of all entities
const entity = this.hass.states[this.config.focus_entity];
if (entity) {
return [entity.attributes.latitude, entity.attributes.longitude];
} else {
throw new Error(`Entity ${this.config.focus_entity} not found`);
}
}
}
I’m saying I’m not a developer because I have no intention of forking this and maintaining anything. It was really a challenge to see if I could do it. I would love to have any feedback.
In the card yaml, if you want to have a focus entity just add a line:
focus_entity: device_tracker.entity_id
Replace entity_id with your device (e.g. device_tracker.peter_s_phone). If you leave the x and y values in your yaml, they will be ignored.
Note, it does seem to take a couple of seconds (literally a one, two count) longer to render the map.