Skip to content

Commit

Permalink
Allow custom layer type
Browse files Browse the repository at this point in the history
  • Loading branch information
furstenheim committed Feb 15, 2017
1 parent b8f4d44 commit c1bf6cb
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 78 deletions.
55 changes: 30 additions & 25 deletions dist/angular-leaflet-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -2016,35 +2016,39 @@ angular.module('leaflet-directive')
return false;
}

if (Object.keys(layerTypes).indexOf(layerDefinition.type) === -1) {
$log.error('[AngularJS - Leaflet] A layer must have a valid type: ' + Object.keys(layerTypes));
return false;
}
// One of the known types
if (Object.keys(layerTypes).indexOf(layerDefinition.type) !== -1) {

// Check if the layer must have an URL
if (layerTypes[layerDefinition.type].mustHaveUrl && !isString(layerDefinition.url)) {
$log.error('[AngularJS - Leaflet] A base layer must have an url');
return false;
}
// Check if the layer must have an URL
if (layerTypes[layerDefinition.type].mustHaveUrl && !isString(layerDefinition.url)) {
$log.error('[AngularJS - Leaflet] A base layer must have an url');
return false;
}

if (layerTypes[layerDefinition.type].mustHaveData && !isDefined(layerDefinition.data)) {
$log.error('[AngularJS - Leaflet] The base layer must have a "data" array attribute');
return false;
}
if (layerTypes[layerDefinition.type].mustHaveData && !isDefined(layerDefinition.data)) {
$log.error('[AngularJS - Leaflet] The base layer must have a "data" array attribute');
return false;
}

if (layerTypes[layerDefinition.type].mustHaveLayer && !isDefined(layerDefinition.layer)) {
$log.error('[AngularJS - Leaflet] The type of layer ' + layerDefinition.type + ' must have an layer defined');
return false;
}
if (layerTypes[layerDefinition.type].mustHaveLayer && !isDefined(layerDefinition.layer)) {
$log.error('[AngularJS - Leaflet] The type of layer ' + layerDefinition.type + ' must have an layer defined');
return false;
}

if (layerTypes[layerDefinition.type].mustHaveBounds && !isDefined(layerDefinition.bounds)) {
$log.error('[AngularJS - Leaflet] The type of layer ' + layerDefinition.type + ' must have bounds defined');
return false;
}
if (layerTypes[layerDefinition.type].mustHaveBounds && !isDefined(layerDefinition.bounds)) {
$log.error('[AngularJS - Leaflet] The type of layer ' + layerDefinition.type + ' must have bounds defined');
return false;
}

if (layerTypes[layerDefinition.type].mustHaveKey && !isDefined(layerDefinition.key)) {
$log.error('[AngularJS - Leaflet] The type of layer ' + layerDefinition.type + ' must have key defined');
return false;
if (layerTypes[layerDefinition.type].mustHaveKey && !isDefined(layerDefinition.key)) {
$log.error('[AngularJS - Leaflet] The type of layer ' + layerDefinition.type + ' must have key defined');
return false;
}
} else {
// Type unknown at build time
if (typeof L.tileLayer[layerDefinition.type] !== 'function') {
return false;
}
}

return true;
Expand Down Expand Up @@ -2089,7 +2093,8 @@ angular.module('leaflet-directive')
};

//TODO Add $watch to the layer properties
return layerTypes[layerDefinition.type].createLayer(params);
if (layerTypes[layerDefinition.type]) return layerTypes[layerDefinition.type].createLayer(params);
return L.tileLayer[layerDefinition.type](params.url, params.options);
}

function safeAddLayer(map, layer) {
Expand Down
6 changes: 3 additions & 3 deletions dist/angular-leaflet-directive.min.js

Large diffs are not rendered by default.

55 changes: 30 additions & 25 deletions dist/angular-leaflet-directive.no-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -1987,35 +1987,39 @@ angular.module('leaflet-directive')
return false;
}

