Last active
August 29, 2015 14:14
-
-
Save rccc/d4ca68ca24b6c2db3fe4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Document</title> | |
| <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.5.0/pure-min.css"> | |
| <style type="text/css"> | |
| body { max-width: 900px; height:auto;} | |
| </style> | |
| <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.js"></script> | |
| <script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script> | |
| <script type="text/javascript" src="http://d3js.org/queue.v1.min.js"></script> | |
| <script type="text/javascript"> | |
| jQuery(document).ready(function(){ | |
| var tooltip = d3.select("body") | |
| .append("div") | |
| .attr("class", "tooltip") | |
| .style("opacity", 0) | |
| ; | |
| function moveToBack(toMove, parent) { | |
| toMove.detach().appendTo(parent); | |
| } | |
| function clicked(d) { | |
| var x, y, k; | |
| if (d && centered !== d) { | |
| var centroid = path.centroid(d); | |
| x = centroid[0]; | |
| y = centroid[1]; | |
| k = 4; | |
| centered = d; | |
| } else { | |
| x = width / 2; | |
| y = height / 2; | |
| k = 1; | |
| centered = null; | |
| } | |
| regs.selectAll("path") | |
| .classed("active", centered && function(d) { return d === centered; }); | |
| regs.transition() | |
| .duration(750) | |
| .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")scale(" + k + ")translate(" + -x + "," + -y + ")") | |
| ; | |
| } | |
| var agency_nodes; | |
| var centered; | |
| var container = jQuery('#map-container'); | |
| var map_ratio = .7; | |
| var regs; | |
| var width = container.width(); | |
| var height = width * map_ratio; | |
| var path = d3.geo.path(); | |
| var projection = d3.geo | |
| .mercator() | |
| .center([1.9, 46]) | |
| .scale(width *2.5) | |
| .translate([width / 2, height / 2]) | |
| ; | |
| var svg = d3.select('#map-container').append("svg") | |
| .attr("id", "svg") | |
| .attr("viewBox", "20 0 " + width + " " + height ) | |
| .attr("width", "100%") | |
| .attr("height", "100%") | |
| ; | |
| path.projection(projection); | |
| queue() | |
| .defer(d3.json, "regions.geojson") | |
| .defer(d3.json, "agences.geojson") | |
| .await(createMap) | |
| ; | |
| function createMap(error, regions_data, agencies){ | |
| regs = svg.append("g"); | |
| regs.selectAll("path") | |
| .data(regions_data.features) | |
| .enter() | |
| .append("path") | |
| .attr("d", path) | |
| .on('click', clicked) | |
| ; | |
| agency_nodes = svg.selectAll('.agency') | |
| .data(agencies.features) | |
| .enter() | |
| .append("svg:circle", '') | |
| .attr('class', 'agency') | |
| .attr('cx', function(d) { return projection(d.geometry.coordinates)[0]}) | |
| .attr('cy', function(d){ return projection(d.geometry.coordinates)[1]}) | |
| // .attr("transform", function(d) { | |
| // return "translate(" + projection([ | |
| // d.geometry.coordinates[0], | |
| // d.geometry.coordinates[1] | |
| // ]) + ")" | |
| // }) | |
| .attr("r", 6) | |
| .attr('fill', '#f00') | |
| .on('mouseenter', function(d,i){ | |
| moveToBack(jQuery(this), jQuery('#map-container g')); | |
| d3.select(this) | |
| .transition() | |
| .duration('500') | |
| .attr('r', 10) | |
| ; | |
| }) | |
| .on('mouseout', function(d,i){ | |
| d3.select(this) | |
| .transition() | |
| .duration('500') | |
| .attr('r', 6) | |
| ; | |
| }); | |
| } | |
| }); | |
| </script> | |
| </head> | |
| <body> | |
| <div class="pure-g"> | |
| <div class="pure-u-1"> | |
| <h3 class="heading"> | |
| <b>TROUVER</b> UNE AGENCE | |
| </h3> | |
| </div> | |
| <div class="pure-u-1"> | |
| <div class="map-container" id="map-container"> | |
| </div><!-- .map-container --> | |
| </div> | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment