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

Commit

Permalink
feat(markers,paths,geojson,watchOptions): More flexible watch options…
Browse files Browse the repository at this point in the history
… and more

watch-options has been expanded to include paths and redesigned to handle
more types of watching. `markersWatchOptions` and `geojsonWatchOptions` are no
longer supported. Instead, this direcitve now supports the `watch-options`
attribute, which takes an object that contains the watch options for each
map element type:

```
watchOptions = {
    markers: <markerWatchOptions>,
    geojson: <geojsonWatchOptions>,
    paths: <pathsWatchOptions>
}
```

The watch options for these map element types looks like:

```
{
    type: <watchTypes>,
    individual: {
        type: <watchTypes>
    }
}
```

`<watchTypes>` can be one of:
-`'watch'`: `$scope.$watch` with no deep watch on the object
-`'watchDeep'`: `$scope.$watch` with a deep watch on the object
-`'watchCollection'`: `$scope.$watchCollection` on the object
-`null`: Do not watch the collection (note: you must explicity `null`,
`undefined` will not work).

I've removed support for the directive attributes `watch-markers` and
`watch-paths`. While these make sense when set to false, it's ambiguous
how they should function when set to `true`, especially when combined
with `watch-options`.

There are some other minor fixes in this commit (fixing breaking examples,
and another small bug).

BREAKING CHANGE: `markersWatchOptions`, `geojsonWatchOptions`, `watch-markers`,
and `watch-paths` are no longer supported. The format of the watch options has
also changed.

Before:

```
<leaflet defaults='defaults' markers-watch-options='markerWatchOptions'>
```

After:

```
<leaflet defaults='defaults' watch-options='watchOptions'>

<script>
    $scope.watchOptions = {
        markers: <watchOptions>
    }
</script>
```

The same can be said for `geojson`.

WatchOptions. `shouldWatch` and `isDeep` are no longer supported, but the
same behaviour can be achieved:

`shouldWatch: true`, `isDeep: true` = `type = 'watchDeep'`
`shouldWatch: true`, `isDeep: false` = `type = 'watch'`
`shouldWatch: false`, `isDeep: false` = `type = null`
`shouldWatch: false`, `isDeep: true` = `type = null`

Furthermore,

Before:

```
<leaflet watch-markers='false'>
```

After:

```
<leaflet watch-options='watchOptions'>

<script>
$scope.watchOptions = {
    markers: {
        type: null,
        individual: {
            type: null
        }
    }
};
</script>
```

`watch-paths='false'` can be achieved in a similar manner.
  • Loading branch information
cgat committed Nov 3, 2015
1 parent ffcfa2f commit 963de33
Show file tree
Hide file tree
Showing 25 changed files with 474 additions and 360 deletions.
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: {
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

0 comments on commit 963de33

Please sign in to comment.