I'm trying to make a map that have zoom-in and zoom-out functionality.
The problem is when wheeling on the map:
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.
https://d3js.org/d3.v4.min.js