, geojson, througout, , , , . , :
HTML:
<leaflet geojson="geojson"></leaflet>
<input ng-model="search" />
<select multiple>
<option ng-repeat="feature in geojson.data.features">
{{feature.properties.NAME}}
</option>
</select>
JS:
angular.module('app').controller('controller', [
'$scope',
'$http',
'$filter',
function ($scope, $http, $filter) {
$scope.search = '';
$scope.geojson = {};
$http.get('stations.geojson').success(function (data) {
$scope.data = data;
$scope.geojson.data = data;
});
$scope.$watch('search', function (newVal, oldVal) {
if (newVal !== oldVal && newVal !== '') {
$scope.geojson.data = $filter('filter')($scope.data, 'NAME', newVal);
} else {
$scope.geojson.data = $scope.data;
}
});
}
]);
JS:
angular.module('app').filter('filter', [function() {
return function(geojson, searchProperty, searchValue) {
var matches = {'type': 'FeatureCollection', 'features': []};
angular.forEach(geojson.features, function(featureObject, featureKey) {
if (featureObject.properties.hasOwnProperty(searchProperty)) {
var property = featureObject.properties[searchProperty].toLowerCase();
var search = searchValue.toLowerCase();
if (property.indexOf(search) > -1) {
matches.features.push(featureObject);
}
}
});
return matches;
};
}]);
, , Plunker: http://plnkr.co/edit/z02JyuGE0Y8EDrhOqzoQ?p=preview
, , , , geojson NAME LINE:
:
<input ng-model="search.NAME" />
<input ng-model="search.LINE" />
:
$scope.search = {
'NAME': '',
'LINE': ''
};
:
$scope.$watch('search', function (newVal, oldVal) {
if (!angular.equals(newVal, oldVal)) {
var geojson = angular.copy($scope.data);
angular.forEach(newVal, function (value, property) {
if (value !== '') {
geojson = $filter('filter')(geojson, property, value);
}
});
$scope.geojson.data = geojson;
} else {
$scope.geojson.data = $scope.data;
}
}, true);
Plunker: http://plnkr.co/edit/OOx5DebtKXBfYqJ2Da3a?p=preview