Add possibility to add all search results to map at once

pull/108/head
Candid Dauth 2017-03-05 23:13:33 +01:00
rodzic 762577d50b
commit b9ce3f03f5
4 zmienionych plików z 50 dodań i 25 usunięć

Wyświetl plik

@ -329,17 +329,19 @@ fm.app.factory("fmMapLines", function(fmUtils, $uibModal, $compile, $timeout) {
map.messages.showMessage("danger", err);
});
},
createLine: function(type, routePoints, properties) {
createLine: function(type, routePoints, properties, noEdit) {
map.socket.addLine($.extend({ routePoints: routePoints, typeId: type.id }, properties)).then(function(line) {
linesUi.editLine(line);
if(!noEdit) {
linesUi.editLine(line);
// We have to wait until the server sends us the trackPoints of the line
var removeWatcher = map.socket.$watch(function() { return !!linesById[line.id]; }, function(exists) {
if(exists) {
linesById[line.id].openPopup();
removeWatcher();
}
});
// We have to wait until the server sends us the trackPoints of the line
var removeWatcher = map.socket.$watch(function() { return !!linesById[line.id]; }, function(exists) {
if(exists) {
linesById[line.id].openPopup();
removeWatcher();
}
});
}
}).catch(function(err) {
map.messages.showMessage("danger", err);
});

Wyświetl plik

@ -160,12 +160,14 @@ fm.app.factory("fmMapMarkers", function($uibModal, fmUtils, $compile, $timeout)
markersUi.createMarker(pos, type);
});
},
createMarker: function(pos, type, properties) {
createMarker: function(pos, type, properties, noEdit) {
map.socket.addMarker($.extend({ lon: pos.lon, lat: pos.lat, typeId: type.id }, properties)).then(function(marker) {
markersUi._addMarker(marker);
markersById[marker.id].openPopup();
markersUi.editMarker(marker);
if(!noEdit) {
markersById[marker.id].openPopup();
markersUi.editMarker(marker);
}
}).catch(function(err) {
map.messages.showMessage("danger", err);
});

Wyświetl plik

@ -35,8 +35,17 @@
</li>
</ul>
</div>
<div class="fm-search-buttons" ng-show="searchResults.features.length > 1">
<button type="button" class="btn btn-default" ng-model="showAll" uib-btn-checkbox>Show all</button>
<div class="fm-search-buttons" ng-show="searchResults.features.length > 0">
<button type="button" class="btn btn-default" ng-model="showAll" uib-btn-checkbox ng-show="searchResults.features.length > 1">Show all</button>
<div uib-dropdown keyboard-nav="true" class="pull-right">
<button id="search-add-all-button" type="button" class="btn btn-default" uib-dropdown-toggle>Add all to map <span class="caret"></span></button>
<ul class="dropdown-menu" uib-dropdown-menu role="menu" aria-labelledby="search-add-all-button">
<li ng-if="(searchResults.features | filter:{isMarker: true}).length > 0" role="menuitem" ng-repeat="type in socket.types | fmObjectFilter:{type:'marker'}"><a href="javascript:" ng-click="addAllToMap(type)">Add all markers as {{type.name}}</a></li>
<li ng-if="(searchResults.features | filter:{isLine: true}).length > 0" role="menuitem" ng-repeat="type in socket.types | fmObjectFilter:{type:'line'}"><a href="javascript:" ng-click="addAllToMap(type)">Add all lines/polygons as {{type.name}}</a></li>
</ul>
</div>
</div>
</div>

Wyświetl plik

@ -16,6 +16,7 @@ fm.app.factory("fmMapSearch", function($rootScope, $compile, fmUtils, $timeout,
scope.searchResults = null;
scope.showAll = false;
scope.activeResult = null;
scope.socket = map.socket;
scope.$watch("activeResult", () => {
setTimeout(() => {
@ -124,6 +125,22 @@ fm.app.factory("fmMapSearch", function($rootScope, $compile, fmUtils, $timeout,
map.displayView(view);
};
scope.addResultToMap = function(result, type, noEdit) {
if(type.type == "marker")
map.markersUi.createMarker(result.lat != null && result.lon != null ? result : { lat: result.geojson.coordinates[1], lon: result.geojson.coordinates[0] }, type, { name: result.display_name }, noEdit);
else if(type.type == "line") {
var trackPoints = _lineStringToTrackPoints(result.geojson);
map.linesUi.createLine(type, [ trackPoints[0], trackPoints[trackPoints.length-1] ], { trackPoints: trackPoints, mode: "track" }, noEdit);
}
};
scope.addAllToMap = function(type) {
for(let result of scope.searchResults.features) {
if((type.type == "marker" && result.isMarker) || (type.type == "line" && result.isLine))
scope.addResultToMap(result, type, true);
}
};
var el = $(require("./search.html")).insertAfter(map.map.getContainer());
$compile(el)(scope);
scope.$evalAsync(); // $compile only replaces variables on next digest
@ -257,20 +274,15 @@ fm.app.factory("fmMapSearch", function($rootScope, $compile, fmUtils, $timeout,
}
function renderResultPopup(query, results, result, popup) {
var scope = map.socket.$new();
var popupScope = map.socket.$new();
scope.result = result;
popupScope.result = result;
scope.addToMap = function(type) {
if(type.type == "marker")
map.markersUi.createMarker(result.lat != null && result.lon != null ? result : { lat: result.geojson.coordinates[1], lon: result.geojson.coordinates[0] }, type, { name: result.display_name });
else if(type.type == "line") {
var trackPoints = _lineStringToTrackPoints(result.geojson);
map.linesUi.createLine(type, [ trackPoints[0], trackPoints[trackPoints.length-1] ], { trackPoints: trackPoints, mode: "track" });
}
popupScope.addToMap = function(type) {
scope.addResultToMap(result, type);
};
scope.useForRoute = function(mode) {
popupScope.useForRoute = function(mode) {
searchUi.hide();
routeUi.show();
@ -288,7 +300,7 @@ fm.app.factory("fmMapSearch", function($rootScope, $compile, fmUtils, $timeout,
var el = popup.getContent();
$(el).html(require("./result-popup.html"));
$compile(el)(scope);
$compile(el)(popupScope);
// Prevent popup close on button click
$("button", el).click(function(e) {