-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
322 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{ | ||
"Search for an address or a place": "Search for an address or a place" | ||
"Location": "Location", | ||
"Search for an address or a place": "Search for an address or a place", | ||
"Submit": "Submit" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{ | ||
"Search for an address or a place": "Rechercher une adresse, un lieu ou une couche" | ||
"Location": "Localisation", | ||
"Search for an address or a place": "Rechercher une adresse, un lieu ou une couche", | ||
"Submit": "Soumettre" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './map-field'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './map-field.component'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div> | ||
<md-input-container> | ||
<input | ||
mdInput | ||
[placeholder]="placeholder" | ||
[readonly]="readonly" | ||
[ngModel]="value" | ||
(ngModelChange)="handleValueChange($event)"> | ||
</md-input-container> | ||
<igo-map-browser [map]="map" [view]="view"></igo-map-browser> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { IgoSharedModule } from '../../../shared'; | ||
import { MapBrowserComponent } from '../../../map'; | ||
|
||
import { MapFieldComponent } from './map-field.component'; | ||
|
||
describe('MapFieldComponent', () => { | ||
let component: MapFieldComponent; | ||
let fixture: ComponentFixture<MapFieldComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
IgoSharedModule, | ||
], | ||
declarations: [ | ||
MapBrowserComponent, | ||
MapFieldComponent | ||
] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(MapFieldComponent); | ||
component = fixture.componentInstance; | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@require '../../../../style/var.styl'; | ||
|
||
:host { | ||
position: relative; | ||
display: block; | ||
} | ||
|
||
:host, .igo-map-browser-target { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
input { | ||
width: 100% | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import { Component, Input, forwardRef, | ||
AfterViewInit, OnDestroy } from '@angular/core'; | ||
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; | ||
|
||
import { IgoMap, MapViewOptions } from '../../../map'; | ||
import { Layer } from '../../../layer'; | ||
|
||
|
||
@Component({ | ||
selector: 'igo-map-field', | ||
templateUrl: './map-field.component.html', | ||
styleUrls: ['./map-field.component.styl'], | ||
providers: [ | ||
{ | ||
provide: NG_VALUE_ACCESSOR, | ||
useExisting: forwardRef(() => MapFieldComponent), | ||
multi: true | ||
} | ||
] | ||
}) | ||
export class MapFieldComponent | ||
implements AfterViewInit, OnDestroy, ControlValueAccessor { | ||
|
||
@Input() | ||
get placeholder() { return this._placeholder; } | ||
set placeholder(value: string) { | ||
this._placeholder = value; | ||
} | ||
private _placeholder: string; | ||
|
||
@Input() | ||
get decimals(): number { return this._decimals; } | ||
set decimals(value: number) { | ||
this._decimals = value; | ||
} | ||
private _decimals: number = 6; | ||
|
||
@Input() | ||
get readonly(): boolean { return this._readonly; } | ||
set readonly(value: boolean) { | ||
this._readonly = value; | ||
} | ||
protected _readonly: boolean = false; | ||
|
||
@Input() | ||
get value(): [number, number] { return this._value; } | ||
set value(value: [number, number]) { | ||
this.map.clearOverlay(); | ||
|
||
if (value === undefined) { | ||
this._value = value; | ||
this.onChange(this._value); | ||
return; | ||
} | ||
|
||
if (!isNaN(+value[0]) && !isNaN(+value[1])) { | ||
const values = [+value[0], +value[1]] as [number, number]; | ||
|
||
this.addOverlay(values); | ||
|
||
this._value = [ | ||
+values[0].toFixed(this.decimals), | ||
+values[1].toFixed(this.decimals) | ||
]; | ||
|
||
this.onChange(this._value); | ||
this.onTouched(); | ||
} | ||
} | ||
private _value: [number, number]; | ||
|
||
@Input() | ||
get view(): MapViewOptions { return this._view; } | ||
set view(value: MapViewOptions) { | ||
this._view = value; | ||
if (this.map !== undefined) { | ||
this.map.setView(value); | ||
} | ||
} | ||
protected _view: MapViewOptions; | ||
|
||
@Input() | ||
get layers(): Layer[] { return this._layers; } | ||
set layers(value: Layer[]) { | ||
this._layers = value; | ||
this.map.removeLayers(); | ||
this.map.addLayers(value); | ||
} | ||
private _layers: Layer[]; | ||
|
||
public map = new IgoMap(); | ||
public projection = 'EPSG:4326'; | ||
|
||
onChange: any = () => {}; | ||
onTouched: any = () => {}; | ||
|
||
constructor() {} | ||
|
||
ngAfterViewInit() { | ||
this.map.olMap.on('singleclick', this.handleMapClick, this); | ||
} | ||
|
||
ngOnDestroy() { | ||
this.map.olMap.un('singleclick', this.handleMapClick, this); | ||
} | ||
|
||
registerOnChange(fn: Function) { | ||
this.onChange = fn; | ||
} | ||
|
||
registerOnTouched(fn: Function) { | ||
this.onTouched = fn; | ||
} | ||
|
||
writeValue(value: [number, number]) { | ||
if (value) { | ||
this.value = value; | ||
} | ||
} | ||
|
||
handleValueChange(value: string) { | ||
this.value = this.parseValue(value); | ||
} | ||
|
||
private handleMapClick(event: ol.MapBrowserEvent) { | ||
this.value = ol.proj.transform( | ||
event.coordinate, this.map.projection, this.projection); | ||
} | ||
|
||
private parseValue(value: string): [number, number] | undefined { | ||
if (value === undefined || value === '') { | ||
return undefined; | ||
} | ||
|
||
const values = value.split(',').filter(v => v !== ''); | ||
if (values.length === 2) { | ||
return [+values[0], +values[1]]; | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
private addOverlay(coordinates: [number, number]) { | ||
const geometry = new ol.geom.Point( | ||
ol.proj.transform(coordinates, this.projection, this.map.projection)); | ||
const extent = geometry.getExtent(); | ||
const feature = new ol.Feature({geometry: geometry}); | ||
|
||
this.map.moveToExtent(extent); | ||
this.map.addOverlay(feature); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './module'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { NgModule, ModuleWithProviders } from '@angular/core'; | ||
|
||
import { IgoSharedModule } from '../shared'; | ||
import { IgoMapModule } from '../map'; | ||
|
||
import { MapFieldComponent } from './fields/map-field'; | ||
|
||
|
||
@NgModule({ | ||
imports: [ | ||
IgoSharedModule, | ||
IgoMapModule | ||
], | ||
exports: [ | ||
MapFieldComponent | ||
], | ||
declarations: [ | ||
MapFieldComponent | ||
] | ||
}) | ||
export class IgoFormModule { | ||
static forRoot(): ModuleWithProviders { | ||
return { | ||
ngModule: IgoFormModule, | ||
providers: [] | ||
}; | ||
} | ||
} | ||
|
||
export * from './fields'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.