let ol = require('openlayers');
let GeocodingItem = require('./geocodingItem');
let GeocodingDictionary = require('./../../constants/geocoding');
let SearchResult = require('./../../tasks/searchResult');
class GoogleGeocodingItem extends GeocodingItem {
constructor(params) {
super(params);
// координаты точки
let position = [params.geometry.location.lng,params.geometry.location.lat];
this.position = position;
// координаты описывающего прямоугольника
let southwest=params.geometry.viewport.southwest;
let northeast=params.geometry.viewport.northeast;
let lowerCorner =[southwest.lng,southwest.lat];
let upperCorner = [northeast.lng,northeast.lat];
let extent = {lowerCorner: lowerCorner, upperCorner: upperCorner};
this.extent = extent;
// описание найденного геообъекта
this.address = params.formatted_address;
// точность соответствия поиска
this.precision = GeocodingDictionary.geocodingPrecision.google[params.geometry.location_type];
this.kind = GeocodingDictionary.geocodingKind.google[params.types[0]];
this.layerId = "Google:Geocoder";
}
/**
* Приводит результат геокодинга к классу SearchResult
* @return {SearchResult} - результат геокодирования
*/
getSearchResult() {
let self = this;
let attributes = {
address: self.address,
precision: self.precision,
kind: self.kind
};
let geometry = new ol.geom.Point(ol.proj.fromLonLat(self.position));
let result = new SearchResult({
layerId: self.layerId,
layerName: self.layerId,
queryGeometry: geometry,
geometry: geometry,
attributes: attributes,
preparedAttributes: [
{
name: "address",
alias: "Адрес",
group: undefined,
value: self.address
},
{
name: "precision",
alias: "Оценка геокодирования",
group: undefined,
value: self.precision
},
{
name: "kind",
alias: "Тип объекта",
group: undefined,
value: self.kind
}
],
dirtyData: new ol.Feature({
geometry: geometry,
address: self.address,
precision: self.precision,
kind: self.kind
}),
title: self.address
});
return result;
}
}
module.exports = GoogleGeocodingItem;