-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathjump.min.js
24 lines (24 loc) · 10.2 KB
/
jump.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(function(a){a.jump={};a.jump.plugins={};a.jump.lon2x=function(a,e,b){return Math.floor((a+180)/360*b*Math.pow(2,e))};a.jump.lat2y=function(a,e,b){a=a*Math.PI/180;return Math.floor((1-Math.log(Math.tan(a)+1/Math.cos(a))/Math.PI)/2*b*Math.pow(2,e))};a.jump.x2lon=function(a,e,b){return 360*(a/b/Math.pow(2,e)-0.5)};a.jump.y2lat=function(a,e,b){a=0.5-a/b/Math.pow(2,e);return 90-360*Math.atan(Math.exp(-a*2*Math.PI))/Math.PI};a.fn.jump=function(g){g=a.extend(!0,{},a.fn.jump.defaults,g);return this.each(function(){var e=
a(this);e.css("position","relative").css("overflow","hidden");var b=a.extend(!0,{},g);e.data("state",b);e.bind("changecenter",function(f,c){c.old_center=a.extend({},b.center);if(c.lat&&c.lon)c.x=b.center.x=a.jump.lon2x(c.lon,b.zoom,b.tilesize),c.y=b.center.y=a.jump.lat2y(c.lat,b.zoom,b.tilesize),hasLatLon=!0;if(c.x&&c.y)b.center.x=c.x,b.center.y=c.y;c.new_center=a.extend({},b.center);c.pixelDiff={x:c.old_center.x-c.new_center.x,y:c.old_center.y-c.new_center.y};c.getNewLon=function(){return a.jump.x2lon(c.x,
b.zoom,b.tilesize)};c.getNewLat=function(){return a.jump.y2lat(c.y,b.zoom,b.tilesize)}});e.bind("moveby",function(a,c){e.triggerHandler("changecenter",{x:b.center.x+(c.x?c.x:0),y:b.center.y+(c.y?c.y:0)})});e.bind("zoom",function(a,c){c<0&&(c=0);c>18&&(c=18);var d={old_level:b.zoom,new_level:c,diff:c-b.zoom};b.center.x*=Math.pow(2,d.diff);b.center.y*=Math.pow(2,d.diff);b.zoom=c;return d});e.bind("zoomin",function(){return e.triggerHandler("zoom",b.zoom+1)});e.bind("zoomout",function(){return e.triggerHandler("zoom",
b.zoom-1)});e.bind("getBoundingBox",function(){e.width();e.height();e.width();e.height()});e.bind("click dblclick mousedown mouseover mouseup touchstart touchmove touchend",function(f){var c=f.pageY?f.pageY:f.originalEvent.touches[0].clientY;f.mapPosition={x:(f.pageX?f.pageX:f.originalEvent.touches[0].clientX)-e.offset().left+b.center.x-e.width()/2,y:c-e.offset().top+b.center.y-e.height()/2};f.mapPosition.getLat=function(){return a.jump.y2lat(f.mapPosition.y,b.zoom,b.tilesize)};f.mapPosition.getLon=
function(){return a.jump.x2lon(f.mapPosition.x,b.zoom,b.tilesize)};return f});for(var d in b.plugins)a.jump.plugins[d].start.call(this,b.plugins[d]);e.triggerHandler("changecenter",b.center)})};a.fn.jump.defaults={zoom:14,center:{lat:52.52643,lon:13.41156},plugins:{clickcontroller:!0,mousecontroller:!0,touchcontroller:!0,osmtiles:{tilesize:256},attribution:!0}}})(jQuery);
(function(a){a.jump.plugins.osmtiles={start:function(g){function e(){var c={y:Math.floor(d.center.x/d.tilesize),x:Math.floor(d.center.y/d.tilesize)};c.xTileOffset=d.center.x-d.tilesize*c.x;c.yTileOffset=d.center.y-d.tilesize*c.y;c.xTotalOffset=Math.floor(b.width()/2-c.xTileOffset);c.yTotalOffset=Math.floor(b.height()/2-c.yTileOffset);var e=Math.ceil((b.width()/2-c.xTileOffset)/d.tilesize),i=Math.ceil((b.width()/2+c.xTileOffset)/d.tilesize)-1,j=Math.ceil((b.height()/2-c.yTileOffset)/d.tilesize),n=
Math.ceil((b.height()/2+c.yTileOffset)/d.tilesize)-1,l,m;for(l in f)f[l].data("visible",!1);var o=a("<img/>").css("position","absolute").css("width",d.tilesize).css("height",d.tilesize);for(e*=-1;e<=i;e++)for(m=-1*j;m<=n;m++){var h={};h.tileXID=e+c.x;h.tileYID=m+c.y;h.id="t_"+d.zoom+"_"+h.tileXID+"_"+h.tileYID;h.left=e*d.tilesize+c.xTotalOffset;h.top=m*d.tilesize+c.yTotalOffset;f[h.id]==void 0?(h.img=o.clone().attr("id",h.id).css("left",h.left).css("top",h.top).attr("src",g.tileurl(d.zoom,h.tileXID,
h.tileYID)),b.append(h.img),f[h.id]=h.img):(h.img=f[h.id],h.img.css("left",h.left),h.img.css("top",h.top));h.img.data("visible",!0)}for(l in f)f[l].data("visible")||(a("#"+l).remove(),delete f[l])}var b=a(this),g=a.extend({},a.jump.plugins.osmtiles.defaults,g),d=b.data("state");d.tilesize=g.tilesize;var f={};b.bind("updatetiles",e);b.bind("changecenter",e);b.bind("zoom",e)}};a.jump.plugins.osmtiles.defaults={tilesize:256,tileurl:function(a,e,b){a=Math.floor(a);return"http://"+String.fromCharCode(97+
Math.abs(a+e+b)%3)+".tile.openstreetmap.org/"+a+"/"+e+"/"+b+".png"}}})(jQuery);
(function(a){a.jump.plugins.touchcontroller={start:function(){function g(a){d.dragging.dragOffset={x:a.originalEvent.touches[0].clientX-d.dragging.start.x,y:a.originalEvent.touches[0].clientY-d.dragging.start.y};b.trigger("changecenter",{x:d.dragging.original_x-d.dragging.dragOffset.x,y:d.dragging.original_y-d.dragging.dragOffset.y})}function e(){a(document).unbind("touchmove",g);a(document).unbind("touchend",e)}var b=a(this),d=b.data("state");b.bind("touchstart",function(f){f.preventDefault&&f.preventDefault();
var c=f.originalEvent.touches;c.length==1?(d.dragging={},d.dragging.start={x:c[0].clientX,y:c[0].clientY},d.dragging.original_x=d.center.x,d.dragging.original_y=d.center.y,a(document).bind("touchmove",g),a(document).bind("touchend",e),d.dbltap?(clearTimeout(d.dbltap),d.dbltap=!1,f=a.extend({},f,!0),f.type="dbltap",b.trigger(f)):d.dbltap=setTimeout(function(){d.dbltap=!1},500)):e(f)});b.bind("gesturestart",function(){d.twoFingerTap=setTimeout(function(){d.twoFingerTap=!1},500)});b.bind("gestureend",
function(f){if(d.twoFingerTap)clearTimeout(d.twoFingerTap),d.twoFingerTap=!1,f=a.extend({},f,!0),f.type="twofingertap",b.trigger(f)});b.bind("gesturechange",function(a){var c={};a.originalEvent.scale<0.75&&b.triggerHandler("zoomout",c);a.originalEvent.scale>1.25&&b.triggerHandler("zoomin",c)});b.bind("dbltap",function(a){d.center.x=a.mapPosition.x;d.center.y=a.mapPosition.y;b.triggerHandler("zoomin")});b.bind("twofingertap",function(){b.triggerHandler("zoomout")})}}})(jQuery);
(function(a){a.jump.plugins.mousecontroller={start:function(){function g(c){c=a.event.fix(c||window.event);c.type="mousewheel";c.preventDefault();var b=0;c.wheelDelta&&(b=c.wheelDelta/120);c.detail&&(b=-c.detail/3);c={x:c.pageX-d.offset().top,y:c.pageY-d.offset().left};b>0&&d.triggerHandler("zoomin",c);b<0&&d.triggerHandler("zoomout",c)}function e(a){a.preventDefault();f.dragging.dragOffset={x:a.pageX-f.dragging.start.x,y:a.pageY-f.dragging.start.y};d.trigger("changecenter",{x:f.dragging.original_x-
f.dragging.dragOffset.x,y:f.dragging.original_y-f.dragging.dragOffset.y})}function b(){a(document).unbind("mousemove",e);a(document).unbind("mouseup",b)}var d=a(this),f=d.data("state");d.bind("mousewheel",g);d.bind("DOMMouseScroll",g);d.onmousewheel=g;d.bind("mousedown",function(c){c.preventDefault();f.dragging={};f.dragging.start={x:c.pageX,y:c.pageY};f.dragging.original_x=f.center.x;f.dragging.original_y=f.center.y;a(document).bind("mousemove",e);a(document).bind("mouseup",b)});d.bind("dblclick",
function(a){f.center.x=a.mapPosition.x;f.center.y=a.mapPosition.y;d.triggerHandler("zoomin")})}}})(jQuery);
(function(a){a.jump.plugins.clickcontroller={start:function(){var g=a(this),e=a('<div class="clicknavigation">').css("width","60px").css("position","absolute").css("z-index","10").css("top","20px").css("left","20px"),b=a('<div class="clicknavigationbox" href="#">').css("width","25px").css("height","25px").css("margin","0").css("background-color","#FAFAFA").css("border","1px solid #AAA").css("display","inline-block").css("text-align","center").css("font-weight","bold").css("font-size","18px").css("text-decoration",
"none"),d=b.clone().addClass("gonorth").html("↑").borderradius("15px 15px 0 0").css("margin-left","12px").bind("touchstart click dblclick",function(a){g.trigger("moveby",{y:-10});a.preventDefault();a.stopPropagation()}),f=b.clone().addClass("gowest").html("←").borderradius("15px 0 0 15px").bind("touchstart click dblclick",function(a){g.trigger("moveby",{x:-10});a.preventDefault();a.stopPropagation()}),c=b.clone().addClass("goeast").html("→").borderradius("0 15px 15px 0").bind("touchstart click dblclick",
function(a){g.trigger("moveby",{x:10});a.preventDefault();a.stopPropagation()}),k=b.clone().addClass("gosouth").html("↓").borderradius("0 0 15px 15px").css("margin-left","12px").bind("touchstart click dblclick",function(a){g.trigger("moveby",{y:10});a.preventDefault();a.stopPropagation()}),i=b.clone().addClass("zoomin").html("+").borderradius("15px 15px 0 0").css("margin","10px 0 0 12px").bind("touchstart click dblclick",function(a){g.trigger("zoomin");a.preventDefault();a.stopPropagation()}),
b=b.clone().addClass("zoomout").html("-").borderradius("0 0 15px 15px").css("margin-left","12px").bind("touchstart click dblclick",function(a){g.trigger("zoomout");a.preventDefault();a.stopPropagation()});e.append(d).append(f).append(c).append(k).append(i).append(b);g.append(e)}}})(jQuery);(function(a){a.fn.borderradius=function(g){return this.each(function(){a(this).css("border-radius",g).css("-moz-border-radius",g).css("-webkit-border-radius",g)})}})(jQuery);
(function(a){a.jump.plugins.attribution={start:function(){var g=a('<div style="position:absolute;bottom:5px;right:20px;font-family:sans-serif;font-size:12px;z-index:10;">');g.html('Map data CCBYSA <a href="http://openstreetmap.org/">OpenStreetMap.org</a> contributors');a(this).append(g)}}})(jQuery);
(function(a){a.jump.plugins.coordinates={start:function(){var g=a(this);g.data("state");var e=a('<div style="position:absolute;bottom:20px;right:20px;font-weight:bold;z-index:10;">');g.append(e);g.bind("changecenter",function(a,d){e.html(Math.round(d.getNewLon()*1E5)/1E5+"<br>"+Math.round(d.getNewLat()*1E5)/1E5)})}}})(jQuery);
(function(a){a.jump.plugins.marker={start:function(){function g(d,f){return{x:a.jump.lon2x(d,b.zoom,b.tilesize)-(b.center.x-Math.floor(e.width()/2)),y:a.jump.lat2y(f,b.zoom,b.tilesize)-(b.center.y-Math.floor(e.height()/2))}}var e=a(this),b=e.data("state");e.bind("addElement",function(a,b){var c=b.element,k=b.location,i=b.offset?b.offset:{x:0,y:0},j=g(k.lon,k.lat);c.css("position","absolute");c.css("left",j.x+i.x);c.css("top",j.y+i.y);e.append(c);e.bind("zoom changecenter",function(){j=g(k.lon,k.lat);
c.css("left",j.x+i.x);c.css("top",j.y+i.y)})});e.bind("addMarker",function(b,f){var f=a.extend({color:"red",content:!1,offset:{x:-9,y:-9}},f),c=a("<div>").css("border","1px solid grey").css("background-color","white").css("z-index",11).addClass("popupContent").html(f.content).hide(),g=a("<div>").css("border","4px solid "+f.color).css("height","10").css("width","10").css("z-index",10).borderradius("10px").bind("click touchstart",function(){c.toggle()});e.trigger("addElement",{element:c,location:f.location});
e.trigger("addElement",{element:g,offset:f.offset,location:f.location})})}}})(jQuery);