Nondeterministic Programming Methodology
    Have ideas to improve npm?Join in the discussion! »

    @mapify/angular
    TypeScript icon, indicating that this package has built-in type declarations

    0.2.9 • Public • Published

    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.

    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 --save

    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 = new ClientConfig(
             environment.mapifyApiKey
          );
          this.mapifyClient = MapifyClient.createClient(clientConfig);
       }
    
       public async ngOnInit(): Promise<void> {
          // Get some maps from Mapify
          const maps = await this.mapifyClient.maps.list({});
          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({ mapId: 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();

    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, set their visibility in the Map object returned by the MapifyClient before setting it to this.map or send a callback function to the map component.

    You can use the initialization event to know when the map is ready, for this your will need to provide a handler to the mapReady event emitter. You can do this by creating a method you want to trigger in your component, then running it when there is a mapReady event:

    <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() {}
       ...
    }

    Keywords

    none

    Install

    npm i @mapify/angular

    DownloadsWeekly Downloads

    53

    Version

    0.2.9

    License

    MIT

    Unpacked Size

    1.09 MB

    Total Files

    59

    Last publish

    Collaborators

    • avatar
    • avatar
    • avatar
    • avatar