Skip to content

Commit f42b1de

Browse files
author
Paweł Marynowski
committed
feat(map): add search for map
1 parent cb3dd9e commit f42b1de

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/components/main/map/map.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@
44
Dashboard
55
</md-button>
66
<span flex></span>
7+
<md-autocomplete
8+
md-input-name="autocompleteField"
9+
md-selected-item="$ctrl.search.selectedItem"
10+
md-search-text="$ctrl.search.text"
11+
md-items="item in $ctrl.querySearch($ctrl.search.text)"
12+
md-selected-item-change="$ctrl.goToItem(item)"
13+
md-item-text="item.label"
14+
md-min-length="1"
15+
placeholder="Search"
16+
md-menu-class="autocomplete-custom-template">
17+
<md-item-template>
18+
<strong>{{item.label}}</strong>
19+
<span>{{item.description}}</span>
20+
</md-item-template>
21+
</md-autocomplete>
722
</div>
823
</md-toolbar>
924
<div class="container" layout="column" layout-align="space-between stretch" flex>

src/components/main/map/map.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ function controller($location, $scope, $state, $stateParams, $timeout, leafletDa
1111

1212
// bindings
1313

14-
vm.goToItem = item => $state.go('main.list', { id: item.id.substring(1) });
14+
vm.goToItem = item => setMap(item);
1515
vm.map = mapService.getMapInstance({ center: { lat: 51.686, lng: 19.545, zoom: 7 } });
16+
vm.querySearch = text => wikidata.getSearch(text);
1617
vm.list = [];
1718
vm.listParams = {};
1819
vm.loading = vm.loadingMap = true;
@@ -96,6 +97,24 @@ function controller($location, $scope, $state, $stateParams, $timeout, leafletDa
9697
return obj;
9798
}
9899

100+
function setMap(item) {
101+
if (!item || !item.id) { return; }
102+
vm.loading = true;
103+
wikidata.getById(item.id)
104+
.then((data) => {
105+
const element = Object.values(data)[0];
106+
const coords = element.claims.P625;
107+
if (coords) {
108+
const lat = coords.values[0].value.latitude;
109+
const lng = coords.values[0].value.longitude;
110+
leafletData.getMap().then((map) => {
111+
map.setView([lat, lng], 14);
112+
getDataBB(map.getBounds());
113+
});
114+
}
115+
});
116+
}
117+
99118
function setMarker(element) {
100119
return {
101120
lat: +element.coord[1],

0 commit comments

Comments
 (0)