Maps
Google Maps Offical link Preview link
you have to install google map
npm i @angular/google-maps
Map At A Specified Location With Marker
<!-- htlm file-->
<google-map width="100%" height="500px" [zoom]="zoom">
@for (marker of markers; track marker) {
<map-marker [position]="marker.position" [label]="marker.label"></map-marker>
}
</google-map>
<!--ts files-->
import { Component, ViewChild } from '@angular/core';
import { GoogleMap, GoogleMapsModule } from '@angular/google-maps';
@Component({
selector: 'app-google-map',
imports: [GoogleMapsModule],
templateUrl: './google-map.html',
styleUrls: ['./google-map.scss']
})
export class GoogleMap {
public openInfo: any;
public markers: any[];
public zoom: number;
constructor() {
this.markers = [];
this.zoom = 2;
}
ngOnInit() {
this.markers.push({
position: {
lat: 35.717,
lng: 139.731
},
label: {
color: "black",
text: "Madrid"
},
Option: {
draggable: true,
animation: google.maps.Animation.DROP,
}
});
this.markers.push({
position: {
lat: 48.8615515,
lng: 2.3112233
},
label: {
color: "black",
text: "Paris"
},
Option: {
draggable: true,
animation: google.maps.Animation.DROP,
}
});
}
//Street View
@ViewChild(GoogleMap) map!: GoogleMap;
ngAfterViewInit() {
let streetView = this.map.getStreetView();
streetView.setOptions({
position: {
lat: 48.8615515,
lng: 2.3112233
},
pov: { heading: 70, pitch: -10 },
});
streetView.setVisible(true);
}
}
Leaflet Maps Offical link Preview link
you have to install Leaflet map
<!-- html file -->
<div style="height: 500px; z-index: 0;" leaflet [leafletOptions]="options1"></div>
<!--ts file-->
import { Component } from '@angular/core';
import { LeafletModule } from '@bluehalo/ngx-leaflet';
import * as L from 'leaflet';
@Component({
selector: 'app-leaflet-map',
imports: [LeafletModule,CommonModule]
templateUrl: './leaflet-map.html',
styleUrls: ['./leaflet-map.scss']
})
export class LeafletMap {
// First map options
options1 = {
layers: [
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '...',
}),
],
zoom: 5,
center: L.latLng(46.879966, -121.726909),
};
}
To use vector map you have to add the following css
@import 'leaflet/dist/leaflet.css';