npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mapify/angular

v0.7.1

Published

Mapify angular components library

Downloads

136

Readme

README

Summary

  • Mapify Angular - an angular library with components for the Mapify platform

The @mapify/angular project contains the Mapify angular components which can be used to ease the visualisation of Mapify maps and data.

Further Documentation and Blog Posts

You can checkout the following blog post for an example on setting up an Angular App.

For further information and blog posts you can go here.

General Setup

You will need to have nodejs and npm installed.

You will need a Mapify account in order to get an API Key to use when configuring the SDK and other components.

  • Get your desired API Key from the Mapify console.

Mapify Angular Lib

Angular Lib Setup

Install @mapify/angular from npm:

  • npm i @mapify/angular @angular/cdk@13 @angular/material@13 --save

then add to polyfills.ts:

  • import 'reflect-metadata';

The Angular library requires:

  • A Mapify API Key in order to access the Mapify platform. Get your API Key from the Mapify console.
  • A Google Maps API Key in order to use the Google Maps services.

Angular Lib Configuration

In order to use the Angular components provided by this library, you will need to configure the module when importing it in your app's module.

In your app's module import MapifyAngularModule with the configuration required:

import { MapifyAngularModule } from '@mapify/angular'
import { MapConfig } from '@mapify/core';

@NgModule({
   imports: [
      MapifyAngularModule.forRoot(new MapConfig(
         // Your API keys
         environment.mapifyApiKey,
         environment.googleMapsApiKey
      ))
   ]
   ...
})
export class YourAppModule { }

From this point onward, you will be able to use components provided in the library.

Using the Map Component from the Mapify Angular Lib

In you component's html add the mapify-map component:

<mapify-map [map]="map" #mapifymap> </mapify-map>

In your component initialize and use the MapifyClient in order to get your maps:

import { MapifyClient, Map } from '@mapify/core';

@Component({
	selector: 'app-root',
	templateUrl: './app.component.html',
	styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
	@ViewChild('mapifymap') mapifyMap: MapifyMapComponent;
	public map: Map;

	constructor() {
		const clientConfig: ClientConfig = {
			// Your API key
			apiKey: environment.mapifyApiKey,
		};
		this.mapifyClient = MapifyClient.createClient(clientConfig);
	}

	public async ngOnInit(): Promise<void> {
		// Get some maps from Mapify
		const maps = await this.mapifyClient.maps.getAllPaginated();
		if (maps?.items?.length <= 0) {
			return;
		}
		const desiredMap = maps.items[0];
		// Request the map specifically to get the full data needed to display the map
		this.map = await this.mapifyClient.maps.get(desiredMap.mapId);
	}
}

By updating the contents of this.map the Mapify map component will detect changes and react to them. By using the ViewChild mapifyMap we can gain access to further methods that help us manipulate the map we have provided.

For example in order to show the map use:

this.mapifyMap.showMap();

Or to hide the map:

this.mapifyMap.hideMap();

Or to query the map's visibility:

this.mapifyMap.isMapVisible();

In order to center the map use:

this.mapifyMap.centerMap();

NOTE: In order to be able to manipulate the map, you will need to wait for the map to be set in the component. For example, you will not be able to toggle the map in the same ngOnInit method in which you changed the content of this.map. This is because at that point no changes have been detected yet, thus only in the following cycles will the component render the map data provided.

In order to start the map with layers visible/centered there are two approaches you can choose from:

onMapReady

The first approach is to send a handler to the mapReady event emitter, that toggles the map visibility and centers the map once the map is ready.

Example usage:

export class AppComponent implements OnInit {
   ...

   // Define the method in your component
   public onMapReady() {
      this.mapifyMap.showMap();
      this.mapifyMap.centerMap();
   }
}
<mapify-map [map]="map" (mapReady)="onMapReady()" #mapifymap> </mapify-map>

Further Map Configuration

The mapify-map component can be further configured. Optional inputs include:

  • googleMapsMapOptions
  • height
  • width

The googleMapsMapOptions gives control of the base map and its properties. For more information on this interface check Google's documentation here.

The height property allows the height of the map container to be defined. By default it is set to '100%'. This string should reflect a CSS string's format to apply to the map's container's height style.

The width property allows the width of the map container to be defined. By default it is set to '100%'. This string should reflect a CSS string's format to apply to the map's container's width style.

Example

In you component's html add the mapify-map component:

<mapify-map
	#mapifymap
	[map]="map"
	[googleMapsMapOptions]="googleMapsMapOptions"
	height="height"
	width="width"
	(mapReady)="onMapReady()"
>
</mapify-map>

In your component initialize and use the configurations:

...
export class AppComponent implements OnInit {

   @ViewChild('mapifymap') mapifyMap: MapifyMapComponent;
   public map: Map;
   public height: '500px';
   public width: '500px';
   public googleMapsMapOptions: google.maps.MapOptions = {
      backgroundColor: '#2B2B2B',
      zoomControl: false,
      scrollwheel: true,
      disableDoubleClickZoom: true,
      fullscreenControl: false,
      mapTypeControl: false,
      streetViewControl: false,
      maxZoom: 20,
      minZoom: 1,
      zoom: 3,
   }

   constructor() {}
   ...
}