kopia lustrzana https://github.com/FacilMap/facilmap
Add possibility to add LineString/Polygon search results as lines
rodzic
67a046e1cf
commit
762577d50b
|
@ -10,14 +10,15 @@
|
|||
<dd ng-repeat-end ng-bind-html="value | fmRenderOsmTag:key">{{value}}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="buttons" ng-if="!readonly && type">
|
||||
<div uib-dropdown keyboard-nav="true" ng-if="(types | fmPropertyCount:{type:type}) > 1">
|
||||
<div class="buttons" ng-if="!readonly && (result.isMarker || result.isLine)">
|
||||
{{filteredTypes = (result.isMarker && result.isLine ? types : (types | fmObjectFilter:{type:isMarker ? 'marker' : 'line'})); ""}}
|
||||
<div uib-dropdown keyboard-nav="true" ng-if="(filteredTypes | fmPropertyCount) > 1">
|
||||
<button id="add-type-button" type="button" class="btn btn-default" uib-dropdown-toggle>Add to map <span class="caret"></span></button>
|
||||
<ul class="dropdown-menu" uib-dropdown-menu role="menu" aria-labelledby="add-type-button">
|
||||
<li role="menuitem" ng-repeat="type in types | fmObjectFilter:{type:type}"><a href="javascript:" ng-click="addToMap(type)">{{type.name}}</a></li>
|
||||
<li role="menuitem" ng-repeat="type in filteredTypes"><a href="javascript:" ng-click="addToMap(type)">{{type.name}}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<button type="button" ng-if="(types | fmPropertyCount:{type:type}) == 1" class="btn btn-default" ng-click="addToMap()">Add to map</button>
|
||||
<button type="button" ng-if="(filteredTypes | fmPropertyCount) == 1" class="btn btn-default" ng-click="addToMap(filteredTypes[0])">Add to map</button>
|
||||
<div uib-dropdown keyboard-nav="true">
|
||||
<button type="button" class="btn btn-default" uib-dropdown-toggle>Use as <span class="caret"></span></button>
|
||||
<ul class="dropdown-menu" uib-dropdown-menu role="menu">
|
||||
|
|
|
@ -168,13 +168,26 @@ fm.app.factory("fmMapSearch", function($rootScope, $compile, fmUtils, $timeout,
|
|||
|
||||
scope.searchResults = results;
|
||||
|
||||
if(results && results.features.length > 0)
|
||||
if(results && results.features.length > 0) {
|
||||
for(let result of results.features) {
|
||||
if((result.lat != null && result.lon != null) || result.geojson && result.geojson.type == "Point")
|
||||
result.isMarker = true;
|
||||
if([ "LineString", "MultiLineString", "Polygon" ].indexOf(result.geojson && result.geojson.type) != -1)
|
||||
result.isLine = true;
|
||||
}
|
||||
|
||||
(scope.showAll && results.features.length > 1) ? scope.showAllResults(noZoom) : scope.showResult(scope.searchResults.features[0], noZoom);
|
||||
}
|
||||
}
|
||||
|
||||
function _lineStringToTrackPoints(geometry) {
|
||||
var ret = [ ];
|
||||
var coords = (geometry.type == "MultiLineString" ? geometry.coordinates : [ geometry.coordinates ]);
|
||||
var coords = (["MultiPolygon", "MultiLineString"].indexOf(geometry.type) != -1 ? geometry.coordinates : [ geometry.coordinates ]);
|
||||
|
||||
// Take only outer ring of polygons
|
||||
if(["MultiPolygon", "Polygon"].indexOf(geometry.type) != -1)
|
||||
coords = coords.map((coordArr) => coordArr[0]);
|
||||
|
||||
coords.forEach(function(linePart) {
|
||||
linePart.forEach(function(latlng) {
|
||||
ret.push({ lat: latlng[1], lon: latlng[0] });
|
||||
|
@ -248,24 +261,10 @@ fm.app.factory("fmMapSearch", function($rootScope, $compile, fmUtils, $timeout,
|
|||
|
||||
scope.result = result;
|
||||
|
||||
if((result.lat != null && result.lon != null) || result.geojson && result.geojson.type == "Point")
|
||||
scope.type = "marker";
|
||||
else if([ "LineString", "MultiLineString" ].indexOf(result.geojson && result.geojson.type) != -1)
|
||||
scope.type = "line";
|
||||
|
||||
scope.addToMap = function(type) {
|
||||
if(type == null) {
|
||||
for(var i in map.socket.types) {
|
||||
if(map.socket.types[i].type == scope.type) {
|
||||
type = map.socket.types[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(scope.type == "marker")
|
||||
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(scope.type == "line") {
|
||||
else if(type.type == "line") {
|
||||
var trackPoints = _lineStringToTrackPoints(result.geojson);
|
||||
map.linesUi.createLine(type, [ trackPoints[0], trackPoints[trackPoints.length-1] ], { trackPoints: trackPoints, mode: "track" });
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue