From 2fe52ec148adee350ac271e3ec253af546a09458 Mon Sep 17 00:00:00 2001 From: Brandon Tilley Date: Tue, 24 Dec 2013 21:33:28 -0800 Subject: [PATCH] (drag, zoom): Expose planet instance as `this` in event callbacks --- CHANGELOG.md | 3 +++ dist/planetaryjs-noplugins.js | 2 +- dist/planetaryjs.js | 18 +++++++++--------- dist/planetaryjs.min.js | 2 +- site/public/documentation/builtin_drag.md | 2 +- site/public/documentation/builtin_zoom.md | 2 +- site/public/examples/quake.ejs | 4 ++-- site/public/examples/quake/quake.js | 4 ++-- site/public/examples/rotating.ejs | 6 +++--- site/public/examples/rotating.js | 6 +++--- site/public/js/homepage.js | 8 ++++---- site/public/js/lib/planetaryjs.min.js | 2 +- src/plugins.js | 16 ++++++++-------- 13 files changed, 39 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e0c073..5ce5386 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +* Fix load order of global plugins +* Expose planet instance as `this` in event callbacks + v1.0.0-rc.1 (2013/12/24) ------------------------ diff --git a/dist/planetaryjs-noplugins.js b/dist/planetaryjs-noplugins.js index 159be03..18c77ef 100644 --- a/dist/planetaryjs-noplugins.js +++ b/dist/planetaryjs-noplugins.js @@ -2,7 +2,7 @@ * Copyright (c) 2013 Brandon Tilley * * Released under the MIT license - * Date: 2013-12-25T05:19:01.534Z + * Date: 2013-12-25T05:32:20.950Z */ (function (root, factory) { if (typeof define === 'function' && define.amd) { diff --git a/dist/planetaryjs.js b/dist/planetaryjs.js index bc317ce..8d5425a 100644 --- a/dist/planetaryjs.js +++ b/dist/planetaryjs.js @@ -2,7 +2,7 @@ * Copyright (c) 2013 Brandon Tilley * * Released under the MIT license - * Date: 2013-12-25T05:19:01.305Z + * Date: 2013-12-25T05:32:20.749Z */ (function (root, factory) { if (typeof define === 'function' && define.amd) { @@ -337,12 +337,12 @@ } zoom - .on('zoomstart', onZoomStart) - .on('zoomend', onZoomEnd) + .on('zoomstart', onZoomStart.bind(planet)) + .on('zoomend', onZoomEnd.bind(planet)) .on('zoom', function() { - onZoom(); + onZoom.call(planet); planet.projection.scale(d3.event.scale); - afterZoom(); + afterZoom.call(planet); }); d3.select(planet.canvas).call(zoom); }); @@ -360,10 +360,10 @@ return function(planet) { planet.onInit(function() { var drag = d3.behavior.drag() - .on('dragstart', onDragStart) - .on('dragend', onDragEnd) + .on('dragstart', onDragStart.bind(planet)) + .on('dragend', onDragEnd.bind(planet)) .on('drag', function() { - onDrag(); + onDrag.call(planet); var dx = d3.event.dx; var dy = d3.event.dy; var rotation = planet.projection.rotate(); @@ -379,7 +379,7 @@ if (rotation[1] < -90) rotation[1] = -90; if (rotation[0] >= 180) rotation[0] -= 360; planet.projection.rotate(rotation); - afterDrag(); + afterDrag.call(planet); }); d3.select(planet.canvas).call(drag); }); diff --git a/dist/planetaryjs.min.js b/dist/planetaryjs.min.js index d3c7454..817d55b 100644 --- a/dist/planetaryjs.min.js +++ b/dist/planetaryjs.min.js @@ -1,2 +1,2 @@ /*! Planetary.js 1.0.0-rc.1 | (c) 2013 Brandon Tilley | Released under MIT License */ -!function(n,t){"function"==typeof define&&define.amd?define(["d3","topojson"],t):"object"==typeof exports?module.exports=t(require("d3"),require("topojson")):n.planetaryjs=t(n.d3,n.topojson,n)}(this,function(n,t,o){"use strict";var i=null;o&&(i=o.planetaryjs);var e=[],r=function(t,o,i){n.timer(function(){t.context.clearRect(0,0,o.width,o.height);for(var n=0;n=0;o--)t.unshift(e[o]);for(0===t.length&&(c.plugins.earth&&n.loadPlugin(c.plugins.earth()),c.plugins.pings&&n.loadPlugin(c.plugins.pings())),o=0;o=o.onInit.length?r(n,t,o):e(l)};e(l)}else r(n,t,o)},u=function(n,t,o,i){l(n,o),n.canvas=t,n.context=t.getContext("2d"),a(n,t,i)},c={plugins:{},noConflict:function(){return o.planetaryjs=i,c},loadPlugin:function(n){e.push(n)},planet:function(){var t=[],o={onInit:[],onDraw:[]},i={plugins:{},draw:function(n){u(i,n,t,o)},onInit:function(n){o.onInit.push(n)},onDraw:function(n){o.onDraw.push(n)},loadPlugin:function(n){t.push(n)},withSavedContext:function(n){if(!this.context)throw new Error("No canvas to fetch context for");this.context.save(),n(this.context),this.context.restore()}};return i.projection=n.geo.orthographic().clipAngle(90).precision(0),i.path=n.geo.path().projection(i.projection),i}};return c.plugins.topojson=function(t){return function(o){o.plugins.topojson={},o.onInit(function(i){if(t.world)o.plugins.topojson.world=t.world,setTimeout(i,0);else{var e=t.file||"world-110m.json";n.json(e,function(n,t){if(n)throw new Error("Could not load JSON "+e);o.plugins.topojson.world=t,i()})}})}},c.plugins.oceans=function(n){return function(t){t.onDraw(function(){t.withSavedContext(function(o){o.beginPath(),t.path.context(o)({type:"Sphere"}),o.fillStyle=n.fill||"black",o.fill()})})}},c.plugins.land=function(n){return function(o){var i=null;o.onInit(function(){var n=o.plugins.topojson.world;i=t.feature(n,n.objects.land)}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(i),n.fill!==!1&&(t.fillStyle=n.fill||"white",t.fill()),n.stroke&&(n.lineWidth&&(t.lineWidth=n.lineWidth),t.strokeStyle=n.stroke,t.stroke())})})}},c.plugins.borders=function(n){return function(o){var i=null,e={internal:function(n,t){return n.id!==t.id},external:function(n,t){return n.id===t.id},both:function(){return!0}};o.onInit(function(){var r=o.plugins.topojson.world,l=r.objects.countries,a=n.type||"internal";i=t.mesh(r,l,e[a])}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(i),t.strokeStyle=n.stroke||"gray",n.lineWidth&&(t.lineWidth=n.lineWidth),t.stroke()})})}},c.plugins.earth=function(n){n=n||{};var t=n.topojson||{},o=n.oceans||{},i=n.land||{},e=n.borders||{};return function(n){c.plugins.topojson(t)(n),c.plugins.oceans(o)(n),c.plugins.land(i)(n),c.plugins.borders(e)(n)}},c.plugins.pings=function(t){var o=[];t=t||{};var i=function(n,i,e){e=e||{},e.color=e.color||t.color||"white",e.angle=e.angle||t.angle||5,e.ttl=e.ttl||t.ttl||2e3;var r={time:new Date,options:e};t.latitudeFirst?(r.lat=n,r.lng=i):(r.lng=n,r.lat=i),o.push(r)},e=function(n,t,i){for(var e=[],l=0;l90&&(e[1]=90),e[1]<-90&&(e[1]=-90),e[0]>=180&&(e[0]-=360),t.projection.rotate(e),l()});n.select(t.canvas).call(o)})}},c}); \ No newline at end of file +!function(n,t){"function"==typeof define&&define.amd?define(["d3","topojson"],t):"object"==typeof exports?module.exports=t(require("d3"),require("topojson")):n.planetaryjs=t(n.d3,n.topojson,n)}(this,function(n,t,o){"use strict";var i=null;o&&(i=o.planetaryjs);var e=[],r=function(t,o,i){n.timer(function(){t.context.clearRect(0,0,o.width,o.height);for(var n=0;n=0;o--)t.unshift(e[o]);for(0===t.length&&(u.plugins.earth&&n.loadPlugin(u.plugins.earth()),u.plugins.pings&&n.loadPlugin(u.plugins.pings())),o=0;o=o.onInit.length?r(n,t,o):e(l)};e(l)}else r(n,t,o)},c=function(n,t,o,i){l(n,o),n.canvas=t,n.context=t.getContext("2d"),a(n,t,i)},u={plugins:{},noConflict:function(){return o.planetaryjs=i,u},loadPlugin:function(n){e.push(n)},planet:function(){var t=[],o={onInit:[],onDraw:[]},i={plugins:{},draw:function(n){c(i,n,t,o)},onInit:function(n){o.onInit.push(n)},onDraw:function(n){o.onDraw.push(n)},loadPlugin:function(n){t.push(n)},withSavedContext:function(n){if(!this.context)throw new Error("No canvas to fetch context for");this.context.save(),n(this.context),this.context.restore()}};return i.projection=n.geo.orthographic().clipAngle(90).precision(0),i.path=n.geo.path().projection(i.projection),i}};return u.plugins.topojson=function(t){return function(o){o.plugins.topojson={},o.onInit(function(i){if(t.world)o.plugins.topojson.world=t.world,setTimeout(i,0);else{var e=t.file||"world-110m.json";n.json(e,function(n,t){if(n)throw new Error("Could not load JSON "+e);o.plugins.topojson.world=t,i()})}})}},u.plugins.oceans=function(n){return function(t){t.onDraw(function(){t.withSavedContext(function(o){o.beginPath(),t.path.context(o)({type:"Sphere"}),o.fillStyle=n.fill||"black",o.fill()})})}},u.plugins.land=function(n){return function(o){var i=null;o.onInit(function(){var n=o.plugins.topojson.world;i=t.feature(n,n.objects.land)}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(i),n.fill!==!1&&(t.fillStyle=n.fill||"white",t.fill()),n.stroke&&(n.lineWidth&&(t.lineWidth=n.lineWidth),t.strokeStyle=n.stroke,t.stroke())})})}},u.plugins.borders=function(n){return function(o){var i=null,e={internal:function(n,t){return n.id!==t.id},external:function(n,t){return n.id===t.id},both:function(){return!0}};o.onInit(function(){var r=o.plugins.topojson.world,l=r.objects.countries,a=n.type||"internal";i=t.mesh(r,l,e[a])}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(i),t.strokeStyle=n.stroke||"gray",n.lineWidth&&(t.lineWidth=n.lineWidth),t.stroke()})})}},u.plugins.earth=function(n){n=n||{};var t=n.topojson||{},o=n.oceans||{},i=n.land||{},e=n.borders||{};return function(n){u.plugins.topojson(t)(n),u.plugins.oceans(o)(n),u.plugins.land(i)(n),u.plugins.borders(e)(n)}},u.plugins.pings=function(t){var o=[];t=t||{};var i=function(n,i,e){e=e||{},e.color=e.color||t.color||"white",e.angle=e.angle||t.angle||5,e.ttl=e.ttl||t.ttl||2e3;var r={time:new Date,options:e};t.latitudeFirst?(r.lat=n,r.lng=i):(r.lng=n,r.lat=i),o.push(r)},e=function(n,t,i){for(var e=[],l=0;l90&&(e[1]=90),e[1]<-90&&(e[1]=-90),e[0]>=180&&(e[0]-=360),t.projection.rotate(e),l.call(t)});n.select(t.canvas).call(o)})}},u}); \ No newline at end of file diff --git a/site/public/documentation/builtin_drag.md b/site/public/documentation/builtin_drag.md index 715e158..9d28ae5 100644 --- a/site/public/documentation/builtin_drag.md +++ b/site/public/documentation/builtin_drag.md @@ -10,7 +10,7 @@ API Valid keys for `config` are: -* `onDragStart`, `onDragEnd`, `onDrag`, `afterDrag`: hooks to the `d3.behavior.drag` object's `dragstart`, `dragend`, and `drag` events; each defaults to a no-op. `onDrag` fires at the start of the `drag` event, `afterDrag` at the end. +* `onDragStart`, `onDragEnd`, `onDrag`, `afterDrag`: hooks to the `d3.behavior.drag` object's `dragstart`, `dragend`, and `drag` events; each defaults to a no-op. `onDrag` fires at the start of the `drag` event, `afterDrag` at the end. The planet instance is available as `this` inside the each of the functions.
JavaScript
diff --git a/site/public/documentation/builtin_zoom.md b/site/public/documentation/builtin_zoom.md index b36130a..96edbdc 100644 --- a/site/public/documentation/builtin_zoom.md +++ b/site/public/documentation/builtin_zoom.md @@ -12,7 +12,7 @@ Valid keys for `config` are: * `initialScale`: the value to initialize the [`d3.behavior.zoom`](https://github.com/mbostock/d3/wiki/Zoom-Behavior) object's scale to; defaults to the scale of the planet's projection at the time the planet is initialized * `scaleExtent`: the value to use for the `d3.behavior.zoom` object's `scaleExtent` property, which defines how far in and out the planet can be zoomed; defaults to `[50, 2000]` -* `onZoomStart`, `onZoomEnd`, `onZoom`, `afterZoom`: hooks to the `d3.behavior.zoom` object's `zoomstart`, `zoomend`, and `zoom` events; each defaults to a no-op. `onZoom` fires at the start of the `zoom` event, `afterZoom` at the end. +* `onZoomStart`, `onZoomEnd`, `onZoom`, `afterZoom`: hooks to the `d3.behavior.zoom` object's `zoomstart`, `zoomend`, and `zoom` events; each defaults to a no-op. `onZoom` fires at the start of the `zoom` event, `afterZoom` at the end. The planet instance is available as `this` inside the each of the functions.
JavaScript
diff --git a/site/public/examples/quake.ejs b/site/public/examples/quake.ejs index 8bc7fac..bc9fa41 100644 --- a/site/public/examples/quake.ejs +++ b/site/public/examples/quake.ejs @@ -42,10 +42,10 @@ })); planet.loadPlugin(planetaryjs.plugins.drag({ onDragStart: function() { - planet.plugins.autorotate.pause(); + this.plugins.autorotate.pause(); }, onDragEnd: function() { - planet.plugins.autorotate.resume(); + this.plugins.autorotate.resume(); } })); planet.loadPlugin(autorotate(5)); diff --git a/site/public/examples/quake/quake.js b/site/public/examples/quake/quake.js index c2d073b..362d1ed 100644 --- a/site/public/examples/quake/quake.js +++ b/site/public/examples/quake/quake.js @@ -18,10 +18,10 @@ })); planet.loadPlugin(planetaryjs.plugins.drag({ onDragStart: function() { - planet.plugins.autorotate.pause(); + this.plugins.autorotate.pause(); }, onDragEnd: function() { - planet.plugins.autorotate.resume(); + this.plugins.autorotate.resume(); } })); planet.loadPlugin(autorotate(5)); diff --git a/site/public/examples/rotating.ejs b/site/public/examples/rotating.ejs index ef083b2..7423eb9 100644 --- a/site/public/examples/rotating.ejs +++ b/site/public/examples/rotating.ejs @@ -38,12 +38,12 @@ // Dragging the globe should pause the // automatic rotation until we release the mouse. onDragStart: function() { - globe.plugins.autorotate.pause(); + this.plugins.autorotate.pause(); }, onDragEnd: function() { - globe.plugins.autorotate.resume(); + this.plugins.autorotate.resume(); } - })) + })); // Set up the globe's initial scale, offset, and rotation. globe.projection.scale(175).translate([175, 175]).rotate([0, -10, 0]); diff --git a/site/public/examples/rotating.js b/site/public/examples/rotating.js index ecab566..5fae10e 100644 --- a/site/public/examples/rotating.js +++ b/site/public/examples/rotating.js @@ -21,12 +21,12 @@ // Dragging the globe should pause the // automatic rotation until we release the mouse. onDragStart: function() { - globe.plugins.autorotate.pause(); + this.plugins.autorotate.pause(); }, onDragEnd: function() { - globe.plugins.autorotate.resume(); + this.plugins.autorotate.resume(); } - })) + })); // Set up the globe's initial scale, offset, and rotation. globe.projection.scale(175).translate([175, 175]).rotate([0, -10, 0]); diff --git a/site/public/js/homepage.js b/site/public/js/homepage.js index b05b3d7..f88cefd 100644 --- a/site/public/js/homepage.js +++ b/site/public/js/homepage.js @@ -20,11 +20,11 @@ globe.loadPlugin(planetaryjs.plugins.drag({ // Dragging the globe should pause the // automatic rotation until we release the mouse. - onDragStart: function() { - globe.plugins.autorotate.pause(); + onDragStart: function(planet) { + this.plugins.autorotate.pause(); }, - onDragEnd: function() { - globe.plugins.autorotate.resume(); + onDragEnd: function(planet) { + this.plugins.autorotate.resume(); } })) // Set up the globe's initial scale, offset, and rotation. diff --git a/site/public/js/lib/planetaryjs.min.js b/site/public/js/lib/planetaryjs.min.js index d3c7454..817d55b 100644 --- a/site/public/js/lib/planetaryjs.min.js +++ b/site/public/js/lib/planetaryjs.min.js @@ -1,2 +1,2 @@ /*! Planetary.js 1.0.0-rc.1 | (c) 2013 Brandon Tilley | Released under MIT License */ -!function(n,t){"function"==typeof define&&define.amd?define(["d3","topojson"],t):"object"==typeof exports?module.exports=t(require("d3"),require("topojson")):n.planetaryjs=t(n.d3,n.topojson,n)}(this,function(n,t,o){"use strict";var i=null;o&&(i=o.planetaryjs);var e=[],r=function(t,o,i){n.timer(function(){t.context.clearRect(0,0,o.width,o.height);for(var n=0;n=0;o--)t.unshift(e[o]);for(0===t.length&&(c.plugins.earth&&n.loadPlugin(c.plugins.earth()),c.plugins.pings&&n.loadPlugin(c.plugins.pings())),o=0;o=o.onInit.length?r(n,t,o):e(l)};e(l)}else r(n,t,o)},u=function(n,t,o,i){l(n,o),n.canvas=t,n.context=t.getContext("2d"),a(n,t,i)},c={plugins:{},noConflict:function(){return o.planetaryjs=i,c},loadPlugin:function(n){e.push(n)},planet:function(){var t=[],o={onInit:[],onDraw:[]},i={plugins:{},draw:function(n){u(i,n,t,o)},onInit:function(n){o.onInit.push(n)},onDraw:function(n){o.onDraw.push(n)},loadPlugin:function(n){t.push(n)},withSavedContext:function(n){if(!this.context)throw new Error("No canvas to fetch context for");this.context.save(),n(this.context),this.context.restore()}};return i.projection=n.geo.orthographic().clipAngle(90).precision(0),i.path=n.geo.path().projection(i.projection),i}};return c.plugins.topojson=function(t){return function(o){o.plugins.topojson={},o.onInit(function(i){if(t.world)o.plugins.topojson.world=t.world,setTimeout(i,0);else{var e=t.file||"world-110m.json";n.json(e,function(n,t){if(n)throw new Error("Could not load JSON "+e);o.plugins.topojson.world=t,i()})}})}},c.plugins.oceans=function(n){return function(t){t.onDraw(function(){t.withSavedContext(function(o){o.beginPath(),t.path.context(o)({type:"Sphere"}),o.fillStyle=n.fill||"black",o.fill()})})}},c.plugins.land=function(n){return function(o){var i=null;o.onInit(function(){var n=o.plugins.topojson.world;i=t.feature(n,n.objects.land)}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(i),n.fill!==!1&&(t.fillStyle=n.fill||"white",t.fill()),n.stroke&&(n.lineWidth&&(t.lineWidth=n.lineWidth),t.strokeStyle=n.stroke,t.stroke())})})}},c.plugins.borders=function(n){return function(o){var i=null,e={internal:function(n,t){return n.id!==t.id},external:function(n,t){return n.id===t.id},both:function(){return!0}};o.onInit(function(){var r=o.plugins.topojson.world,l=r.objects.countries,a=n.type||"internal";i=t.mesh(r,l,e[a])}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(i),t.strokeStyle=n.stroke||"gray",n.lineWidth&&(t.lineWidth=n.lineWidth),t.stroke()})})}},c.plugins.earth=function(n){n=n||{};var t=n.topojson||{},o=n.oceans||{},i=n.land||{},e=n.borders||{};return function(n){c.plugins.topojson(t)(n),c.plugins.oceans(o)(n),c.plugins.land(i)(n),c.plugins.borders(e)(n)}},c.plugins.pings=function(t){var o=[];t=t||{};var i=function(n,i,e){e=e||{},e.color=e.color||t.color||"white",e.angle=e.angle||t.angle||5,e.ttl=e.ttl||t.ttl||2e3;var r={time:new Date,options:e};t.latitudeFirst?(r.lat=n,r.lng=i):(r.lng=n,r.lat=i),o.push(r)},e=function(n,t,i){for(var e=[],l=0;l90&&(e[1]=90),e[1]<-90&&(e[1]=-90),e[0]>=180&&(e[0]-=360),t.projection.rotate(e),l()});n.select(t.canvas).call(o)})}},c}); \ No newline at end of file +!function(n,t){"function"==typeof define&&define.amd?define(["d3","topojson"],t):"object"==typeof exports?module.exports=t(require("d3"),require("topojson")):n.planetaryjs=t(n.d3,n.topojson,n)}(this,function(n,t,o){"use strict";var i=null;o&&(i=o.planetaryjs);var e=[],r=function(t,o,i){n.timer(function(){t.context.clearRect(0,0,o.width,o.height);for(var n=0;n=0;o--)t.unshift(e[o]);for(0===t.length&&(u.plugins.earth&&n.loadPlugin(u.plugins.earth()),u.plugins.pings&&n.loadPlugin(u.plugins.pings())),o=0;o=o.onInit.length?r(n,t,o):e(l)};e(l)}else r(n,t,o)},c=function(n,t,o,i){l(n,o),n.canvas=t,n.context=t.getContext("2d"),a(n,t,i)},u={plugins:{},noConflict:function(){return o.planetaryjs=i,u},loadPlugin:function(n){e.push(n)},planet:function(){var t=[],o={onInit:[],onDraw:[]},i={plugins:{},draw:function(n){c(i,n,t,o)},onInit:function(n){o.onInit.push(n)},onDraw:function(n){o.onDraw.push(n)},loadPlugin:function(n){t.push(n)},withSavedContext:function(n){if(!this.context)throw new Error("No canvas to fetch context for");this.context.save(),n(this.context),this.context.restore()}};return i.projection=n.geo.orthographic().clipAngle(90).precision(0),i.path=n.geo.path().projection(i.projection),i}};return u.plugins.topojson=function(t){return function(o){o.plugins.topojson={},o.onInit(function(i){if(t.world)o.plugins.topojson.world=t.world,setTimeout(i,0);else{var e=t.file||"world-110m.json";n.json(e,function(n,t){if(n)throw new Error("Could not load JSON "+e);o.plugins.topojson.world=t,i()})}})}},u.plugins.oceans=function(n){return function(t){t.onDraw(function(){t.withSavedContext(function(o){o.beginPath(),t.path.context(o)({type:"Sphere"}),o.fillStyle=n.fill||"black",o.fill()})})}},u.plugins.land=function(n){return function(o){var i=null;o.onInit(function(){var n=o.plugins.topojson.world;i=t.feature(n,n.objects.land)}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(i),n.fill!==!1&&(t.fillStyle=n.fill||"white",t.fill()),n.stroke&&(n.lineWidth&&(t.lineWidth=n.lineWidth),t.strokeStyle=n.stroke,t.stroke())})})}},u.plugins.borders=function(n){return function(o){var i=null,e={internal:function(n,t){return n.id!==t.id},external:function(n,t){return n.id===t.id},both:function(){return!0}};o.onInit(function(){var r=o.plugins.topojson.world,l=r.objects.countries,a=n.type||"internal";i=t.mesh(r,l,e[a])}),o.onDraw(function(){o.withSavedContext(function(t){t.beginPath(),o.path.context(t)(i),t.strokeStyle=n.stroke||"gray",n.lineWidth&&(t.lineWidth=n.lineWidth),t.stroke()})})}},u.plugins.earth=function(n){n=n||{};var t=n.topojson||{},o=n.oceans||{},i=n.land||{},e=n.borders||{};return function(n){u.plugins.topojson(t)(n),u.plugins.oceans(o)(n),u.plugins.land(i)(n),u.plugins.borders(e)(n)}},u.plugins.pings=function(t){var o=[];t=t||{};var i=function(n,i,e){e=e||{},e.color=e.color||t.color||"white",e.angle=e.angle||t.angle||5,e.ttl=e.ttl||t.ttl||2e3;var r={time:new Date,options:e};t.latitudeFirst?(r.lat=n,r.lng=i):(r.lng=n,r.lat=i),o.push(r)},e=function(n,t,i){for(var e=[],l=0;l90&&(e[1]=90),e[1]<-90&&(e[1]=-90),e[0]>=180&&(e[0]-=360),t.projection.rotate(e),l.call(t)});n.select(t.canvas).call(o)})}},u}); \ No newline at end of file diff --git a/src/plugins.js b/src/plugins.js index e48de6c..df55f64 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -193,12 +193,12 @@ } zoom - .on('zoomstart', onZoomStart) - .on('zoomend', onZoomEnd) + .on('zoomstart', onZoomStart.bind(planet)) + .on('zoomend', onZoomEnd.bind(planet)) .on('zoom', function() { - onZoom(); + onZoom.call(planet); planet.projection.scale(d3.event.scale); - afterZoom(); + afterZoom.call(planet); }); d3.select(planet.canvas).call(zoom); }); @@ -216,10 +216,10 @@ return function(planet) { planet.onInit(function() { var drag = d3.behavior.drag() - .on('dragstart', onDragStart) - .on('dragend', onDragEnd) + .on('dragstart', onDragStart.bind(planet)) + .on('dragend', onDragEnd.bind(planet)) .on('drag', function() { - onDrag(); + onDrag.call(planet); var dx = d3.event.dx; var dy = d3.event.dy; var rotation = planet.projection.rotate(); @@ -235,7 +235,7 @@ if (rotation[1] < -90) rotation[1] = -90; if (rotation[0] >= 180) rotation[0] -= 360; planet.projection.rotate(rotation); - afterDrag(); + afterDrag.call(planet); }); d3.select(planet.canvas).call(drag); });