mirror of
https://github.com/publiclab/mapknitter.git
synced 2025-12-11 18:59:59 +01:00
* Configurations update for rails 4.0 * ActiveSupport::Testing::Performance extracted to a gem * ruby prof required as a dependency * disable rubocop on bin folder * http patch * Comment out to allow testing * no longer supports plugin loading * lock to sprockets 2.12 * Active record patches * remove deprecated test syntax * fix failing tests * change new super class * replace right_aws with right_aws_api right_aws is no longer maintained, was throwing an error * lock to rails 4.2.11.1 * change rails version in install script * remove deprecation warnings * Change test lib to minitest, add minitest reporters * make app work * active record find patches * root_in_json include defaulted to false * confirm option removed in link helper * cookies serializer changed to hybrid * Change render :text to :plain render :text will be deprecated and poses a security risk * console for dev web * Check and fix interface functionality * fix export functionality * add protected attributes for the warpable model * fix image upload * Fix comments and images failing tests * include mass assignment security in annotations * render html for update images * clear mail array before every test * Fix codeclimate issues * skip failing test The test is failing because of different names in model(warpable) and controller(images) skipping this for now until we decide if we want to standardize the names * replace unprotected redirects * Fix codeclimate issues * Autofixing rubocop offenses and Problematic test for #578 (#667) * Autofixing rubocop offenses * Adding Rubocop to Travis pipelines and development branch * Fixing maps controller test * Fixing remaining offenses * change post test to create since action new is a get action * remove unprotected redirects * Fix codeclimate issues * Add yarn * Remove error log * Fix oauth icons * Modify package.json * Add yarn install to start.sh * Add leaflet google * Remove leaflet-google from package json * remove passenger error logs * Fix install script * Remove flag * Fix gemfile.lock * Fix gemfile.lock * Fix login * Upgrade Gemfile to Rails 5.0 * require rake' * Change config files * Add application record * Bump mysql * Local builds for Travis runners (#672) * Using local mysql for travis * Fix codeclimate issues * Refactoring yamls * Autofixing rubocop offenses and Problematic test for #578 (#667) * Autofixing rubocop offenses * Adding Rubocop to Travis pipelines and development branch * Fixing maps controller test * Fixing remaining offenses * Fixing unit tests * Adding docker build to travis pipelines * Adding docker build to travis pipelines * Staging builds in travis * fix travis.yml * Upgrading sintax of assets and using required gems * Using updated version of GDAL and installing required dependencies * Enabling cache in between builds * Test yarn for travis * Conditionalize rake db:setup for travis * Add semicolon * Remove comment * modify database.yml * Migrate seperately * Run create only for production * Locking newer Rails v * Running update task * Adding missing bootsnap gem * Fixing missing database * Adding missing listen gem * Fixing schema example version * Fixing migration versions * Updating dependencies for Rails 5 * Adding ApplicationMailer abstraction * Adding required initializers * Prefer require_relative instead of full path * Making associations not required by default * Regenerating schema file * Hotfixing MassAssigment * Upgrade web-console, remove mysql adapter override * Remove attr_accessible * Add rails-controller-testing gem * Follow new syntax for tests * Remove extra web-console from gemfile * Regenerating lock file * Fixing rubocop offenses and bundler version * Using correct Paperclip class as in https://github.com/rails/rails/issues/26404#issuecomment-502129936 * Fix images functional tests * images controller test typecast to string * Fix rails logger * Fix map tests * Bumping rubocop version * Autofixing rubocop offenses * Including performance cop to rubocop * Refactoring deprecated routing and secret_token * Fixing routes for feed controller * Using correct routes for RSS builder * Fixing missing routes * Fixing travis bundler and yarn cache * Fixing bundle path * Splitting bundle and yarn verifications * Autofixing rubocop offenses * Fixing prod host for travis, private class usage and rubocop offenses * Upgrade to Rails 5.2 (#685) * Upgrade Gemfile to Rails 5.0 * require rake' * Change config files * Add application record * Bump mysql * Locking newer Rails v * Running update task * Adding missing bootsnap gem * Fixing missing database * Adding missing listen gem * Fixing schema example version * Fixing migration versions * Updating dependencies for Rails 5 * Adding ApplicationMailer abstraction * Adding required initializers * Prefer require_relative instead of full path * Making associations not required by default * Regenerating schema file * Hotfixing MassAssigment * Upgrade web-console, remove mysql adapter override * Remove attr_accessible * Add rails-controller-testing gem * Follow new syntax for tests * Remove extra web-console from gemfile * Regenerating lock file * Fixing rubocop offenses and bundler version * Using correct Paperclip class as in https://github.com/rails/rails/issues/26404#issuecomment-502129936 * Fix images functional tests * images controller test typecast to string * Fix rails logger * Fix map tests * Bumping rubocop version * Autofixing rubocop offenses * Including performance cop to rubocop * Refactoring deprecated routing and secret_token * Fixing routes for feed controller * Using correct routes for RSS builder * Fixing missing routes * Fixing travis bundler and yarn cache * Fixing bundle path * Splitting bundle and yarn verifications * Fixing prod host for travis, private class usage and rubocop offenses * Enforcing params usage on get method * Using correct folder names to Rails >5 conventions * Enforcing params wrapping and adding missing front_ui route * Precompiling assets before serving * Improving Jenkins startup script * Using supported docker yaml version by Jenkins * Adding task to check database existance * Improving start script * Improving Makefile's recipes and target * Adding task to check database existance * Improving start script * Improving Makefile's recipes and target * Improving Makefile's recipes and target * Patching https://github.com/publiclab/mapknitter/pull/803 * Improving Jenkins setup * Fix map loading * h * Fixing Leaflet-Environmental-Layers map loading * h * leaflet * fix * change * updates * stop precompiling assets * precompile * Using correct Yarn, NPM and Node version, avoiding mismatch * Removing unwanted tags.js invocation * Improving Makefile recipe * Using node_modules/ as dependencies folder, since https://github.com/sass/node-sass/issues/2050#issuecomment-317233552 * Upgrading Yarn dependencies * Removing duplicate rubocop directive * Removing test/ from codeclimate checks * Removing fixed FIXME comments * Removing fixed FIXME comments * Updating docs in README * Bumping recaptcha and include methods * Fixing migration version * Using strong params in requests * Using strong params in requests * Use Rack::Test::UploadedFile instead of ActionDispatch::Http::UploadedFile * Remove rubocop linter * Fix codeclimate issues * Fix minor asset issue * Remove manual asset references and add them to application js * Fix asset ordering in application.js * Configure System tests (#936) * Add new system tests and fix minor asset loading * modify test * Add chromedriver to travis * Add sudo * Add dependencies to dockerfile * Properly installing chrome and chromedriver * Fixing Map loading since merges
201 lines
4.3 KiB
JavaScript
201 lines
4.3 KiB
JavaScript
(function(window) {
|
|
var HAS_HASHCHANGE = (function() {
|
|
var doc_mode = window.documentMode;
|
|
return ('onhashchange' in window) &&
|
|
(doc_mode === undefined || doc_mode > 7);
|
|
})();
|
|
|
|
L.Hash = function(map, options) {
|
|
this.onHashChange = L.Util.bind(this.onHashChange, this);
|
|
|
|
if (map) {
|
|
this.init(map, options);
|
|
}
|
|
};
|
|
|
|
L.Hash.parseHash = function(hash) {
|
|
if(hash.indexOf('#') === 0) {
|
|
hash = hash.substr(1);
|
|
}
|
|
var args = hash.split("/");
|
|
if (args.length == 4) {
|
|
var zoom = parseInt(args[0], 10),
|
|
lat = parseFloat(args[1]),
|
|
lon = parseFloat(args[2]),
|
|
layers = (args[3]).split("-");
|
|
if (isNaN(zoom) || isNaN(lat) || isNaN(lon)) {
|
|
return false;
|
|
} else {
|
|
return {
|
|
center: new L.LatLng(lat, lon),
|
|
zoom: zoom,
|
|
layers: layers
|
|
};
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
L.Hash.formatHash = function(map) {
|
|
var center = map.getCenter(),
|
|
zoom = map.getZoom(),
|
|
precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2)),
|
|
layers = [];
|
|
|
|
//console.log(this.options);
|
|
var options = this.options;
|
|
//Check active layers
|
|
for(var key in options) {
|
|
if (options.hasOwnProperty(key)) {
|
|
if (map.hasLayer(options[key])) {
|
|
layers.push(key);
|
|
};
|
|
};
|
|
};
|
|
|
|
return "#" + [zoom,
|
|
center.lat.toFixed(precision),
|
|
center.lng.toFixed(precision),
|
|
layers.join("-")
|
|
].join("/");
|
|
},
|
|
|
|
L.Hash.prototype = {
|
|
map: null,
|
|
lastHash: null,
|
|
|
|
parseHash: L.Hash.parseHash,
|
|
formatHash: L.Hash.formatHash,
|
|
|
|
init: function(map, options) {
|
|
this.map = map;
|
|
L.Util.setOptions(this, options);
|
|
|
|
// reset the hash
|
|
this.lastHash = null;
|
|
this.onHashChange();
|
|
|
|
if (!this.isListening) {
|
|
this.startListening();
|
|
}
|
|
},
|
|
|
|
removeFrom: function(map) {
|
|
if (this.changeTimeout) {
|
|
clearTimeout(this.changeTimeout);
|
|
}
|
|
|
|
if (this.isListening) {
|
|
this.stopListening();
|
|
}
|
|
|
|
this.map = null;
|
|
},
|
|
|
|
onMapMove: function() {
|
|
// bail if we're moving the map (updating from a hash),
|
|
// or if the map is not yet loaded
|
|
|
|
if (this.movingMap || !this.map._loaded) {
|
|
return false;
|
|
}
|
|
|
|
var hash = this.formatHash(this.map);
|
|
if (this.lastHash != hash) {
|
|
location.replace(hash);
|
|
this.lastHash = hash;
|
|
}
|
|
},
|
|
|
|
movingMap: false,
|
|
update: function() {
|
|
var hash = location.hash;
|
|
if (hash === this.lastHash) {
|
|
return;
|
|
}
|
|
var parsed = this.parseHash(hash);
|
|
if (parsed) {
|
|
this.movingMap = true;
|
|
|
|
this.map.setView(parsed.center, parsed.zoom);
|
|
var layers = parsed.layers,
|
|
options = this.options,
|
|
that = this;
|
|
//Add/remove layers
|
|
this.map.eachLayer(function(layer) {
|
|
that.map.removeLayer(layer);
|
|
});
|
|
|
|
layers.forEach(function(element, index, array) {
|
|
//console.log(options[element]);
|
|
that.map.addLayer(options[element]);
|
|
});
|
|
|
|
this.movingMap = false;
|
|
} else {
|
|
this.onMapMove(this.map);
|
|
}
|
|
},
|
|
|
|
// defer hash change updates every 100ms
|
|
changeDefer: 100,
|
|
changeTimeout: null,
|
|
onHashChange: function() {
|
|
// throttle calls to update() so that they only happen every
|
|
// `changeDefer` ms
|
|
if (!this.changeTimeout) {
|
|
var that = this;
|
|
this.changeTimeout = setTimeout(function() {
|
|
that.update();
|
|
that.changeTimeout = null;
|
|
}, this.changeDefer);
|
|
}
|
|
},
|
|
|
|
isListening: false,
|
|
hashChangeInterval: null,
|
|
startListening: function() {
|
|
this.map.on("moveend layeradd layerremove", this.onMapMove, this);
|
|
|
|
if (HAS_HASHCHANGE) {
|
|
L.DomEvent.addListener(window, "hashchange", this.onHashChange);
|
|
} else {
|
|
clearInterval(this.hashChangeInterval);
|
|
this.hashChangeInterval = setInterval(this.onHashChange, 50);
|
|
}
|
|
this.isListening = true;
|
|
},
|
|
|
|
stopListening: function() {
|
|
this.map.off("moveend layeradd layerremove", this.onMapMove, this);
|
|
|
|
if (HAS_HASHCHANGE) {
|
|
L.DomEvent.removeListener(window, "hashchange", this.onHashChange);
|
|
} else {
|
|
clearInterval(this.hashChangeInterval);
|
|
}
|
|
this.isListening = false;
|
|
},
|
|
|
|
_keyByValue: function(obj, value) {
|
|
for(var key in obj) {
|
|
if (obj.hasOwnProperty(key)) {
|
|
if (obj[key] === value) {
|
|
return key;
|
|
} else { return null; };
|
|
};
|
|
};
|
|
}
|
|
};
|
|
L.hash = function(map, options) {
|
|
return new L.Hash(map, options);
|
|
};
|
|
L.Map.prototype.addHash = function() {
|
|
this._hash = L.hash(this, this.options);
|
|
};
|
|
L.Map.prototype.removeHash = function() {
|
|
this._hash.removeFrom();
|
|
};
|
|
})(window);
|