javascript - Dynamic simplification with projection in D3 -


i drawing svg map d3 using d3.geo.mercator() projection.

i use zoom behaviour map applies transform <g> object holding paths of map.

after looking @ examples of dynamic simplification mike bostock (http://bl.ocks.org/mbostock/6252418) wonder whether can apply such algorithm in case redraw geometry fewer points when it's zoomed out?

in examples i've seen, there simplify function skips negligible points , plots rest is, , function used in var path = d3.geo.path().projection(simplify). can't use since need applied on top of existing projection = d3.geo.mercator().scale(*).translate([*,*]).

how should use dynamic simplification existing projection?

according example quoted, dynamic simplification ii

the simplify function like

var simplify = d3.geo.transform({   point: function(x, y, z) {     if (z >= area) {         this.stream.point(x, y);     }   } }); 

where area treshold variable can set beforehand or modify dinamically according zoom.

then use on projection method of d3.geo.path() like

var path = d3.geo.path()     .projection(simplify); 

that's more or less situation described in answer. now, according dynamic simplification iv, projection method defined as

var path = d3.geo.path()     .projection({         stream: function(s) {              return simplify.stream(s);          }      }); 

this same before. it's "expanding" default methods. d3.geo.path calls projection stream method, can declare own stream , forward simplify.stream.

now, need reproject path using d3.geo.mercator().

var mercatorprojection = d3.geo.mercator().scale(*).translate([*,*]); 

no problem: the streams chainable. can do:

var path = d3.geo.path()     .projection({         stream: function(s) {              return simplify.stream(mercatorprojection.stream(s));          }      }); 

as as:

var path = d3.geo.path()     .projection({         stream: function(s) {              return mercatorprojection.stream(simplify.stream(s));          }      }); 

the difference being treshold area have calculated differently if you're dealing wgs84, pixels or coordinate system.

important caveat, z parameter in simplify function isn't altitude. the area of triangle defined each point, precalculated value that's part of topojson sweetness.

i'm afraid means can't rely on example simplify regular geojson. you'll have add own logic calculate each point's related area (if want apply visvalingam's algorithm) or distance closest point (if want apply douglas-peucker algorithm) or implement own algorithm.

good luck.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -