Skip to content

Commit

Permalink
[DEMAD-381] Desarrollo de funcionalidades
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Javier Moreno Hernández committed Jul 1, 2022
1 parent 3bb864a commit ade9083
Show file tree
Hide file tree
Showing 12 changed files with 5,792 additions and 31 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ gem "chartkick"
gem 'caracal'
gem 'caxlsx'
gem 'caxlsx_rails'
gem 'leaflet-rails'

source "http://insecure.rails-assets.org" do
gem "rails-assets-leaflet"
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ GEM
kramdown (1.17.0)
launchy (2.4.3)
addressable (~> 2.3)
leaflet-rails (1.7.0)
rails (>= 4.2.0)
letter_opener (1.7.0)
launchy (~> 2.2)
letter_opener_web (1.3.4)
Expand Down Expand Up @@ -631,6 +633,7 @@ DEPENDENCIES
kaminari (~> 1.1.1)
knapsack_pro (~> 1.1.0)
launchy (~> 2.4.3)
leaflet-rails
letter_opener
letter_opener_web (~> 1.3.4)
mdl (~> 0.5.0)
Expand Down
158 changes: 158 additions & 0 deletions app/assets/javascripts/leaflet.fullscreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
L.Control.FullScreen = L.Control.extend({
options: {
position: 'topleft',
title: 'Full Screen',
forceSeparateButton: false
},

onAdd: function (map) {
// Do nothing if we can't
if (!fullScreenApi.supportsFullScreen)
return map.zoomControl ? map.zoomControl._container : L.DomUtil.create('div', '');

var className = 'leaflet-control-zoom-fullscreen', container;

if(map.zoomControl && !this.options.forceSeparateButton) {
container = map.zoomControl._container;
} else {
container = L.DomUtil.create('div', 'leaflet-bar');
}

this._createButton(this.options.title, className, container, this.toogleFullScreen, map);

return container;
},

_createButton: function (title, className, container, fn, context) {
var link = L.DomUtil.create('a', className, container);
link.href = '#';
link.title = title;

L.DomEvent
.addListener(link, 'click', L.DomEvent.stopPropagation)
.addListener(link, 'click', L.DomEvent.preventDefault)
.addListener(link, 'click', fn, context);

L.DomEvent
.addListener(container, fullScreenApi.fullScreenEventName, L.DomEvent.stopPropagation)
.addListener(container, fullScreenApi.fullScreenEventName, L.DomEvent.preventDefault)
.addListener(container, fullScreenApi.fullScreenEventName, this._handleEscKey, context);

L.DomEvent
.addListener(document, fullScreenApi.fullScreenEventName, L.DomEvent.stopPropagation)
.addListener(document, fullScreenApi.fullScreenEventName, L.DomEvent.preventDefault)
.addListener(document, fullScreenApi.fullScreenEventName, this._handleEscKey, context);

return link;
},

toogleFullScreen: function () {
this._exitFired = false;
if (fullScreenApi.supportsFullScreen){
var container = this._container;
if(fullScreenApi.isFullScreen(container)){
fullScreenApi.cancelFullScreen(container);
this.invalidateSize();
this.fire('exitFullscreen');
this._exitFired = true;
}
else {
fullScreenApi.requestFullScreen(container);
this.invalidateSize();
this.fire('enterFullscreen');
}
}
},

_handleEscKey: function () {
if(!fullScreenApi.isFullScreen(this) && !this._exitFired){
this.fire('exitFullscreen');
this._exitFired = true;
}
}
});

L.Map.addInitHook(function () {
if (this.options.fullscreenControl) {
this.fullscreenControl = L.control.fullscreen(this.options.fullscreenControlOptions);
this.addControl(this.fullscreenControl);
}
});

L.control.fullscreen = function (options) {
return new L.Control.FullScreen(options);
};

/*
Native FullScreen JavaScript API
-------------
Assumes Mozilla naming conventions instead of W3C for now
source : http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/
*/

(function() {
var
fullScreenApi = {
supportsFullScreen: false,
isFullScreen: function() { return false; },
requestFullScreen: function() {},
cancelFullScreen: function() {},
fullScreenEventName: '',
prefix: ''
},
browserPrefixes = 'webkit moz o ms khtml'.split(' ');

// check for native support
if (typeof document.exitFullscreen != 'undefined') {
fullScreenApi.supportsFullScreen = true;
} else {
// check for fullscreen support by vendor prefix
for (var i = 0, il = browserPrefixes.length; i < il; i++ ) {
fullScreenApi.prefix = browserPrefixes[i];

if (typeof document[fullScreenApi.prefix + 'CancelFullScreen' ] != 'undefined' ) {
fullScreenApi.supportsFullScreen = true;

break;
}
}
}

// update methods to do something useful
if (fullScreenApi.supportsFullScreen) {
fullScreenApi.fullScreenEventName = fullScreenApi.prefix + 'fullscreenchange';

fullScreenApi.isFullScreen = function() {
switch (this.prefix) {
case '':
return document.fullScreen;
case 'webkit':
return document.webkitIsFullScreen;
default:
return document[this.prefix + 'FullScreen'];
}
}
fullScreenApi.requestFullScreen = function(el) {
return (this.prefix === '') ? el.requestFullscreen() : el[this.prefix + 'RequestFullScreen']();
}
fullScreenApi.cancelFullScreen = function(el) {
return (this.prefix === '') ? document.exitFullscreen() : document[this.prefix + 'CancelFullScreen']();
}
}

// jQuery plugin
if (typeof jQuery != 'undefined') {
jQuery.fn.requestFullScreen = function() {

return this.each(function() {
var el = jQuery(this);
if (fullScreenApi.supportsFullScreen) {
fullScreenApi.requestFullScreen(el);
}
});
};
}

// export api
window.fullScreenApi = fullScreenApi;
})();
62 changes: 62 additions & 0 deletions app/assets/javascripts/map.js.coffee

Large diffs are not rendered by default.

0 comments on commit ade9083

Please sign in to comment.