All examples By author By category About

1Cr18Ni9

Understanding of Zoom behavior

I'm trying to make a map that have zoom-in and zoom-out functionality.

The problem is when wheeling on the map:

  1. some shape will scale accordingly,
  2. all borders will increase or decrease,
  3. texts will change it's size either.

Firstly, we need understanding what is Zoom Behavior, as the document suggests:

The zoom behavior stores the zoom state on the element to which the zoom behavior was applied

We have two ways to access this object that applied on some node. One way to access it on the fly is when user trigger the zoom event:

var transform = d3.event.transform

Another way is to utilise d3.zoomTransform(node), node is DomNode which bind this behavior.

transform is some kind of 2d matrix object:

k b tx

d k ty

0 0 1

When scaling I can use d3.event.transform.k to get scale factor, and descale the stroke-width make it always seems identical width( normalWidth / scale ).

Symbol path area linear scale with k^2, I was trying to utilise with the same trick but failed because all symbole seems more luminous. So I just redraw the d attribute.