Git Product home page Git Product logo

Comments (3)

damiaan avatar damiaan commented on July 29, 2024 1

Great, i got it working.

first defining, almost exactly as you suggested
collection = {type: "FeatureCollection", features: thecarto.features};
topology = topojson.topology({collection: collection});

then drawing/coloring the regions
mapg.selectAll(".subunit2").data(thecarto.features).enter().append("path") .attr("class","subunit2") .attr("d", carto.path) .attr('fill',function(d){return getcolor(coldata[d.id]);});

then i loop over all countries, merging the regions, and drawing the country borders
// countrylist Array [ "AT", "BE", "BG", "CY", "CZ", "DE", "DK", "EE", "ES", "FI", 18 more… ]
countrylist.forEach(function(d) {
var ctr = topojson.mergeArcs(topology,topology.objects.collection.geometries.filter(function(z) {return (z.id.substring(0,2) == d);}));
mapg.append("path").datum(topojson.mesh(topology,ctr)).attr("d", carto.path).attr("class", "cartoctrborder").style("stroke", "black").style("stroke-width", bordersize_ctr).style("fill", "none");
});

thanks a bunch!

from topogram.

shawnbot avatar shawnbot commented on July 29, 2024

Yeah, I think the problem is that TopoJSON won't work with the plain old Feature objects that topogram returns. You should be able to recreate a topology with something like:

var collection = {type: 'FeatureCollection', features: features};
var topology = topojson.topology(collection);

And then you can run topojson.merge() and/or topojson.mesh() on the resulting topology. Let me know if that works!

from topogram.

shawnbot avatar shawnbot commented on July 29, 2024

No problem!

from topogram.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.