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
<div class="container-fluid">
<div class="row">
<div class="col-xl-6">
<div class="card">
<div class="card-header card-no-border pb-0">
<h5>Map at a specified location with Marker</h5>
</div>
<div class="card-body map-z-index">
<google-map width="100%" height="500px" [zoom]="zoom">
@for( marker of markers ; track maker){
<map-marker [position]="marker.position" [label]="marker.label"></map-marker>
}
</google-map>
</div>
</div>
</div>
</div>
</div>
To use google map following type script files
import { Component, OnInit, ViewChild } from '@angular/core';
import { Component ,ViewChild} from '@angular/core';
import { GoogleMap, GoogleMapsModule } from '@angular/google-maps';
@Component({
selector: 'app-google-map',
templateUrl: './google-map.html',
styleUrls: ['./google-map.scss'],
imports: [GoogleMapsModule]
})
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"
}
});
}
//Street View
@ViewChild(GoogleMap) map!: GoogleMap;
ngAfterViewInit(){
const streetView = this.map.getStreetView();
streetView.setOptions({
position: { lat: 38.9938386, lng: -77.2515373 },
pov: { heading: 70, pitch: -10 },
});
streetView.setVisible(true);
const bounds = this.getBounds(this.markers);
}
getBounds(markers: any[]){
let north;
let south;
let east;
let west;
for (const marker of markers){
// set the coordinates to marker's lat and lng on the first run.
// if the coordinates exist, get max or min depends on the coordinates.
north = north !== undefined ? Math.max(north, marker.position.lat) : marker.position.lat;
south = south !== undefined ? Math.min(south, marker.position.lat) : marker.position.lat;
east = east !== undefined ? Math.max(east, marker.position.lng) : marker.position.lng;
west = west !== undefined ? Math.min(west, marker.position.lng) : marker.position.lng;
};
const bounds = { north, south, east, west };
return bounds;
}
}
Leaflet Maps Offical link Preview link
you have to install Leaflet map
npm i @bluehalo/ngx-leaflett
Simple Map
<div class="row">
<div class="col-xl-6">
<div class="card">
<div class="card-header card-no-border pb-0">
<h3>Simple Map</h3>
</div>
<div class="card-body">
<div style="height: 500px; z-index: 0;" leaflet
[leafletOptions]="options1"></div>
</div>
</div>
</div>
</div>
To use Leaflet Maps following type script files
import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import * as L from 'leaflet';
import { CommonModule } from '@angular/common';
import { LeafletModule } from '@bluehalo/ngx-leaflet';
@Component({
selector: 'app-leaflet-map',
templateUrl: './leaflet-map.html',
styleUrls: ['./leaflet-map.scss'],
imports: [CommonModule,LeafletModule],
})
export class LeafletMap {
constructor(private http: HttpClient) {}
// 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),
};
layersControl = {
baseLayers: {
'Open Street Map': L.tileLayer(
'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{ maxZoom: 18, attribution: '...' }
),
'Open Cycle Map': L.tileLayer(
'http://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png',
{ maxZoom: 18, attribution: '...' }
),
},
overlays: {
'Big Circle': L.circle([46.95, -122], { radius: 5000 }),
'Big Square': L.polygon([
[46.8, -121.55],
[46.9, -121.55],
[46.9, -121.7],
[46.8, -121.7],
]),
},
};
initMarkers() {
const popupInfo = `${this.popupText}`;
L.marker([this.homeCoords.lat, this.homeCoords.lon], this.markerIcon)
.addTo(this.map4)
.bindPopup(popupInfo);
}
onMapReady4(map: L.Map) {
this.map4 = map;
this.initMarkers();
}
}