if (Object.keys(layerTypes).indexOf(layerDefinition.type) === -1) {
$log.error('[AngularJS - Leaflet] A layer must have a valid type: ' + Object.keys(layerTypes));
return false;
}
// One of the known types
if (Object.keys(layerTypes).indexOf(layerDefinition.type) !== -1) {

// Check if the layer must have an URL
if (layerTypes[layerDefinition.type].mustHaveUrl && !isString(layerDefinition.url)) {
$log.error('[AngularJS - Leaflet] A base layer must have an url');
return false;
}
// Check if the layer must have an URL
if (layerTypes[layerDefinition.type].mustHaveUrl && !isString(layerDefinition.url)) {
$log.error('[AngularJS - Leaflet] A base layer must have an url');
return false;
}

if (layerTypes[layerDefinition.type].mustHaveData && !isDefined(layerDefinition.data)) {
$log.error('[AngularJS - Leaflet] The base layer must have a "data" array attribute');
return false;
}
if (layerTypes[layerDefinition.type].mustHaveData && !isDefined(layerDefinition.data)) {
$log.error('[AngularJS - Leaflet] The base layer must have a "data" array attribute');
return false;
}

if (layerTypes[layerDefinition.type].mustHaveLayer && !isDefined(layerDefinition.layer)) {
$log.error('[AngularJS - Leaflet] The type of layer ' + layerDefinition.type + ' must have an layer defined');
return false;
}
if (layerTypes[layerDefinition.type].mustHaveLayer && !isDefined(layerDefinition.layer)) {
$log.error('[AngularJS - Leaflet] The type of layer ' + layerDefinition.type + ' must have an layer defined');
return false;
}

if (layerTypes[layerDefinition.type].mustHaveBounds && !isDefined(layerDefinition.bounds)) {
$log.error('[AngularJS - Leaflet] The type of layer ' + layerDefinition.type + ' must have bounds defined');
return false;
}
if (layerTypes[layerDefinition.type].mustHaveBounds && !isDefined(layerDefinition.bounds)) {
$log.error('[AngularJS - Leaflet] The type of layer ' + layerDefinition.type + ' must have bounds defined');
return false;
}

if (layerTypes[layerDefinition.type].mustHaveKey && !isDefined(layerDefinition.key)) {
$log.error('[AngularJS - Leaflet] The type of layer ' + layerDefinition.type + ' must have key defined');
return false;
if (layerTypes[layerDefinition.type].mustHaveKey && !isDefined(layerDefinition.key)) {
$log.error('[AngularJS - Leaflet] The type of layer ' + layerDefinition.type + ' must have key defined');
return false;
}
} else {
// Type unknown at build time
if (typeof L.tileLayer[layerDefinition.type] !== 'function') {
return false;
}
}

return true;
Expand Down Expand Up @@ -2060,7 +2064,8 @@ angular.module('leaflet-directive')
};

//TODO Add $watch to the layer properties
return layerTypes[layerDefinition.type].createLayer(params);
if (layerTypes[layerDefinition.type]) return layerTypes[layerDefinition.type].createLayer(params);
return L.tileLayer[layerDefinition.type](params.url, params.options);
}

function safeAddLayer(map, layer) {
Expand Down
55 changes: 30 additions & 25 deletions src/services/leafletLayerHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,35 +457,39 @@ angular.module('leaflet-directive')
return false;
}

if (Object.keys(layerTypes).indexOf(layerDefinition.type) === -1) {
$log.error('[AngularJS - Leaflet] A layer must have a valid type: ' + Object.keys(layerTypes));
return false;
}
// One of the known types
if (Object.keys(layerTypes).indexOf(layerDefinition.type) !== -1) {

// Check if the layer must have an URL
if (layerTypes[layerDefinition.type].mustHaveUrl && !isString(layerDefinition.url)) {
$log.error('[AngularJS - Leaflet] A base layer must have an url');
return false;
}
// Check if the layer must have an URL
if (layerTypes[layerDefinition.type].mustHaveUrl && !isString(layerDefinition.url)) {
$log.error('[AngularJS - Leaflet] A base layer must have an url');
return false;
}

if (layerTypes[layerDefinition.type].mustHaveData && !isDefined(layerDefinition.data)) {
$log.error('[AngularJS - Leaflet] The base layer must have a "data" array attribute');
return false;
}
if (layerTypes[layerDefinition.type].mustHaveData && !isDefined(layerDefinition.data)) {
$log.error('[AngularJS - Leaflet] The base layer must have a "data" array attribute');
return false;
}

if (layerTypes[layerDefinition.type].mustHaveLayer && !isDefined(layerDefinition.layer)) {
$log.error('[AngularJS - Leaflet] The type of layer ' + layerDefinition.type + ' must have an layer defined');
return false;
}
if (layerTypes[layerDefinition.type].mustHaveLayer && !isDefined(layerDefinition.layer)) {
$log.error('[AngularJS - Leaflet] The type of layer ' + layerDefinition.type + ' must have an layer defined');
return false;
}

if (layerTypes[layerDefinition.type].mustHaveBounds && !isDefined(layerDefinition.bounds)) {
$log.error('[AngularJS - Leaflet] The type of layer ' + layerDefinition.type + ' must have bounds defined');
return false;
}
if (layerTypes[layerDefinition.type].mustHaveBounds && !isDefined(layerDefinition.bounds)) {
$log.error('[AngularJS - Leaflet] The type of layer ' + layerDefinition.type + ' must have bounds defined');
return false;
}

if (layerTypes[layerDefinition.type].mustHaveKey && !isDefined(layerDefinition.key)) {
$log.error('[AngularJS - Leaflet] The type of layer ' + layerDefinition.type + ' must have key defined');
return false;
if (layerTypes[layerDefinition.type].mustHaveKey && !isDefined(layerDefinition.key)) {
$log.error('[AngularJS - Leaflet] The type of layer ' + layerDefinition.type + ' must have key defined');
return false;
}
} else {
// Type unknown at build time
if (typeof L.tileLayer[layerDefinition.type] !== 'function') {
return false;
}
}

return true;
Expand Down Expand Up @@ -530,7 +534,8 @@ angular.module('leaflet-directive')
};

//TODO Add $watch to the layer properties
return layerTypes[layerDefinition.type].createLayer(params);
if (layerTypes[layerDefinition.type]) return layerTypes[layerDefinition.type].createLayer(params);
return L.tileLayer[layerDefinition.type](params.url, params.options);
}

function safeAddLayer(map, layer) {
Expand Down

0 comments on commit c1bf6cb

Please sign in to comment.