Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.

feat(markers,paths,geojson,watchOptions): More flexible watch options… #77

Merged
merged 1 commit into from
Nov 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
232 changes: 131 additions & 101 deletions dist/ui-leaflet.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/ui-leaflet.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/ui-leaflet.min.no-header.js

Large diffs are not rendered by default.

232 changes: 131 additions & 101 deletions dist/ui-leaflet_dev_mapped.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ui-leaflet_dev_mapped.js.map

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion doc/markers-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ Markers watches
Every marker you add to the map is watched for changes by default, so a change in a marker property will be reflected on the map directly. This feature can be disabled if you don't need to dynamic modification of markers and prefer better performance. This is the command used to disable markers watchers:

```
<leaflet markers="markers" watch-markers="false"></leaflet>
<leaflet markers="markers" watch-options='watchOptions'></leaflet>
```

where:

```
scope.watchOptions = { markers: { type: null, individual: { type: null } } };
```

By default the markers will be watched, so we can change its properties dynamically, like in [this demo](http://angular-ui.github.io/ui-leaflet/examples/markers-update-example.html).
Expand Down
6 changes: 3 additions & 3 deletions examples/0118-basic-double-map-events-example.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<link rel="stylesheet" href="../bower_components/leaflet/dist/leaflet.css" />
<script>
var app = angular.module("demoapp", ['ui-leaflet']);
app.controller("BasicDoubleMapEventsController", [ "$scope", "$log", "leafletData", "leafletEvents", function($scope, $log, leafletData, leafletEvents) {
app.controller("BasicDoubleMapEventsController", [ "$scope", "$log", "leafletData", "leafletMapEvents", function($scope, $log, leafletData, leafletMapEvents) {
angular.extend($scope, {
london: {
lat: 51.505,
Expand All @@ -30,12 +30,12 @@

$scope.events = {
map: {
enable: leafletEvents.getAvailableMapEvents(),
enable: leafletMapEvents.getAvailableMapEvents(),
logic: 'emit'
}
};

var mapEvents = leafletEvents.getAvailableMapEvents();
var mapEvents = leafletMapEvents.getAvailableMapEvents();
for (var k in mapEvents) {
var eventName = 'leafletDirectiveMap.' + mapEvents[k];
$scope.$on(eventName, function(event){
Expand Down
23 changes: 20 additions & 3 deletions examples/0303-paths-3000-items-example.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
defaults: {
scrollWheelZoom: false
},
watchOptions: {
paths: {
type: 'watch',
individual: {
type: null
}
}
},
//restrict map panning for this region
maxbounds: {
northEast: {
Expand Down Expand Up @@ -50,15 +58,19 @@

//bind locationGrid to zoom level
$scope.$watch("centroid.zoom", function (zoom) {
var tempPaths;
if (zoom <= 3) {
//clear path object
$scope.paths = {};

//make new paths
tempPaths = {};

//get location data and initialize leaflet circles
LocationDataService.getLocationsTenGrid().then(function (res) {
angular.forEach(res.data, function (value, key) {
if (value.lat !== null && value.lon !== null) {
$scope.paths['circle' + key] = {
tempPaths['circle' + key] = {
type: 'circle',
className: 'testClass',
fillColor: 'DarkSlateGray',
Expand All @@ -73,6 +85,7 @@
};
}
});
$scope.paths = tempPaths;
}, function (error) {
console.log('An error occured!', error);
});
Expand All @@ -81,11 +94,14 @@
//clear path object
$scope.paths = {};

//make new paths
tempPaths = {};

//get location data and initialize leaflet circles
LocationDataService.getLocationsZeroOneGrid().then(function (res) {
angular.forEach(res.data, function (value, key) {
if (value.lat !== null && value.lon !== null) {
$scope.paths['circle' + key] = {
tempPaths['circle' + key] = {
type: 'circle',
className: 'testClass',
fillColor: 'DarkSlateGray',
Expand All @@ -100,6 +116,7 @@
};
}
});
$scope.paths = tempPaths;
}, function (error) {
console.log('An error occured!', error);
});
Expand Down Expand Up @@ -141,7 +158,7 @@
</script>
</head>
<body ng-controller="Paths3000ItemsController">
<leaflet watch-paths="false" lf-center="centroid" maxbounds="maxbounds" layers="layers" paths="paths" defaults="defaults" width="100%" height="480px"></leaflet>
<leaflet watch-options="watchOptions" lf-center="centroid" maxbounds="maxbounds" layers="layers" paths="paths" defaults="defaults" width="100%" height="480px"></leaflet>
<h1>3000 items in a map performance</h1>
</body>
</html>
6 changes: 3 additions & 3 deletions examples/0514-markers-delayed-events.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<link rel="stylesheet" href="../bower_components/leaflet/dist/leaflet.css" />
<script>
var app = angular.module("demoapp", ['ui-leaflet']);
app.controller("MarkersDelayedEventsController", ["$scope", "leafletEvents", function($scope, leafletEvents){
app.controller("MarkersDelayedEventsController", ["$scope", "leafletMarkerEvents", function($scope, leafletMarkerEvents){
angular.extend($scope, {
london: {
lat: 51.505,
Expand Down Expand Up @@ -40,12 +40,12 @@

$scope.events = {
markers: {
enable: leafletEvents.getAvailableMarkerEvents(),
enable: leafletMarkerEvents.getAvailableEvents(),
}
};

$scope.eventDetected = "No events yet...";
var markerEvents = leafletEvents.getAvailableMarkerEvents();
var markerEvents = leafletMarkerEvents.getAvailableEvents();
for (var k in markerEvents){
var eventName = 'leafletDirectiveMarker.' + markerEvents[k];
$scope.$on(eventName, function(event, args){
Expand Down
6 changes: 3 additions & 3 deletions examples/0604-mixed-markers-nested-events-example.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<link rel="stylesheet" href="../bower_components/leaflet/dist/leaflet.css"/>
<script>
var app = angular.module("demoapp", ['ui-leaflet']);
app.controller("MixedMarkersNestedEventsController", ["$scope", "leafletEvents", function ($scope, leafletEvents) {
app.controller("MixedMarkersNestedEventsController", ["$scope", "leafletMarkerEvents", function ($scope, leafletMarkerEvents) {
$scope.map = {
show: true
};
Expand Down Expand Up @@ -53,12 +53,12 @@

$scope.events = {
markers: {
enable: leafletEvents.getAvailableMarkerEvents()
enable: leafletMarkerEvents.getAvailableEvents()
}
};

$scope.eventDetected = "No events yet...";
var markerEvents = leafletEvents.getAvailableMarkerEvents();
var markerEvents = leafletMarkerEvents.getAvailableEvents();
for (var k in markerEvents) {
var eventName = 'leafletDirectiveMarker.' + markerEvents[k];
$scope.$on(eventName, function (event, args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
});
}, 4000);
angular.extend($scope, {
markersWatchOptions: {
doWatch: false,
isDeep: false,
individual: {
doWatch: false,
isDeep: false
watchOptions: {
markers: {
type: null,
individual: {
type: null
}
}
},
center: {
Expand Down Expand Up @@ -160,7 +160,7 @@
markers="markers"
layers="layers"
markers-nested="true"
markers-watch-options="markersWatchOptions"
watch-options="watchOptions"
height="480px" width="100%">
</leaflet>
<h1>Overlays with nested markers no watchers example</h1>
Expand Down
30 changes: 15 additions & 15 deletions examples/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ var app = angular.module('webapp');
});
};
}]);
app.controller("BasicDoubleMapEventsController", [ "$scope", "$log", "leafletData", "leafletEvents", function($scope, $log, leafletData, leafletEvents) {
app.controller("BasicDoubleMapEventsController", [ "$scope", "$log", "leafletData", "leafletMapEvents", function($scope, $log, leafletData, leafletMapEvents) {
angular.extend($scope, {
london: {
lat: 51.505,
Expand All @@ -147,11 +147,11 @@ var app = angular.module('webapp');
});
$scope.events = {
map: {
enable: leafletEvents.getAvailableMapEvents(),
enable: leafletMapEvents.getAvailableMapEvents(),
logic: 'emit'
}
};
var mapEvents = leafletEvents.getAvailableMapEvents();
var mapEvents = leafletMapEvents.getAvailableMapEvents();
for (var k in mapEvents) {
var eventName = 'leafletDirectiveMap.' + mapEvents[k];
$scope.$on(eventName, function(event){
Expand Down Expand Up @@ -3232,7 +3232,7 @@ var app = angular.module('webapp');
},
});
} ]);
app.controller("MarkersDelayedEventsController", ["$scope", "leafletEvents", function($scope, leafletEvents){
app.controller("MarkersDelayedEventsController", ["$scope", "leafletMarkerEvents", function($scope, leafletMarkerEvents){
angular.extend($scope, {
london: {
lat: 51.505,
Expand Down Expand Up @@ -3261,11 +3261,11 @@ var app = angular.module('webapp');
};
$scope.events = {
markers: {
enable: leafletEvents.getAvailableMarkerEvents(),
enable: leafletMarkerEvents.getAvailableEvents(),
}
};
$scope.eventDetected = "No events yet...";
var markerEvents = leafletEvents.getAvailableMarkerEvents();
var markerEvents = leafletMarkerEvents.getAvailableEvents();
for (var k in markerEvents){
var eventName = 'leafletDirectiveMarker.' + markerEvents[k];
$scope.$on(eventName, function(event, args){
Expand Down Expand Up @@ -4058,12 +4058,12 @@ var app = angular.module('webapp');
});
}, 4000);
angular.extend($scope, {
markersWatchOptions: {
doWatch: false,
isDeep: false,
individual: {
doWatch: false,
isDeep: false
watchOptions: {
markers: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zacronos or @jessertaylor what do you think about having explicit 'none' to disable watches? IE Why not just disable watches if type is undefined?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, both should be allowed. Then there is a way to be explicit if desired, but it isn't required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If watches were off by default, then I would support undefined or null as a way to turn off watching, however, watches are watchDeep by default as this was how angular-leaflet-directive was originally designed (paths have a bit different defaults). I would argue the absence of a property should probably yield the default behaviour. I would support replacing 'none' with null (explicitly defined) if so desired. Supporting both is more hassle than it is worth as some conditionals check whether a watch is set simply by checking if type != 'none' (supporting both would require longer conditionals).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'm good w that.

type: null
individual: {
type: null
}
}
},
center: {
Expand Down Expand Up @@ -4196,7 +4196,7 @@ var app = angular.module('webapp');
console.log(data);
});
}]);
app.controller("MixedMarkersNestedEventsController", ["$scope", "leafletEvents", function ($scope, leafletEvents) {
app.controller("MixedMarkersNestedEventsController", ["$scope", "leafletMarkerEvents", function ($scope, leafletMarkerEvents) {
$scope.map = {
show: true
};
Expand Down Expand Up @@ -4238,11 +4238,11 @@ var app = angular.module('webapp');
};
$scope.events = {
markers: {
enable: leafletEvents.getAvailableMarkerEvents()
enable: leafletMarkerEvents.getAvailableEvents()
}
};
$scope.eventDetected = "No events yet...";
var markerEvents = leafletEvents.getAvailableMarkerEvents();
var markerEvents = leafletMarkerEvents.getAvailableEvents();
for (var k in markerEvents) {
var eventName = 'leafletDirectiveMarker.' + markerEvents[k];
$scope.$on(eventName, function (event, args) {
Expand Down
6 changes: 3 additions & 3 deletions examples/js/controllers/BasicDoubleMapEventsController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
app.controller("BasicDoubleMapEventsController", [ "$scope", "$log", "leafletData", "leafletEvents", function($scope, $log, leafletData, leafletEvents) {
app.controller("BasicDoubleMapEventsController", [ "$scope", "$log", "leafletData", "leafletMapEvents", function($scope, $log, leafletData, leafletMapEvents) {
angular.extend($scope, {
london: {
lat: 51.505,
Expand All @@ -18,11 +18,11 @@
});
$scope.events = {
map: {
enable: leafletEvents.getAvailableMapEvents(),
enable: leafletMapEvents.getAvailableMapEvents(),
logic: 'emit'
}
};
var mapEvents = leafletEvents.getAvailableMapEvents();
var mapEvents = leafletMapEvents.getAvailableMapEvents();
for (var k in mapEvents) {
var eventName = 'leafletDirectiveMap.' + mapEvents[k];
$scope.$on(eventName, function(event){
Expand Down
6 changes: 3 additions & 3 deletions examples/js/controllers/MarkersDelayedEventsController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
app.controller("MarkersDelayedEventsController", ["$scope", "leafletEvents", function($scope, leafletEvents){
app.controller("MarkersDelayedEventsController", ["$scope", "leafletMarkerEvents", function($scope, leafletMarkerEvents){
angular.extend($scope, {
london: {
lat: 51.505,
Expand Down Expand Up @@ -27,11 +27,11 @@
};
$scope.events = {
markers: {
enable: leafletEvents.getAvailableMarkerEvents(),
enable: leafletMarkerEvents.getAvailableEvents(),
}
};
$scope.eventDetected = "No events yet...";
var markerEvents = leafletEvents.getAvailableMarkerEvents();
var markerEvents = leafletMarkerEvents.getAvailableEvents();
for (var k in markerEvents){
var eventName = 'leafletDirectiveMarker.' + markerEvents[k];
$scope.$on(eventName, function(event, args){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
});
}, 4000);
angular.extend($scope, {
markersWatchOptions: {
doWatch: false,
isDeep: false,
individual: {
doWatch: false,
isDeep: false
watchOptions: {
markers: {
type: null
individual: {
type: null
}
}
},
center: {
Expand Down
6 changes: 3 additions & 3 deletions examples/js/controllers/MixedMarkersNestedEventsController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
app.controller("MixedMarkersNestedEventsController", ["$scope", "leafletEvents", function ($scope, leafletEvents) {
app.controller("MixedMarkersNestedEventsController", ["$scope", "leafletMarkerEvents", function ($scope, leafletMarkerEvents) {
$scope.map = {
show: true
};
Expand Down Expand Up @@ -40,11 +40,11 @@
};
$scope.events = {
markers: {
enable: leafletEvents.getAvailableMarkerEvents()
enable: leafletMarkerEvents.getAvailableEvents()
}
};
$scope.eventDetected = "No events yet...";
var markerEvents = leafletEvents.getAvailableMarkerEvents();
var markerEvents = leafletMarkerEvents.getAvailableEvents();
for (var k in markerEvents) {
var eventName = 'leafletDirectiveMarker.' + markerEvents[k];
$scope.$on(eventName, function (event, args) {
Expand Down
10 changes: 8 additions & 2 deletions src/directives/geojson.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ angular.module('ui-leaflet')
.directive('geojson', function (leafletLogger, $rootScope, leafletData, leafletHelpers,
leafletWatchHelpers, leafletDirectiveControlsHelpers,leafletIterators, leafletGeoJsonEvents) {
var _maybeWatch = leafletWatchHelpers.maybeWatch,
_watchOptions = leafletHelpers.watchOptions,
_defaultWatchOptions = leafletHelpers.watchOptions,
_extendDirectiveControls = leafletDirectiveControlsHelpers.extend,
hlp = leafletHelpers,
$it = leafletIterators;
Expand All @@ -21,7 +21,13 @@ angular.module('ui-leaflet')
_hasSetLeafletData = false;

controller.getMap().then(function(map) {
var watchOptions = leafletScope.geojsonWatchOptions || _watchOptions;
var watchOptions;
if(leafletScope.watchOptions && leafletScope.watchOptions.geojson) {
watchOptions = leafletScope.watchOptions.geojson;
}
else {
watchOptions = _defaultWatchOptions;
}

var _hookUpEvents = function(geojson, maybeName){
var onEachFeature;
Expand Down
3 changes: 1 addition & 2 deletions src/directives/leaflet.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ angular.module('ui-leaflet', ['nemLogging']).directive('leaflet',
controls : '=',
decorations : '=',
eventBroadcast : '=',
markersWatchOptions : '=',
geojsonWatchOptions : '='
watchOptions : '='
},
transclude: true,
template: '<div class="angular-leaflet-map"><div ng-transclude></div></div>',
Expand Down
Loading