[tarent-useful-scripts SCM] {mirkarte} branch master updated. a08de508780e7dbe9c4959294461cb969148b5ee

mirabilos at evolvis.org mirabilos at evolvis.org
Fri Nov 3 16:21:07 CET 2017 • <20171103152107.087C14A019A@evolvis.org>


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "MirKarte source code repository".

The branch, master has been updated
       via  a08de508780e7dbe9c4959294461cb969148b5ee (commit)
       via  e966e79548aa78cd862b845a6ef74e923a87fe6e (commit)
       via  d8e898d8023e299c7e7366116bd0a99a89d1a2fd (commit)
      from  c14329c2710b6ad360d6e86b91704e8791fa2b20 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit a08de508780e7dbe9c4959294461cb969148b5ee
Author: mirabilos <t.glaser at tarent.de>
Date:   Fri Nov 3 16:20:50 2017 +0100

    integrate compass

commit e966e79548aa78cd862b845a6ef74e923a87fe6e
Author: mirabilos <t.glaser at tarent.de>
Date:   Fri Nov 3 16:20:11 2017 +0100

    add leaflet-compass
    
    commit e0ca0e9920fcd8e14479f004da11f76aa7d10339
    from git at github.com:stefanocudini/leaflet-compass.git

commit d8e898d8023e299c7e7366116bd0a99a89d1a2fd
Author: mirabilos <t.glaser at tarent.de>
Date:   Fri Nov 3 16:19:43 2017 +0100

    mobile-friendlier (from Tutorial)

-----------------------------------------------------------------------

Summary of changes:
 img/compass-icon.png                | Bin 0 -> 1760 bytes
 index.htm                           |   8 ++
 leaflet-compass/leaflet-compass.css |  47 +++++++++
 leaflet-compass/leaflet-compass.js  | 188 ++++++++++++++++++++++++++++++++++++
 4 files changed, 243 insertions(+)
 create mode 100644 img/compass-icon.png
 create mode 100644 leaflet-compass/leaflet-compass.css
 create mode 100644 leaflet-compass/leaflet-compass.js

diff --git a/img/compass-icon.png b/img/compass-icon.png
new file mode 100644
index 0000000..0962c47
Binary files /dev/null and b/img/compass-icon.png differ
diff --git a/index.htm b/index.htm
index 96a34c7..096d056 100644
--- a/index.htm
+++ b/index.htm
@@ -3,8 +3,10 @@
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <meta name="copyright" content="see mirkarte.js" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  <title>MirKarte (Beta)</title>
  <link rel="stylesheet" type="text/css" href="leaflet/leaflet.css" />
+ <link rel="stylesheet" type="text/css" href="leaflet-compass/leaflet-compass.css" />
  <style type="text/css"><!--/*--><![CDATA[/*><!--*/
   #nomap {
 	padding:12px;
@@ -43,12 +45,18 @@
   }
  /*]]>*/--></style>
  <script type="text/javascript" src="leaflet/leaflet-src.js"></script>
+ <script type="text/javascript" src="leaflet-compass/leaflet-compass.js"></script>
  <script type="text/javascript" src="prototype/prototype.js"></script>
  <script type="text/javascript" src="togeojson/togeojson.js"></script>
  <script type="text/javascript" src="zip.js/WebContent/zip.js"></script>
  <script type="text/javascript"><!--//--><![CDATA[//><!--
   zip.workerScriptsPath = "zip.js/WebContent/";
   mirkarte_default_loc = [50.7, 7.11, 12];
+  mirkarte_hookfn = function (map) {
+	var compass = new L.Control.Compass();
+	map.addControl(compass);
+	compass.activate();
+  };
  //--><!]]></script>
  <script type="text/javascript" src="mirkarte.js"></script>
 </head><body>
