I use leaflet-angular-directive, i successfully display objects in table and map, although i achieved filtering through searching input only affect geojson objects in table.
My aim: make filtering through searching input affect geojson objects in table and map.
My Module
var AppMapDirectory = angular.module('DirectoryAppMap', ['ngResource', 'leaflet- directive']);
My Factory
AppMapDirectory.factory("Directory", function($resource) {
return $resource("json/result.json", {}, {
get: {
method: "GET",
cache: true
}
});
});
My Controller
AppMapDirectory.controller("DirectoryMapList", function($scope, Directory) {
Directory.get(function(data) {
$scope.hf_directory = data.features;
function onEachFeature(feature, layer) {
layer.bindPopup("<b>Wardname:</b> " + feature.properties.name +
"<br><b>Category:" + feature.properties.category + "");
}
angular.extend($scope, {
geojson: {
data: $scope.hf_directory,
onEachFeature: onEachFeature
}
});
});
angular.extend($scope, {
defaults: {
tileLayer: "https://dnv9my2eseobd.cloudfront.net/v3/foursquare.map-ikj05elx/{z}/{x}/{y}.png",
maxZoom: 14,
minZoom: 3
},
center: {
lat: 8.1238,
lng: 11.8777,
zoom: 2
}
});
});
My Template
<div ng-app="DirectoryAppMap" ng-controller="DirectoryMapList">
<ul>
<li><input ng-model="search.properties.name" placeholder="Name" ></li>
<li><input ng-model="search.properties.category" placeholder="Category"></li>
</ul>
<table>
<thead>
<tr>
<th>Name</th>
<th>Category</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="hf in hf_directory| filter:search">
<td>{{ hf.properties.name }}</td>
<td>{{ hf.properties.category }}</td>
</tr>
</tbody>
</table>
<div leaflet id="map" center="center" defaults="defaults" geojson="geojson">
</div>
</div>
Maybe somebody could show me right direction so I know what I am doing wrong, I tried to bind search to leaflet on many different ways but without success, actually i think that it is not something that should be done on template side? But rather in options for geojson like filter? Is this the right thing to do now?
I used ng-repeat directive but then i had thousands of maps, maybe it is possible to use ng-repeat and still have only one map?
Here's an example of how to reflect searchresults in the geojson dataset, i've commented the code througout to explain some things since it's a rather large piece and understanding works best by example i think. So here it goes:
Controller HTML:
Controller JS:
Filter JS:
Hope that helps, here's a working example on Plunker: http://plnkr.co/edit/z02JyuGE0Y8EDrhOqzoQ?p=preview
After discussion in the comments about filtering on multiple properties i thought it might be handy to add that in an example, so assuming the geojson has a NAME and a LINE property:
Multiple inputs:
Change search property in scope to an object:
Modified watch function:
Here's the updated example on Plunker: http://plnkr.co/edit/OOx5DebtKXBfYqJ2Da3a?p=preview