Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.
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
30 changes: 13 additions & 17 deletions dist/ui-leaflet.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* ui-leaflet 1.0.1 2016-06-08
* ui-leaflet 1.0.1 2016-09-17
* ui-leaflet - An AngularJS directive to easily interact with Leaflet maps
* git: https://github.com/angular-ui/ui-leaflet
*/
Expand Down Expand Up @@ -230,14 +230,15 @@ angular.module('ui-leaflet').factory('leafletBoundsHelpers', ["leafletLogger", "
angular.module('ui-leaflet').factory('leafletControlHelpers', ["$rootScope", "leafletLogger", "leafletHelpers", "leafletLayerHelpers", "leafletMapDefaults", function ($rootScope, leafletLogger, leafletHelpers, leafletLayerHelpers, leafletMapDefaults) {
var isDefined = leafletHelpers.isDefined,
isObject = leafletHelpers.isObject,
get = leafletHelpers.get,
createLayer = leafletLayerHelpers.createLayer,
_controls = {},
errorHeader = leafletHelpers.errorHeader + ' [Controls] ',
$log = leafletLogger;

var _controlLayersMustBeVisible = function(baselayers, overlays, mapId) {
var defaults = leafletMapDefaults.getDefaults(mapId);
if(!defaults.controls.layers.visible) {
if(!get(defaults, 'controls.layers.visible')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This kinda stuff is where I much prefer coffeescript... anyway using get to get a value as undefined regardless how nested.

return false;
}

Expand Down Expand Up @@ -275,7 +276,7 @@ angular.module('ui-leaflet').factory('leafletControlHelpers', ["$rootScope", "le
angular.extend(controlOptions, defaults.controls.layers.options);

var control;
if(defaults.controls.layers && isDefined(defaults.controls.layers.control)) {
if(!!get(defaults, 'controls.layers.control')) {
control = defaults.controls.layers.control.apply(this, [[], [], controlOptions]);
} else {
control = new L.control.layers([], [], controlOptions);
Expand Down Expand Up @@ -619,21 +620,15 @@ angular.module('ui-leaflet').service('leafletHelpers', ["$q", "$log", function($
};
_getObjectValue(obj,"bike.1") returns 'hi'
this is getPath in ui-gmap

like _.get
http://stackoverflow.com/questions/2631001/javascript-test-for-existence-of-nested-object-key?page=1&tab=active#tab-top
*/
var _getObjectValue = function(object, pathStr) {
var obj;
if (!object || !angular.isObject(object))
return;
//if the key is not a sting then we already have the value
if ((pathStr === null) || !angular.isString(pathStr)) {
return pathStr;
}
obj = object;
pathStr.split('.').forEach(function(value) {
if (obj) {
obj = obj[value];
}
});
var _getObjectValue = function (object, path){
if(!object) return;
path = path.split('.');
var obj = object[path.shift()];
while(obj && path.length) obj = obj[path.shift()];
return obj;
};

Expand Down Expand Up @@ -751,6 +746,7 @@ angular.module('ui-leaflet').service('leafletHelpers', ["$q", "$log", function($
clone: _clone,
errorHeader: _errorHeader,
getObjectValue: _getObjectValue,
get: _getObjectValue,
getObjectArrayPath: _getObjectArrayPath,
getObjectDotPath: _getObjectDotPath,
defaultTo: function(val, _default) {
Expand Down
4 changes: 2 additions & 2 deletions dist/ui-leaflet.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/ui-leaflet.min.no-header.js

Large diffs are not rendered by default.

30 changes: 13 additions & 17 deletions dist/ui-leaflet_dev_mapped.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/services/leafletControlHelpers.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
angular.module('ui-leaflet').factory('leafletControlHelpers', function ($rootScope, leafletLogger, leafletHelpers, leafletLayerHelpers, leafletMapDefaults) {
var isDefined = leafletHelpers.isDefined,
isObject = leafletHelpers.isObject,
get = leafletHelpers.get,
createLayer = leafletLayerHelpers.createLayer,
_controls = {},
errorHeader = leafletHelpers.errorHeader + ' [Controls] ',
$log = leafletLogger;

var _controlLayersMustBeVisible = function(baselayers, overlays, mapId) {
var defaults = leafletMapDefaults.getDefaults(mapId);
if(!defaults.controls.layers.visible) {
if(!get(defaults, 'controls.layers.visible')) {
return false;
}

Expand Down Expand Up @@ -46,7 +47,7 @@ angular.module('ui-leaflet').factory('leafletControlHelpers', function ($rootSco
angular.extend(controlOptions, defaults.controls.layers.options);

var control;
if(defaults.controls.layers && isDefined(defaults.controls.layers.control)) {
if(!!get(defaults, 'controls.layers.control')) {
control = defaults.controls.layers.control.apply(this, [[], [], controlOptions]);
} else {
control = new L.control.layers([], [], controlOptions);
Expand Down
23 changes: 9 additions & 14 deletions src/services/leafletHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,15 @@ angular.module('ui-leaflet').service('leafletHelpers', function($q, $log) {
};
_getObjectValue(obj,"bike.1") returns 'hi'
this is getPath in ui-gmap

like _.get
http://stackoverflow.com/questions/2631001/javascript-test-for-existence-of-nested-object-key?page=1&tab=active#tab-top
*/
var _getObjectValue = function(object, pathStr) {
var obj;
if (!object || !angular.isObject(object))
return;
//if the key is not a sting then we already have the value
if ((pathStr === null) || !angular.isString(pathStr)) {
return pathStr;
}
obj = object;
pathStr.split('.').forEach(function(value) {
if (obj) {
obj = obj[value];
}
});
var _getObjectValue = function (object, path){
if(!object) return;
path = path.split('.');
var obj = object[path.shift()];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using while and shift should be quicker then forcibly iterating through everything via forEach.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good...

while(obj && path.length) obj = obj[path.shift()];
return obj;
};

Expand Down Expand Up @@ -146,6 +140,7 @@ angular.module('ui-leaflet').service('leafletHelpers', function($q, $log) {
clone: _clone,
errorHeader: _errorHeader,
getObjectValue: _getObjectValue,
get: _getObjectValue,
getObjectArrayPath: _getObjectArrayPath,
getObjectDotPath: _getObjectDotPath,
defaultTo: function(val, _default) {
Expand Down
29 changes: 24 additions & 5 deletions test/unit/services/leafletHelpersSpec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,30 @@ describe 'leafletHelpers', ->
expect(@subject.defaultTo(null, '')).toBe('')

describe 'Object Helpers', ->
it 'should correctly fetch object values using dot-notation', ->
object = { foo: { sea: 'hawks' }}
expect(@subject.getObjectValue(object, 'foo.sea')).toEqual('hawks')
expect(@subject.getObjectValue(object, 'foo.sea.birds')).toEqual(undefined)
expect(@subject.getObjectValue(object, 'boo.hoo')).toEqual(undefined)
describe 'get / getObjectValue', ->
it 'should correctly fetch object values using dot-notation', ->
object = { foo: { sea: 'hawks' }}
expect(@subject.getObjectValue(object, 'foo.sea')).toEqual('hawks')
expect(@subject.getObjectValue(object, 'foo.sea.birds')).toEqual(undefined)
expect(@subject.getObjectValue(object, 'boo.hoo')).toEqual(undefined)


describe 'undefined tests', ->
it 'starts undefined is undefined', ->
object = undefined
expect(@subject.get(object, 'foo.sea')).toBeFalsy()

it 'second depth field undefined, with attempt to access third depth', ->
object =
second:
third:
fourth: true

expect(@subject.get(object, 'second.third.fourth')).toBeTruthy()

object.second.third = undefined
expect(@subject.get(object, 'second.third.fourth'))


describe 'obtainEffectiveMapId', ->
describe 'no mapId', ->
Expand Down