Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ng-leaflet-universal

Package Overview
Dependencies
Maintainers
3
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng-leaflet-universal

NgLeafletUniversal is an open source Angular module that extends and simplifies the Leaflet implementation for Angular.

  • 15.2.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
32
Maintainers
3
Weekly downloads
 
Created
Source

NgLeafletUniversal

NgLeafletUniversal is an open source Angular module that extends and simplifies the Leaflet implementation for Angular.

Server side rendering (SSR) support

One of the principals problems when you are using Leaflet's maps in your Angular application is the configuration for SSR. This library contains all the required configuration for been integrated with your Angular Universal application.

Installation

You can install this library via npm using the next command on your project

npm i ng-leaflet-universal

Implementation

After installing, import the module in your application:

import { NgLeafletUniversalModule } from "ng-leaflet-universal";
imports: [
	...
	NgLeafletUniversalModule
],

Add the leaflet css to your angular.json:

"styles": [
	"./node_modules/leaflet/dist/leaflet.css",
	"src/styles.css"
],

Basic template implementation:

<div class="map-wrapper">
  <ng-leaflet-universal></ng-leaflet-universal>
</div>

It's up to you adding this styles.

.map-wrapper {
  position: relative;
  width: 300px;
  height: 300px;
}

Add marker to your map using the updateMarkers function in your own component

import { AfterViewInit, Component, ViewChild } from  '@angular/core';
import { MapComponent } from 'ng-leaflet-universal';
import { Marker } from 'ng-leaflet-universal/lib/models/marker.interface';

@Component({
	selector:  'app-custom-component',
	templateUrl:  './custom-component.component.html',
	styleUrls: ['./custom-component.component.scss'],
})
export  class  CustomComponentComponent  implements AfterViewInit {
@ViewChild(MapComponent) mapComponent: MapComponent;
markers: Marker[];

constructor() {
	this.markers = [];
}

ngAfterViewInit(): void {
	this.mapComponent.updateMarkers(this.markers);
}

Once you set or update your marker list using the updateMarkers function, the map will set the view on the center of your markers collection automatically.

Elements / components

Markers

We provide you an marker component that you can use for setting your locations easily, setting the location point (Latitude and Longitude) and the icon you would like to show into it.

Marker example

Model:

KeyTypeDefinition
iconstringUrl of icon or image you want to show in your marker.
locationLocation: { latitude: string, longitude: string }The specific location where your marker will be showed.
cardMarkerCardThe card that will be open when a user click on your marker.

Example:

myMarker: Marker = {
  id: "abc123",
  icon: "https://picsum.photos/200/200",
  location: {
    latitude: -81.1288,
    longitude: -81.4579,
  },
  card: myMarkerCard,
};

Marker Cards

This library contains a card component that you can customize and adapt to your own needs. These cards will be open when you click in your markers. Every single element in this cards includes several parameters that allows you customize that element's style, and a class param that you can use for setting your own css class.

Marker card example

Model:

KeyTypeDefinition
imageCardImageSpecify the main image of the card
titleCardTextShow a title into the card
subtitleCardTextShow a subtitle into the card
addressCardTextShow the address of the lacation
contentCardTextAn html that will be rendered into the card
cardStyleCardStyleAn object that define (By params) the way your card will look
callToActionsCardCallToAction[]A collection that indicate the buttons will be shown in the card
customStyleClassstringA css class that allows you to set your own style rules for your cards
customHtmlstringA custom html string that you can use to replace the default card structure and define everything you want in the card

Example:

    card: {
	    image: { url:  'https://picsum.photos/200/200' },
	    title: { text:  'The place', customStyleClass:  'awesome-title' },
	    subtitle: { text:  'The best place' },
	    content: { text: '<p> This is the content that will be used in the <b> card </b> </p>' },
	    address: { text:  'Neverland, NM 88203' },
	    callToActions: [
		    {
			    text:  'View details',
			    link:  'https://myawesomeapp.domain/Location-1',
			    customStyleClass:  'my-details-button'
		    },
		    {
			    text:  'Directions',
			    backgroundColor:  '#007319',
			    textColor:  '#fff',
			    link:  `https://www.google.com/maps/@-81.1288,-81.4579,18.13z`,
			    icon: 'fas fa-directions'
		    }
	    ],
	    customStyleClass: 'custom-card-style'
    }

Contribuitors

  • Christian De La Cruz
  • Rafael A. Reyes
  • Niurmiguel Gonzalez

Keywords

FAQs

Package last updated on 28 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc