Learn About Angular AGM Map Places Visibility

Introduction

 
The AGM map hides Google places and labels using custom styles in Angular. Please follow the below steps.
 
Step 1
 
First, we have to install the following npm commands in our project.
 
npm install @agm/core –save
 
The above command adds external dependencies.
 
Step 2
 
import AgmCoreModule to your AppModule.
 
Angular AGM Map Places Visibility 
  1. import { NgModule, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA,ErrorHandler } from '@angular/core';  
  2. import { BrowserModule } from '@angular/platform-browser';  
  3. import { FormsModule } from '@angular/forms';  
  4. import { AppComponent } from './app.component';  
  5. import {APP_BASE_HREF} from '@angular/common';  
  6. import { AgmCoreModule } from '@agm/core';    
Add app.module.ts page with the below code to import the references for Agm Maps.
  1. @NgModule({  
  2.     schemas: [NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA],  
  3.     imports: [BrowserModule, FormsModule,  
  4.         AgmCoreModule.forRoot({  
  5.             apiKey: 'YOUR-API-KEY'  
  6.         })  
  7.     ],  
  8.     declarations: [AppComponent],  
  9.     providers: [],  
  10.     bootstrap: [AppComponent]  
  11. })  
  12. export class AppModule {}  
Step 3
 
The app.component.ts sets latitude,longitude value and marker values as marlatitude,marongitude.
  1. import {  
  2.     Component  
  3. } from '@angular/core';  
  4. @Component({  
  5.     selector: 'my-app',  
  6.     templateUrl: './app.component.html',  
  7.     styleUrls: ['./app.component.css']  
  8. })  
  9. export class AppComponent {  
  10.     public latitude: number = 13.0628;  
  11.     public longitude: number = 80.2517;  
  12.     public marlatitude: number = 13.0628;  
  13.     public marongitude: number = 80.2517;  
  14.     constructor() {}  
  15. }  
Step 4
 
In app.component.html, add the agm-map & agm-marker tag and set the height and width for map using the following code:
  1. <style>  
  2.    agm-map {  
  3.       height: 600px;  
  4.       width: 1200px;  
  5. }  
  6. </style>  
  7.    <agm-map [latitude]="latitude" [longitude]="longitude" [zoom]="15" >  
  8.    <agm-marker [latitude]="marlatitude" [longitude]="marongitude" ></agm-marker>  
  9. </agm-map>  
Step 5
 
I'm not sure if you can show only specific types of places, however, you can hide all places of interest by hiding them in your map options.
 
Please refer to the below link to a "hide places" list.
 
https://developers.google.com/maps/documentation/javascript/style-reference.
 
Step 6
 
Here I have hidden the hospital list. ‘poi‘ selects all points of interest.
 
poi.medical selects emergency services including hospitals, pharmacies, police, doctors, and others.
 
Angular AGM Map Places Visibility
 
Angular AGM Map Places Visibility
 
Step 7 - Feature Type
 
Feature type is optional. This style allows modification of agm maps with the below characteristics on the map list.
  • Roads
  • Parks
  • Bodiesof water,
  • Others
If you don’t need any specific style features, all features are selected and shown/hidden from the AGM map.
 
elementType - Element type is also optional. The property is used to select labels and geometry in the AGM map list.
 
stylers - Visibility (on, off, or simplified) indicates whether and how the element appears on the map.
 
A simplified visibility removes some style features from the modified visibility features.
  1. import {  
  2.     Component  
  3. } from '@angular/core';  
  4. @Component({  
  5.     selector: 'my-app',  
  6.     templateUrl: './app.component.html',  
  7.     styleUrls: ['./app.component.css']  
  8. })  
  9. export class AppComponent {  
  10.     public latitude: number = 13.0628;  
  11.     public longitude: number = 80.2517;  
  12.     public marlatitude: number = 13.0628;  
  13.     public marongitude: number = 80.2517;  
  14.     constructor() {}  
  15.     public customStyle = [{  
  16.         "featureType""poi.medical",  
  17.         "elementType""all",  
  18.         "stylers": [{  
  19.             visibility: "off",  
  20.         }]  
  21.     }, ];  
Step 8
 
The agm initial shows all areas like hospital, temple, petrol bunk, apartment, hotels etc. Now I'm going to restrict specific features like medical section using the following code.
  1. <style>  
  2. agm-map {  
  3.    height: 600px;  
  4.    width: 1200px;  
  5. }  
  6. </style>  
  7.    <agm-map [latitude]="latitude" [longitude]="longitude" [zoom]="15" [styles]="customStyle">  
  8.    <agm-marker [latitude]="marlatitude" [longitude]="marongitude" ></agm-marker>  
  9. </agm-map>  
Angular AGM Map Places Visibility
 
The above image displays all hospital places. After adding custom style I an restricting poi.medical section styler’s visibility of all the poi elements. After executing the styles, all hospitals are now hidden as in the screenshot below.
 
Angular AGM Map Places Visibility
 
Hope this article was helpful. Thank you.