From f29f5038591f287c366a052c4b52c0eea6f6f1b8 Mon Sep 17 00:00:00 2001 From: sylvain brissy Date: Fri, 8 Sep 2017 12:29:55 +0200 Subject: [PATCH] first build --- .gitignore | 1 + dist/L.SpeechBubble.js | 1 + gulpfile.js | 7 ++++--- package.json | 19 +++++++++++-------- 4 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 .gitignore create mode 100644 dist/L.SpeechBubble.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..07e6e47 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/node_modules diff --git a/dist/L.SpeechBubble.js b/dist/L.SpeechBubble.js new file mode 100644 index 0000000..cc38f64 --- /dev/null +++ b/dist/L.SpeechBubble.js @@ -0,0 +1 @@ +"use strict";!function(t,e){"function"==typeof define&&define.amd?define(["leaflet"],t):"object"==typeof exports&&(module.exports=t(require("leaflet"))),void 0!==e&&e.L&&(e.L.YourPlugin=t(L))}(function(t){return t.speechBubble=function(e,i){return e?new t.SpeechBubble(e,i):new t.SpeechBubble(null,i)},t.SpeechBubble=t.DivOverlay.extend({includes:t.Mixin.Events,options:{width:null,height:null,top:null,left:null,strenth:200,base:30,angle:0,background:"#FFF",borderThick:2,borderColor:"#000",borderRadius:10},_toLatLng:function(e,i,s){return e instanceof t.LatLng?e:t.Util.isArray(e)&&"object"!=typeof e[0]?3===e.length?new t.LatLng(e[0],e[1],e[2]):2===e.length?new t.LatLng(e[0],e[1]):null:void 0===e||null===e?e:"object"==typeof e&&"lat"in e?new t.LatLng(e.lat,"lng"in e?e.lng:e.lon,e.alt):"object"==typeof e&&"getLatLng"in e?e.getLatLng():void 0===i?null:new t.LatLng(e,i,s)},initialize:function(e,i){e&&t.setOptions(this,e),this._source=i,this.turn=0,this._div=t.DomUtil.create("div","leaflet-speechbubble",this._container),this._curs=t.DomUtil.create("div","leaflet-speechbubble-curs",this._div),this._arrow=t.DomUtil.create("div","leaflet-speechbubble-arrow",this._curs),this._arrow_back=t.DomUtil.create("div","leaflet-speechbubble-arrow-back",this._arrow),this._divcontent=t.DomUtil.create("div","leaflet-speechbubble-content",this._div),this._latlng=this._toLatLng(i)},className:"leaflet-speechbubble",setClassName:function(t){t&&"string"==typeof t&&(this.className=t,this._div.className=this.className)},addClass:function(t){t&&"string"==typeof t&&this._div.classList.add(t)},removeClass:function(t){t&&"string"==typeof t&&this._div.classList.contains(t)&&this._div.classList.remove(t)},_setDefaultDim:function(){var t=this._container.clientWidth/2,e=this._container.clientHeight/2;this.options.height||(this.options.height=2*this._container.clientHeight/4),this.options.width||(this.options.width=2*this._container.clientWidth/4),this.options.top||(this.options.top=e-this.options.height/2),this.options.left||(this.options.left=t-this.options.width/2)},update:function(){if(this._map){console.log("update"),this._setDefaultDim();var e=this._map.getCenter(),i=this._latlng.lng-e.lng,s=this._latlng.lat-e.lat;this.options.angle=180*Math.atan2(s,i)/Math.PI,console.log(this.options.angle),this._divcontent.innerHTML=this._content;var o=this._getLineLengthInRect(this.options.angle,this.options.width,this.options.height),n=this._deg2rad(this.options.angle%360);this._div.style.height=this.options.height+"px",this._div.style.background=this.options.borderColor,this._div.style.width=this.options.width+"px",this._div.style.top=this.options.top+"px",this._div.style.zIndex=1e4,this._div.style.left=this.options.left+"px",this._div.style.borderRadius=this.options.borderRadius+"px",this._div.style.position="absolute";var h=Math.cos(-n)*o+this.options.width/2,a=Math.sin(-n)*o+this.options.height/2,r=t.point(h+this.options.left,a+this.options.top);this._offsetCenter=this._map.containerPointToLatLng(r);var i=this._latlng.lng-this._offsetCenter.lng,s=this._latlng.lat-this._offsetCenter.lat;this.options.angle=180*Math.atan2(s,i)/Math.PI,this.options.angle%360-this.options.lastAngle>180&&this.turn--,this.options.lastAngle-this.options.angle%360>180&&this.turn++,this.options.lastAngle=this.options.angle,this.options.angle=360*this.turn+this.options.angle,this._curs.style.position="absolute",this._curs.style.top=a+"px",this._curs.style.left=h+"px",this._curs.style.transform="rotate("+-1*this.options.angle+"deg) ",this._arrow.style.position="absolute",this._arrow.style.border=this.options.base+"px solid transparent",this._arrow.style.borderRight="none",this._arrow.style.borderLeft=this.options.strenth+"px solid "+this.options.borderColor,this._arrow.style.transform="translate(-"+this.options.base+"px,-50%)",this._arrow.style.borderBottomLeftRadius=this.options.base+"px",this._arrow.style.borderTopLeftRadius=this.options.base+"px",this._arrow_back.style.position="absolute",this._arrow_back.style.border=this.options.base+"px solid transparent",this._arrow_back.style.borderRight="none",this._arrow_back.style.borderLeft=this.options.strenth+"px solid "+this.options.background;var l=5*this.options.borderThick;this._arrow_back.style.transform="translate("+(-this.options.strenth-l)+"px,-"+this.options.base+"px)",this._arrow_back.style.borderBottomLeftRadius=this.options.base+"px",this._arrow_back.style.borderTopLeftRadius=this.options.base+"px",this._divcontent.style.position="absolute",this._divcontent.style.top=this.options.borderThick+"px",this._divcontent.style.left=this.options.borderThick+"px",this._divcontent.style.right=this.options.borderThick+"px",this._divcontent.style.bottom=this.options.borderThick+"px",this._divcontent.style.background=this.options.background,this._divcontent.style.borderRadius=this.options.borderRadius-this.options.borderThick+"px"}},remove:function(t){return this.onRemove(this._map,t),this},onAdd:function(t){this._map=t,this._container=t.getContainer(),t.getContainer().appendChild(this._div),t.speechbubble=this,t.on("move ",function(){this.speechbubble.update()}),t.on("zoom ",function(){this.speechbubble.update()})},addTo:function(t){return this.onAdd(t),this},onRemove:function(t,e){this.timer&&clearInterval(this.timer),t.getContainer().removeChild(this._div),this._map=null},_setStrenth:function(t){this.options.strenth=t,this.update()},_setAngle:function(t){this.options.deg=t,this.update()},_deg2rad:function(t){return 2*t*Math.PI/360},_rad2deg:function(t){return 180*t/Math.PI},_getLineLengthInRect:function(t,e,i){t%=360;var s=Math.abs(this._deg2rad(t)),o=e/2,n=i/2,h=Math.atan(n/o);if(s>=h&&s<=Math.PI-h||s>=Math.PI+h&&s<=2*Math.PI-h)e=Math.abs(n/Math.sin(s));else var e=Math.abs(o/Math.cos(s));return e}}),t.Layer.include({bindSpeechBubble:function(e,i){return e instanceof t.SpeechBubble?(setOptions(e,i),this._speechbubble=e,e._source=this):(this._speechbubble&&!i||(this._speechbubble=new t.SpeechBubble(i,this)),this._speechbubble.setContent(e)),this},openSpeechBubble:function(e,i){if(e instanceof t.Layer||(i=e,e=this),e instanceof t.FeatureGroup)for(var s in this._layers){e=this._layers[s];break}return i||(i=e.getCenter?e.getCenter():e.getLatLng()),this._speechbubble&&this._map&&(this._speechbubble._source=e,this._speechbubble.update(),this._map.openSpeechBubble(this._speechbubble,i)),this}}),t.Map.include({openSpeechBubble:function(e,i,s){return e instanceof t.SpeechBubble||(e=new t.SpeechBubble(s).setContent(e)),i&&e.setLatLng(i),this.hasLayer(e)?this:(this._speechbubble=e,this._speechbubble.update(),this.addLayer(e))},closeSpeechBubble:function(t){return t&&t!==this._speechbubble||(t=this._speechbubble,this._speechbubble=null),t&&this.removeLayer(t),this}}),t.SpeechBubble},window); \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index b6244dd..c745b20 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,13 +1,13 @@ var gulp = require('gulp'); var uglify = require('gulp-uglify'); -var mochaPhantomJS = require('gulp-mocha-phantomjs'); +//var mochaPhantomJS = require('gulp-mocha-phantomjs'); gulp.task('dist', function() { gulp.src('src/L.SpeechBubble.js') .pipe(uglify()) .pipe(gulp.dest('dist')) }); - +/* gulp.task('test', function () { return gulp .src('tests/testrunner.html') @@ -16,4 +16,5 @@ gulp.task('test', function () { 'ssl-protocol': 'tlsv1' } })); -}); \ No newline at end of file +}); +*/ \ No newline at end of file diff --git a/package.json b/package.json index bb2cc90..411eeff 100644 --- a/package.json +++ b/package.json @@ -3,16 +3,19 @@ "version": "1.0.0", "description": "Speech Bubble to get direction.", "main": "src/L.SpeechBubble.js", - "author": "Sylvain BRISSY", + "author": { + "name": "Sylvain BRISSY", + "email": "s.brissy@autoroutes-trafic.fr" + }, "license": "IST", "peerDependencies": { "leaflet": "^1.0.0" }, - "directories": { + "directories": { "example": "examples", "dist": "dist" }, - "repository": { + "repository": { "type": "git", "url": "https://github.com/sybri/Leaflet.SpeechBubble.git" }, @@ -20,8 +23,8 @@ "leaflet", "SpeechBubble" ], - "author": { - "name": "Sylvain BRISYS", - "email": "s.brissy@autoroutes-trafic.fr" - }, -} \ No newline at end of file + "devDependencies": { + "gulp": "^3.9.1", + "gulp-uglify": "^3.0.0" + } +}