-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddress.js
152 lines (123 loc) · 3.98 KB
/
address.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import http from './http.js';
import {filter, map, some, find, isObject} from 'lodash';
class Address {
constructor () {
this.address = false;
}
/**
* Поиск адреса по заданамо шаблону
* @param {string} text - шаблон для поиска
* @return {Address array} массив объектв типа Address
* https://github.com/HIVETAXI/client-web-api/wiki/Поиск-адреса
* */
static getAddress (text) {
return http.send('/api/client/web/1.0/address/address?pattern=' + encodeURIComponent(text));
}
/**
* Поиск точки по заданамо шаблону
* @param {string} pattern - шаблон для поиска
* @param {string} parent - родительский объект, например город.
* @return {Point array} массив объектв типа Point
* https://github.com/HIVETAXI/client-web-api/wiki/Поиск-адресной-точки
* */
static getPoints(parent, pattern) {
return http.send('/api/client/web/1.0/address/point?pattern=' + encodeURIComponent(pattern) + '&parent=' + parent);
}
/**
* Установить адресный объект (либо адрес, либо поинт)
* @param {object} addressObj - адресный объект
* @return false
* */
setAddress (addressObj) {
if (Address.isPoint(addressObj)) {
this.address.point = addressObj
} else {
this.address = addressObj;
}
}
/**
* Очисить адрес
* */
clear () {
this.address = false;
}
/**
* Проверить имеет ли адрес alias
* @param {Address object} address - адресc
* */
static hasAlias(address) {
return Boolean(address.point && address.point.info && address.point.info.alias)
}
thisHasAlias(){
return Address.hasAlias(this.address)
}
static getAlias (address) {
if (Address.hasAlias(address)) {
return address.point.info.alias;
}
}
static hasPoint (address) {
return Boolean(address && address.point && address.point.coordinates)
}
static getPoint(address) {
if (Address.hasPoint(address)){
return address.point;
}
}
hasLevels() {
if (this.address.levels && this.address.levels.length) {
return true
}
return false
}
static isPoint (point) {
if(point && point.coordinates) {
return true
}
}
static hasStreet (address) {
if (some(address.levels, ['type', 7])) {
return true;
}
}
static hasLocality (address) {
return some(address.levels, ['type', 6])
}
static getLocality (address) {
return find(address.levels, ['type', 6]);
}
static getLocalityName (address) {
if(Address.hasLocality(address)) {
return Address.getLocality(address).prefix + ' ' + Address.getLocality(address).name;
}
}
static getStreet (address) {
var streetLevel = find(address.levels, ['type', 7]);
return streetLevel;
}
static getStreetName (address) {
if(Address.hasStreet(address)) {
return Address.getStreet(address).prefix + ' ' + Address.getStreet(address).name;
}
}
static getHouseName (point) {
var house = '';
if (point && point.info) {
var info = point.info;
if (info.house) {
house = house + info.house;
}
if (info.housing) {
house = house + ' кор. ' + info.housing;
}
if (info.building) {
house = house + ' cт. ' + info.building;
}
if (info.lit) {
house = house + ' лит. ' + info.lit;
}
}
return house;
}
}
export default Address;