Demonstrates how to add a custom popup to location markers on a Leaflet map using an Angular.io Component.. A blog post going over the steps can be found at -----
To run this project locally clone the repository then run.
npm install
ng serve
Created with StackBlitz ⚡️
Home Page: https://stackblitz.com/edit/angular-ivy-leafletjs-map-popup
Demonstrates how to add a custom popup to location markers on a Leaflet map using an Angular.io Component.. A blog post going over the steps can be found at -----
To run this project locally clone the repository then run.
npm install
ng serve
I am using your function to inject my PopupComponent into the Leaflet popup and the popup should display a table with the data for that specific layer. However, the popup does not adjust to the table size:
But when I do set the width for the leaflet-popup-content:
.tmo_popup .leaflet-popup-content {
margin: 0px !important;
width: 100% !important;
}
the popup does not appear right above the point and gets shifted to the right:
The way I am displaying the popup is the following (in my popup service):
let popupOptions = {
className: "popup",
maxWidth: 250 // This doesn't do anything for some reason
};
L.popup(popupOptions)
.setLatLng(latLng)
.setContent(this.compilePopup(PopupComponent))
.openOn(map);
You can see that I am using the this.compilePopup(PopupComponent)
function to inject the PopupComponent into the Leaflet popup and the this.compile function looks exactly the same as what you have in your file. This is how my PopupComponent HTML looks like:
<ng-template>
<table class="table table-striped table-bordered table-condensed table-hover">
<tr>
<th *ngFor="let col of columns;">
{{columns}}
</th>
</tr>
<tr>
<td *ngFor="let col of columns;">
{{columnDetails[columns]}}
</td>
</tr>
</table>
</ng-template>
popup-component.ts:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-popup',
templateUrl: './popup.component.html',
styleUrls: ['./popup.component.css']
})
export class PopupComponent implements OnInit {
columnDetails: any;
columns: Array<string> = ["Column 1", "Column 2", "Column 3"];
constructor(
private popupService: PopupService,
private popupStore: PopupStore
) {
this.columnDetails= this.popupService.columnDetails;
}
}
and the way I am initializing my Leaflet map is in my map-component.ts where I have:
options: MapOptions = {
center: latLng(47.5786262, -122.1654623),
minZoom: 4,
layers: [
L.gridLayer.googleMutant({
type: 'roadmap', // valid values are 'roadmap', 'satellite', 'terrain' and 'hybrid'
styles: [
{
featureType: "poi.business",
elementType: "labels",
stylers:
[
{
visibility: "simplified"
}
]
}
]
}),
],
zoom: 5,
zoomControl: false
};
map-component.html:
<div id="map"
leaflet [leafletOptions]="options"
(leafletMapReady)="onMapReady($event)"
(leafletMapMove)="onMapMove($event)"
(leafletMapZoom)="onMapZoom($event)"
(leafletClick)="onMapClick($event)">
</div>
Do you know how I can get it so the popup adjust to my table size AND that the popup is right above the marker that I click on? I'm pretty sure the UI is like this because I am injecting the PopupComponent into the Leaflet popup. Any ideas on how to resolve this issue? Any help is greatly appreciated!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.