Giter Site home page Giter Site logo

Comments (3)

RandomEtc avatar RandomEtc commented on June 23, 2024

I'm not sure if any internal code already calculates the extent of the layer, so you probably need to loop over the features and calculate that yourself.

Once you have the min and max lat/lon of your features you can call map.extent(newExtent) to change the visible area. http://polymaps.org/docs/map.html#extent

from polymaps.

palewire avatar palewire commented on June 23, 2024

Thanks. I think I got it by adding a load function my json that links to:

Array.max = function( array ){
    return Math.max.apply( Math, array );
};
Array.min = function( array ){
    return Math.min.apply( Math, array );
};

function load(e) {
  var x = Array();
  var y = Array();
  for (var i = 0; i < e.features.length; i++) {
    var feature = e.features[i];
    var coords = feature.data.geometry.coordinates;
    var polygons = $.map(coords, function(a){return a});
    var points = $.map(polygons, function(a){return a});
    $.map(points, function(a){
        if(!isNaN(a[0])){x.push(a[0])}; 
        if(!isNaN(a[1])){y.push(a[1])};
    });
  }
  xMax = Array.max(x);
  xMin = Array.min(x);
  yMax = Array.max(y);
  yMin = Array.min(y);
  map.extent([{lon:xMin,lat:yMin},{lon:xMax,lat:yMax}])
}

from polymaps.

drewda avatar drewda commented on June 23, 2024

Just for future reference here's a relevant bit of code: https://github.com/mbostock/polymaps/blob/master/examples/bounds/bounds.js

from polymaps.

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.