mirror of
https://github.com/akveo/ngx-admin.git
synced 2025-12-16 15:40:11 +01:00
feat(maps): add google map with access search location dropdown
This commit is contained in:
parent
cb5795b52f
commit
97c7134c77
13 changed files with 151 additions and 3 deletions
10
package-lock.json
generated
10
package-lock.json
generated
|
|
@ -357,6 +357,12 @@
|
|||
"integrity": "sha512-lbWmXFxIpEzpH7OprsCRvxj7kie+248Y2ItjeVsF+0+IqvwG+R+0xgZmxq1ofYNTszvuihDahas7O5dscfxTsw==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/googlemaps": {
|
||||
"version": "3.30.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/googlemaps/-/googlemaps-3.30.4.tgz",
|
||||
"integrity": "sha512-S5Bzg+vlguaIhJa20V+QmetQqoAHAtpy+tAsv7ayps3Vsu0sU1QAEqHrV3KdBb7qy/tq9m4qDs1wQws0gm5Vpg==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/jasmine": {
|
||||
"version": "2.5.54",
|
||||
"resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-2.5.54.tgz",
|
||||
|
|
@ -6431,7 +6437,7 @@
|
|||
"opn": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/opn/-/opn-5.1.0.tgz",
|
||||
"integrity": "sha512-iPNl7SyM8L30Rm1sjGdLLheyHVw5YXVfi3SKWJzBI7efxRwHojfRFjwE/OLM6qp9xJYMgab8WicTU1cPoY+Hpg==",
|
||||
"integrity": "sha1-cs4jBqF9vqWP8QQYUzUrSo/HdRk=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"is-wsl": "1.1.0"
|
||||
|
|
@ -6440,7 +6446,7 @@
|
|||
"send": {
|
||||
"version": "0.16.1",
|
||||
"resolved": "https://registry.npmjs.org/send/-/send-0.16.1.tgz",
|
||||
"integrity": "sha512-ElCLJdJIKPk6ux/Hocwhk7NFHpI3pVm/IZOYWqUmoxcgeyM+MpxHHKhb8QmlJDX1pU6WrgaHBkVNm73Sv7uc2A==",
|
||||
"integrity": "sha1-pw4coh0TgsEdDZ9iMd6ygQgNerM=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"debug": "2.6.9",
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@
|
|||
"@angular/compiler-cli": "~5.1.0",
|
||||
"@angular/language-service": "~5.1.0",
|
||||
"@compodoc/compodoc": "1.0.1",
|
||||
"@types/googlemaps": "3.30.4",
|
||||
"@types/d3-color": "1.0.5",
|
||||
"@types/jasmine": "2.5.54",
|
||||
"@types/jasminewd2": "2.0.3",
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ import { MapsComponent } from './maps.component';
|
|||
import { GmapsComponent } from './gmaps/gmaps.component';
|
||||
import { LeafletComponent } from './leaflet/leaflet.component';
|
||||
import { BubbleMapComponent } from './bubble/bubble-map.component';
|
||||
import { SearchMapComponent } from './search-map/search-map.component';
|
||||
import { MapComponent } from './search-map/map/map.component';
|
||||
import { SearchComponent } from './search-map/search/search.component';
|
||||
|
||||
const routes: Routes = [{
|
||||
path: '',
|
||||
|
|
@ -18,6 +21,9 @@ const routes: Routes = [{
|
|||
}, {
|
||||
path: 'bubble',
|
||||
component: BubbleMapComponent,
|
||||
}, {
|
||||
path: 'searchmap',
|
||||
component: SearchMapComponent,
|
||||
}],
|
||||
}];
|
||||
|
||||
|
|
@ -32,4 +38,7 @@ export const routedComponents = [
|
|||
GmapsComponent,
|
||||
LeafletComponent,
|
||||
BubbleMapComponent,
|
||||
SearchMapComponent,
|
||||
MapComponent,
|
||||
SearchComponent,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -9,7 +9,10 @@ import { MapsRoutingModule, routedComponents } from './maps-routing.module';
|
|||
@NgModule({
|
||||
imports: [
|
||||
ThemeModule,
|
||||
AgmCoreModule.forRoot(),
|
||||
AgmCoreModule.forRoot({
|
||||
apiKey: 'AIzaSyCpVhQiwAllg1RAFaxMWSpQruuGARy0Y1k',
|
||||
libraries: ['places'],
|
||||
}),
|
||||
LeafletModule.forRoot(),
|
||||
MapsRoutingModule,
|
||||
NgxEchartsModule,
|
||||
|
|
|
|||
4
src/app/pages/maps/search-map/entity/Location.ts
Normal file
4
src/app/pages/maps/search-map/entity/Location.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
export class Location {
|
||||
constructor(public latitude: number = 54, public longitude: number = 33) {
|
||||
}
|
||||
}
|
||||
7
src/app/pages/maps/search-map/map/map.component.html
Normal file
7
src/app/pages/maps/search-map/map/map.component.html
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<agm-map [latitude]="latitude"
|
||||
[longitude]="longitude"
|
||||
[scrollwheel]="false"
|
||||
[zoom]="zoom">
|
||||
<agm-marker [latitude]="latitude"
|
||||
[longitude]="longitude"></agm-marker>
|
||||
</agm-map>
|
||||
13
src/app/pages/maps/search-map/map/map.component.scss
Normal file
13
src/app/pages/maps/search-map/map/map.component.scss
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
@import '../../../../@theme/styles/themes';
|
||||
|
||||
@include nb-install-component() {
|
||||
|
||||
nb-card-body {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/deep/ agm-map {
|
||||
width: 100%;
|
||||
height: nb-theme(card-height-large);
|
||||
}
|
||||
}
|
||||
31
src/app/pages/maps/search-map/map/map.component.ts
Normal file
31
src/app/pages/maps/search-map/map/map.component.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { Location } from '../entity/Location';
|
||||
|
||||
@Component({
|
||||
selector: 'ngx-map',
|
||||
templateUrl: './map.component.html',
|
||||
styleUrls: ['./map.component.scss'],
|
||||
})
|
||||
export class MapComponent implements OnInit {
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
zoom: number;
|
||||
|
||||
@Input()
|
||||
public set searchedLocation(searchedLocation: Location) {
|
||||
this.latitude = searchedLocation.latitude;
|
||||
this.longitude = searchedLocation.longitude;
|
||||
this.zoom = 12;
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
// set up current location
|
||||
if ('geolocation' in navigator) {
|
||||
navigator.geolocation.getCurrentPosition((position) => {
|
||||
this.searchedLocation = new Location(
|
||||
position.coords.latitude, position.coords.longitude,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
7
src/app/pages/maps/search-map/search-map.component.html
Normal file
7
src/app/pages/maps/search-map/search-map.component.html
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<nb-card>
|
||||
<nb-card-header>Google Maps with search</nb-card-header>
|
||||
<nb-card-body>
|
||||
<ngx-search (positionChanged)="updateLocation($event)"></ngx-search>
|
||||
<ngx-map [searchedLocation]="searchedLocation"></ngx-map>
|
||||
</nb-card-body>
|
||||
</nb-card>
|
||||
15
src/app/pages/maps/search-map/search-map.component.ts
Normal file
15
src/app/pages/maps/search-map/search-map.component.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { Component } from '@angular/core';
|
||||
import { Location } from './entity/Location';
|
||||
|
||||
@Component({
|
||||
selector: 'ngx-search-map',
|
||||
templateUrl: './search-map.component.html',
|
||||
})
|
||||
export class SearchMapComponent {
|
||||
|
||||
searchedLocation: Location = new Location();
|
||||
|
||||
updateLocation(event: Location) {
|
||||
this.searchedLocation = new Location(event.latitude, event.longitude);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<div class="form-group">
|
||||
<input placeholder="search for location" autocorrect="off" autocapitalize="off" spellcheck="off" type="text"
|
||||
class="form-control search-location" #search>
|
||||
</div>
|
||||
44
src/app/pages/maps/search-map/search/search.component.ts
Normal file
44
src/app/pages/maps/search-map/search/search.component.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import { Component, ElementRef, EventEmitter, NgZone, OnInit, Output, ViewChild } from '@angular/core';
|
||||
import { MapsAPILoader } from '@agm/core';
|
||||
import { Location } from '../entity/Location';
|
||||
import {} from 'googlemaps';
|
||||
|
||||
@Component({
|
||||
selector: 'ngx-search',
|
||||
templateUrl: './search.component.html',
|
||||
})
|
||||
export class SearchComponent implements OnInit {
|
||||
|
||||
@Output() positionChanged = new EventEmitter<Location>();
|
||||
|
||||
@ViewChild('search')
|
||||
public searchElementRef: ElementRef;
|
||||
|
||||
constructor(private mapsAPILoader: MapsAPILoader,
|
||||
private ngZone: NgZone) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
// load Places Autocomplete
|
||||
this.mapsAPILoader.load().then(() => {
|
||||
const autocomplete = new google.maps.places.Autocomplete(this.searchElementRef.nativeElement, {
|
||||
types: ['address'],
|
||||
});
|
||||
autocomplete.addListener('place_changed', () => {
|
||||
this.ngZone.run(() => {
|
||||
// get the place result
|
||||
const place: google.maps.places.PlaceResult = autocomplete.getPlace();
|
||||
|
||||
// verify result
|
||||
if (place.geometry === undefined || place.geometry === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.positionChanged.emit(
|
||||
new Location(place.geometry.location.lat(),
|
||||
place.geometry.location.lng()));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -89,6 +89,10 @@ export const MENU_ITEMS: NbMenuItem[] = [
|
|||
title: 'Bubble Maps',
|
||||
link: '/pages/maps/bubble',
|
||||
},
|
||||
{
|
||||
title: 'Search Maps',
|
||||
link: '/pages/maps/searchmap',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue