Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made domain name a settable domain name option #307

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.js
Expand Up @@ -25,6 +25,7 @@ module.exports = {
"indent": ["error", 2],
"camelcase": 0,
"no-unused-vars": ["warn", { "vars": "local", "args": "none" }],
"require-jsdoc": 0
"require-jsdoc": 0,
"linebreak-style": 0
},
};
6 changes: 4 additions & 2 deletions example/layers.js
Expand Up @@ -229,9 +229,11 @@ var allMapLayers = {
// });

var hash = new L.FullHash(map, allMapLayers);
var leafletControl = new L.control.layers(baseMaps,overlayMaps);
var leafletControl = new L.control.layers(baseMaps, overlayMaps);
leafletControl.addTo(map);

var embedControl = new L.control.embed();
var embedControl = new L.control.embed({
// hostname: 'your domain name goes here'
});
embedControl.addTo(map);

3 changes: 2 additions & 1 deletion example/oneLinerCodeExample.html
Expand Up @@ -81,7 +81,8 @@
include: ['odorreport', 'asian', 'clouds', 'eonetFiresLayer', 'Unearthing'],
// exclude: ['mapknitter', 'clouds'],
hash: true,
embed: true
embed: true,
// hostname: 'domain name goes here'
}).addTo(map);

</script>
Expand Down
3 changes: 2 additions & 1 deletion example/unearthing-pvd.html
Expand Up @@ -78,7 +78,8 @@
include: ['asian', 'clouds', 'Unearthing'],
// exclude: ['mapknitter', 'clouds'],
hash: true,
embed: true
embed: true,
// hostname: 'domain name goes here'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome!

}).addTo(map);

</script>
Expand Down
27 changes: 17 additions & 10 deletions src/AllLayers.js
Expand Up @@ -38,9 +38,9 @@ L.LayerGroup.environmentalLayers = L.LayerGroup.extend(
if (!!param.hash) {
this.options.hash = param.hash;
}
if(!!param.baseLayers) {
this.options.baseLayers = param.baseLayers;
}
if (!!param.baseLayers) {
this.options.baseLayers = param.baseLayers;
}
param.all = [...this.options.layers0, ...this.options.layers1, ...this.options.layers2, ...this.options.layers3, ...this.options.layers4, ...this.options.layers5, ...this.options.layers6];
if (!param.include || !param.include.length) {
param.include = param.all;
Expand All @@ -56,6 +56,9 @@ L.LayerGroup.environmentalLayers = L.LayerGroup.extend(
if (!!param.embed) {
this.options.embed = param.embed;
}
if (!!param.hostname) {
this.options.hostname = param.hostname;
}
},

onAdd: function(map) {
Expand Down Expand Up @@ -111,18 +114,22 @@ L.LayerGroup.environmentalLayers = L.LayerGroup.extend(
}
}

if(this.options.embed) {
L.control.embed().addTo(map);
if (this.options.embed) {
this.options.hostname ? (
L.control.embed({
hostname: this.options.hostname,
}).addTo(map)
) : L.control.embed().addTo(map);
}
L.control.layers(baseMaps,this.overlayMaps).addTo(map);

L.control.layers(baseMaps, this.overlayMaps).addTo(map);

var allMaps = Object.assign(baseMaps, this.overlayMaps);
if(this.options.hash) {
var hash = new L.FullHash(map,allMaps);
if (this.options.hash) {
var hash = new L.FullHash(map, allMaps);
// Update map state from hash
hash.update(this.options.currentHash);
}
}
},

onRemove: function(map) {},
Expand Down
90 changes: 46 additions & 44 deletions src/util/embedControl.js
@@ -1,48 +1,50 @@
L.Control.Embed = L.Control.extend({

options: {
position: 'topleft',
},

initialize: function(options) {
L.Util.setOptions(this, options);
this._embedElement = L.DomUtil.create('div');
this._embedElement.classList.add('leaflet-control-embed', 'leaflet-bar', 'leaflet-control')
this._embedAnchorElement = L.DomUtil.create('a');
this._embedAnchorElement.classList.add('leaflet-control-embed-link');
this._embedAnchorElement.setAttribute('href', '#');
this._embedAnchorElement.setAttribute('onclick', 'return false'); // To prevent the removal of url hash
this._embedAnchorElement.setAttribute('title', 'embed');
this._embedAnchorElement.setAttribute('role', 'button');
this._embedAnchorElement.setAttribute('aria-labelledby', 'embed');
this._embedElement.appendChild(this._embedAnchorElement);
this._embedIconElement = L.DomUtil.create('i', 'fas fa-code');
this._embedAnchorElement.appendChild(this._embedIconElement);
this.onClick();
},

onAdd: function(map) {
return this._embedElement;
},

onClick: function() {
var self = this;
L.DomEvent.on(this._embedElement, 'click', function(ev) {
prompt('Use this HTML code to embed this map on another site.', self.generateCode());
})
},

generateCode: function() {
var currentHash = window.location.hash;
var path = window.location.pathname;
var code = '<iframe style="border:none;" width="100%" height="900px" src="//publiclab.github.io/leaflet-environmental-layers' + path + currentHash +'"></iframe>';
return code;
},

onRemove: function(map) {}

})
options: {
position: 'topleft',
hostname: 'publiclab.github.io',
},

initialize: function(options) {
L.Util.setOptions(this, options);
this._embedElement = L.DomUtil.create('div');
this._embedElement.classList.add('leaflet-control-embed', 'leaflet-bar', 'leaflet-control');
this._embedAnchorElement = L.DomUtil.create('a');
this._embedAnchorElement.classList.add('leaflet-control-embed-link');
this._embedAnchorElement.setAttribute('href', '#');
this._embedAnchorElement.setAttribute('onclick', 'return false'); // To prevent the removal of url hash
this._embedAnchorElement.setAttribute('title', 'embed');
this._embedAnchorElement.setAttribute('role', 'button');
this._embedAnchorElement.setAttribute('aria-labelledby', 'embed');
this._embedElement.appendChild(this._embedAnchorElement);
this._embedIconElement = L.DomUtil.create('i', 'fas fa-code');
this._embedAnchorElement.appendChild(this._embedIconElement);
this.onClick();
},

onAdd: function(map) {
return this._embedElement;
},

onClick: function() {
var self = this;
L.DomEvent.on(this._embedElement, 'click', function(ev) {
prompt('Use this HTML code to embed this map on another site.', self.generateCode());
});
},

generateCode: function() {
var currentHash = window.location.hash;
var path = window.location.pathname;
var hostname = this.options.hostname;
var code = '<iframe style="border:none;" width="100%" height="900px" src="//' + hostname + '/leaflet-environmental-layers' + path + currentHash +'"></iframe>';
return code;
},

onRemove: function(map) {},

});

L.control.embed = function(options) {
return new L.Control.Embed(options);
}
return new L.Control.Embed(options);
};