-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #77: pluggable leaflet layers support
- Loading branch information
Showing
7 changed files
with
87 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Copyright 2015, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
var Layers = require('../../../utils/leaflet/Layers'); | ||
var L = require('leaflet'); | ||
|
||
Layers.registerType('osm', () => { | ||
return L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { | ||
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright 2015, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
var Layers = require('../../../utils/leaflet/Layers'); | ||
var L = require('leaflet'); | ||
var objectAssign = require('object-assign'); | ||
|
||
function wmsToLeafletOptions(options) { | ||
var opacity = options.opacity !== undefined ? options.opacity : 1; | ||
// NOTE: can we use opacity to manage visibility? | ||
return objectAssign({ | ||
layers: options.name, | ||
styles: options.style || "", | ||
format: options.format || 'image/png', | ||
transparent: options.transparent !== undefined ? options.transparent : true, | ||
opacity: opacity | ||
}, options.params || {}); | ||
} | ||
|
||
function getWMSURL( url ) { | ||
return url.split("\?")[0]; | ||
} | ||
|
||
Layers.registerType('wms', (options) => { | ||
return L.tileLayer.wms( | ||
getWMSURL(options.url), | ||
wmsToLeafletOptions(options)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright 2015, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const layerTypes = {}; | ||
|
||
var Layers = { | ||
|
||
registerType: function(type, impl) { | ||
layerTypes[type] = impl; | ||
}, | ||
|
||
createLayer: function(type, options) { | ||
var layerCreator = layerTypes[type]; | ||
if (layerCreator) { | ||
return layerCreator(options); | ||
} | ||
return null; | ||
} | ||
}; | ||
|
||
module.exports = Layers; |