diff --git a/leaflet-compass/leaflet-compass.css b/leaflet-compass/leaflet-compass.css
new file mode 100644
index 0000000..08ed0e4
--- /dev/null
+++ b/leaflet-compass/leaflet-compass.css
@@ -0,0 +1,47 @@
+
+.leaflet-control.leaflet-compass {
+	position:relative;
+	float:left;
+	color:#1978cf;
+	-moz-border-radius: 4px;
+	-webkit-border-radius: 4px;
+	border-radius: 4px;
+	/*background-color: rgba(0, 0, 0, 0.25);*/
+	background-color: rgba(255, 255, 255, 0.8);
+	/*background: none;*/
+	box-shadow: 0 1px 7px rgba(0,0,0,0.65);
+	margin-left:10px;
+	margin-top:10px;
+}
+.leaflet-compass .compass-button {
+	display:block;
+	float:left;
+	width:36px;
+	height:36px;
+	border-radius:4px;
+}
+.leaflet-compass .compass-button.active {
+	background: #fff;
+}
+.leaflet-compass .compass-icon {
+	height: 32px;
+	width: 32px;
+	margin: 2px;
+	background: url('../img/compass-icon.png') center center no-repeat;
+}
+
+.leaflet-compass .compass-digit {
+}
+
+.leaflet-compass .compass-alert {
+	position:absolute;
+	left:26px;
+	bottom:-1px;
+	width:100px;
+	padding:2px;
+	line-height:.95em;
+	color:#e00;
+	border: 1px solid #888;	
+	background-color: rgba(255, 255, 255, 0.75);
+	border-radius:4px;
+}
diff --git a/leaflet-compass/leaflet-compass.js b/leaflet-compass/leaflet-compass.js
new file mode 100644
index 0000000..7925794
--- /dev/null
+++ b/leaflet-compass/leaflet-compass.js
@@ -0,0 +1,188 @@
+// Stefano Cudini <stefano.cudini at gmail.com> • MIT Licence
+
+(function (factory) {
+    if(typeof define === 'function' && define.amd) {
+    //AMD
+        define(['leaflet'], factory);
+    } else if(typeof module !== 'undefined') {
+    // Node/CommonJS
+        module.exports = factory(require('leaflet'));
+    } else {
+    // Browser globals
+        if(typeof window.L === 'undefined')
+            throw 'Leaflet must be loaded first';
+        factory(window.L);
+    }
+})(function (L) {
+
+L.Control.Compass = L.Control.extend({
+
+	includes: L.Mixin.Events, 
+	//
+	//Managed Events:
+	//	Event				Data passed		Description
+	//
+	//	compass:rotated		{angle}			fired after compass data is rotated
+	//	compass:disabled					fired when compass is disabled
+	//
+	//Methods exposed:
+	//	Method 			Description
+	//
+	//  getAngle		return Azimut angle
+	//  setAngle		set rotation compass
+	//  activate		active tracking on runtime
+	//  deactivate		deactive tracking on runtime
+	//
+	options: {
+		position: 'topright',	//position of control inside map
+		autoActive: false,		//activate control at startup
+		showDigit: true,		//show angle value bottom compass
+		textErr: null,			//error message on alert notification
+		callErr: null,			//function that run on compass error activating
+		angleOffset: 2			//min angle deviation before rotate
+		/* big angleOffset is need for device have noise in orientation sensor */
+	},
+
+	initialize: function(options) {
+		if(options && options.style)
+			options.style = L.Util.extend({}, this.options.style, options.style); 
+		L.Util.setOptions(this, options);
+		this._errorFunc = this.options.callErr || this.showAlert;
+		this._isActive = false;//global state of compass
+		this._currentAngle = null;	//store last angle
+	},
+
+	onAdd: function (map) {
+
+		var self = this;
+
+		this._map = map;	
+			
+		var container = L.DomUtil.create('div', 'leaflet-compass');
+
+		this._button = L.DomUtil.create('span', 'compass-button', container);
+		this._button.href = '#';
+
+		this._icon = L.DomUtil.create('div', 'compass-icon', this._button);
+		this._digit = L.DomUtil.create('span', 'compass-digit', this._button);
+
+		this._alert = L.DomUtil.create('div', 'compass-alert', container);
+		this._alert.style.display = 'none';
+
+		L.DomEvent
+			.on(this._button, 'click', L.DomEvent.stop, this)
+			.on(this._button, 'click', this._switchCompass, this);
+
+		L.DomEvent.on(window, 'compassneedscalibration', function(e) {
+			self.showAlert('Your compass needs calibrating! Wave your device in a figure-eight motion');
+		}, this);
+
+		if(this.options.autoActive)
+			this.activate();
+
+		return container;
+	},
+
+	onRemove: function(map) {
+		
+		this.deactivate();
+		
+		L.DomEvent
+			.off(this._button, 'click', L.DomEvent.stop, this)
+			.off(this._button, 'click', this._switchCompass, this);
+	},
+
+	_switchCompass: function() {
+		if(this._isActive)
+			this.deactivate();
+		else
+			this.activate();
+	},
+
+	_rotateHandler: function(e) {
+
+		var self = this, angle;
+
+		if(!this._isActive) return false;
+
+		if(e.webkitCompassHeading)	//iphone
+			angle = 360 - e.webkitCompassHeading;
+
+		else if(e.alpha)			//android
+			angle = e.alpha;
+		else {
+			this._errorCompass({message: 'Orientation angle not found'});
+		}
+		
+		angle = Math.round(angle);
+
+		if(angle % this.options.angleOffset === 0)
+			self.setAngle(angle);
+	},
+
+	_errorCompass: function(e) {
+		this.deactivate();
+		this._errorFunc.call(this, this.options.textErr || e.message);
+	},
+
+	_rotateElement: function(el) {
+		el.style.webkitTransform = "rotate("+ this._currentAngle +"deg)";
+		el.style.MozTransform = "rotate("+ this._currentAngle +"deg)";
+		el.style.transform = "rotate("+ this._currentAngle +"deg)";
+	},
+
+	setAngle: function(angle) {
+		
+		if(this.options.showDigit && !isNaN(parseFloat(angle)) && isFinite(angle))
+			this._digit.innerHTML = angle+'°';
+
+		this._currentAngle = angle;
+		this._rotateElement( this._icon );
+
+		this.fire('compass:rotated', {angle: angle});
+	},
+	
+	getAngle: function() {	//get last angle
+		return this._currentAngle;
+	},
+
+	activate: function() {
+
+		this._isActive = true;
+
+		L.DomEvent.on(window, 'deviceorientation', this._rotateHandler, this);
+		
+		L.DomUtil.addClass(this._button, 'active');
+	},
+
+	deactivate: function() {
+		
+		this.setAngle(0);
+
+		this._isActive = false;
+
+		L.DomEvent.off(window, 'deviceorientation', this._rotateHandler, this);
+
+		L.DomUtil.removeClass(this._button, 'active');
+
+		this.fire('compass:disabled');
+	},
+
+	showAlert: function(text) {
+		this._alert.style.display = 'block';
+		this._alert.innerHTML = text;
+		var that = this;
+		clearTimeout(this.timerAlert);
+		this.timerAlert = setTimeout(function() {
+			that._alert.style.display = 'none';
+		}, 5000);
+	}
+});
+
+L.control.compass = function (options) {
+	return new L.Control.Compass(options);
+};
+
+return L.Control.Compass;
+
+});
\ No newline at end of file


hooks/post-receive
-- 
MirKarte source code repository
(Evolvis project useful-scripts repository mirkarte)


More information about the useful-scripts-commits mailing list