Skip to content

Commit

Permalink
Draw outline of states instead of mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrudz committed Nov 3, 2017
1 parent df1fb6b commit 7b7fec8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
27 changes: 22 additions & 5 deletions app/lib/plane-map-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ class ThreeJSRenderContext {
toShapes() {
return this.shapePath.toShapes(true);
}
toVertexes() {
const geometry = new THREE.Geometry();
this.shapePath.subPaths.forEach((line) => {
line.curves.forEach((lineCurve) => {
const a = new THREE.Vector3(lineCurve.v1.x, lineCurve.v1.y, 0);
const b = new THREE.Vector3(lineCurve.v2.x, lineCurve.v2.y, 0);
geometry.vertices.push(a, b);
});
});
return geometry;
}
}

AFRAME.registerComponent("plane-map", {
Expand Down Expand Up @@ -111,19 +122,25 @@ AFRAME.registerComponent("plane-map", {
}
};
// const projection = d3.geoStereographic().scale(0.5).translate([0, 0]).center([-73.968285, 40.785091]);
const material = new THREE.MeshStandardMaterial({ color: "blue", side: THREE.DoubleSide });

// const material = new THREE.MeshBasicMaterial({ color: "gray" });
const material = new THREE.LineBasicMaterial({
linewidth: 1,
color: "#ff00f1",
side: THREE.DoubleSide
});
geoJsonMesh.features.forEach(feature => {
const renderContext = new ThreeJSRenderContext();
const path = d3.geoPath(projectionInAFrameCoords, renderContext);
path(feature);
const [centerX, centerY] = path.centroid(feature);
const [[x0, y0], [x1, y1]] = path.bounds(feature);

const shapes = renderContext.toShapes();
const geometry = new THREE.ShapeGeometry(shapes);
// const shapes = renderContext.toShapes();
// console.log(shapes);
// const geometry = new THREE.ShapeBufferGeometry(shapes);
const geometry = renderContext.toVertexes();
geometry.translate(-centerX, -centerY, 0);
const mesh = new THREE.Mesh(geometry, material);
const mesh = new THREE.LineSegments(geometry, material);
const entity = document.createElement("a-entity");
entity.setAttribute("position", `${ centerX } ${ centerY } 0`);
entity.setAttribute("width", `${ x1 - x0 }`);
Expand Down
2 changes: 1 addition & 1 deletion app/vr-election-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const ready = (error, data) => {

const width = +stateContainer.attr("width");
const height = +stateContainer.attr("height");
const maxRadius = (d3.min([width, height]) / 2);
const maxRadius = (d3.min([width, height]) / 3);
rscale.range([0, maxRadius]);

let prevCylTop = 0;
Expand Down
4 changes: 2 additions & 2 deletions www/vr-election-map.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@


<a-entity id="plane-map"
position="0 -2 -8"
position="0 0 0"
rotation="-90 0 0"
geometry="primitive: plane; height: 10; width: 15;"
material="color: lightgray; transparent: false;"
plane-map="src: #json-states-10m; lineWidth: 1;"
visible="true"
>
</a-entity>
<a-camera id="camera" user-height="0" wasd-controls-enabled="true" look-controls-enabled="true">
<a-camera id="camera" wasd-controls-enabled="true" look-controls-enabled="true">
<a-entity id="infoText"
position="0.9 0 -2"
visible="false"
Expand Down

0 comments on commit 7b7fec8

Please sign in to comment.