(geo, projection)
| 199 | // zoom for clipped projections |
| 200 | // inspired by https://www.jasondavies.com/maps/d3.geo.zoom.js |
| 201 | function zoomClipped(geo, projection) { |
| 202 | var view = {r: projection.rotate(), k: projection.scale()}; |
| 203 | var zoom = initZoom(geo, projection); |
| 204 | var event = d3eventDispatch(zoom, 'zoomstart', 'zoom', 'zoomend'); |
| 205 | var zooming = 0; |
| 206 | var zoomOn = zoom.on; |
| 207 | |
| 208 | var zoomPoint; |
| 209 | |
| 210 | zoom.on('zoomstart', function() { |
| 211 | d3.select(this).style(zoomstartStyle); |
| 212 | |
| 213 | var mouse0 = d3.mouse(this); |
| 214 | var rotate0 = projection.rotate(); |
| 215 | var lastRotate = rotate0; |
| 216 | var translate0 = projection.translate(); |
| 217 | var q = quaternionFromEuler(rotate0); |
| 218 | |
| 219 | zoomPoint = position(projection, mouse0); |
| 220 | |
| 221 | zoomOn.call(zoom, 'zoom', function() { |
| 222 | var mouse1 = d3.mouse(this); |
| 223 | |
| 224 | projection.scale(view.k = d3.event.scale); |
| 225 | |
| 226 | if(!zoomPoint) { |
| 227 | // if no zoomPoint, the mouse wasn't over the actual geography yet |
| 228 | // maybe this point is the start... we'll find out next time! |
| 229 | mouse0 = mouse1; |
| 230 | zoomPoint = position(projection, mouse0); |
| 231 | } else if(position(projection, mouse1)) { |
| 232 | // check if the point is on the map |
| 233 | // if not, don't do anything new but scale |
| 234 | // if it is, then we can assume between will exist below |
| 235 | // so we don't need the 'bank' function, whatever that is. |
| 236 | |
| 237 | // go back to original projection temporarily |
| 238 | // except for scale... that's kind of independent? |
| 239 | projection |
| 240 | .rotate(rotate0) |
| 241 | .translate(translate0); |
| 242 | |
| 243 | // calculate the new params |
| 244 | var point1 = position(projection, mouse1); |
| 245 | var between = rotateBetween(zoomPoint, point1); |
| 246 | var newEuler = eulerFromQuaternion(multiply(q, between)); |
| 247 | var rotateAngles = view.r = unRoll(newEuler, zoomPoint, lastRotate); |
| 248 | |
| 249 | if(!isFinite(rotateAngles[0]) || !isFinite(rotateAngles[1]) || |
| 250 | !isFinite(rotateAngles[2])) { |
| 251 | rotateAngles = lastRotate; |
| 252 | } |
| 253 | |
| 254 | // update the projection |
| 255 | projection.rotate(rotateAngles); |
| 256 | lastRotate = rotateAngles; |
| 257 | } |
| 258 |
nothing calls this directly
no test coverage detected
searching dependent graphs…