New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

errisy-map

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

errisy-map

Angular 2 simple wrap of Google Map API

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

Errisy-Map

Angular 2 simple wrap of Google Map API

Why Simple Wrap?

There are some complex wrap that allows you to place markers in Google Map in a way similar to place elements in a parent element. However, those are too heavy as a wrap for Google Map API.

To make the API as light as possible, here I provide a simple solution that allows you to load Google Map API.

How to use?

In your @NgModule

@NgModule({
    imports: [ ErrisyMapModule.forRoot({ key: 'Your Google Map API Key' }), ...YourModules],
    declarations: [ ...YourComponents],
    entryComponents: [],
    providers: [],
    bootstrap: [AppComponent]
})
export class AppModule { }

In your component html, where you want to use Google Map. The selector is [google-map].

MapInit is the most important part, which is the callback when Google Map is loaded. You can then do additional setups such as load customized Google Map Markers.


<div google-map [Lng]="location.x" [Lat]="location.y" [Zoom]="12" (MapInit)="onMapReady($event);" class="app-map">
</div>

How to Customized (extends) Markers or Other Google Map classes?

Since Google Map API is loaded asynchronously, you can not extend their classes until you have loaded the API.

To extends the API classes, you must import the API after Google Map is loaded.

With SystemJS in Angular 2, there is a simple solution:

//Define your own marker by extending Google Map Marker in file 'customized.marker.ts'

export class MyCustomizedMarker extends google.maps.Marker{

}

Then you can load it via SystemJS.import in the MapInit callback.

import * as CustomizedMarkers from 'customized.marker'; // this will just import the definition, it will disappear in the compiled the .js file.


@Component({
    selector: 'app',
    template: `
    <div google-map [Lng]="location.x" [Lat]="location.y" [Zoom]="12" (MapInit)="onMapReady($event);" class="app-map">
    </div>
    `
})
export class MyApp{
    this.CustomizedMarkersModule: typeof CustomizedMarkers; 
    onMapReady($event: google.maps.Map){
        this.CustomizedMarkersModule = await SystemJS.import('...foldername/markers.js'); //load the customized marker module
        let myMarker = new CustomizedMarkersModule.MyCustomizedMarker(); //create your customized marker
    }
}

Keywords

Google Map API Wrapper

FAQs

Package last updated on 04 Mar 2017

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