Skip to content

Instantly share code, notes, and snippets.

@ebrelsford
ebrelsford / index.html
Created March 28, 2017 16:14
Hover popups in Carto.js v3, template in HTML
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<!--
Load Carto's code so we can pull in our Carto maps.
-->
<link rel="stylesheet" href="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/themes/css/cartodb.css" />
@ebrelsford
ebrelsford / index.html
Created March 28, 2017 16:07
Hover popups in Carto.js v3
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<!--
Load Carto's code so we can pull in our Carto maps.
-->
<link rel="stylesheet" href="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/themes/css/cartodb.css" />
@ebrelsford
ebrelsford / index.html
Created March 28, 2017 15:39
Using legends in Carto.js v3
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<!--
Load Carto's code so we can pull in our Carto maps.
-->
<link rel="stylesheet" href="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/themes/css/cartodb.css" />
@ebrelsford
ebrelsford / index.html
Created March 28, 2017 14:43
Adding zoom in and zoom out buttons with Carto.js v3
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<!--
Load Carto's code so we can pull in our Carto maps.
-->
@ebrelsford
ebrelsford / index.html
Last active March 28, 2017 14:32
Start map with custom SQL with Carto.js v3
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<!--
Load Carto's code so we can pull in our Carto maps.
-->
@ebrelsford
ebrelsford / index.html
Created March 28, 2017 14:08
Popups with Carto.js v3
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<!--
Load Carto's code so we can pull in our Carto maps.
-->
<link rel="stylesheet" href="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/themes/css/cartodb.css" />
@ebrelsford
ebrelsford / carto-js-builder.md
Last active May 18, 2017 11:05
Potential issues and workarounds when using Carto.js v3 with maps made with the Builder interface

Potential issues and workarounds when using Carto.js v3 with maps made with the Builder interface

When using the current version (v3 as of March 2017) of Carto.js with maps using Carto's new Builder interface, there are some issues you are likely to run into. Here I run through the common issues and some suggested workarounds.

Analysis and Widgets don't work

This is because Carto.js v3 doesn't understand them. Sorry but there is no easy workaround here. In the case of Analysis you could save it as its own layer and use that layer instead.

Legends don't work

@ebrelsford
ebrelsford / PinnedOverlay.js
Created January 5, 2017 21:00
React component that pins overlaid children on top of an element's background image
class PinnedOverlay extends React.Component {
constructor(props) {
super(props);
var image = new Image();
image.src = window.getComputedStyle(this.props.overlaid)['background-image'].replace(/"/g,"").replace(/url\(|\)$/ig, "");
this.imageWidth = image.width;
this.imageHeight = image.height;
this.aspectRatio = this.imageWidth / this.imageHeight;

Keybase proof

I hereby claim:

  • I am ebrelsford on github.
  • I am ebrelsford (https://keybase.io/ebrelsford) on keybase.
  • I have a public key ASC3gabi902GYAL8aiKmFotr-Kf19RrW4E6NvckfCpehlAo

To claim this, I am signing this object:

@ebrelsford
ebrelsford / index.md
Last active April 30, 2016 19:21
Points in polygon spatial joins with PostGIS

PostGIS is capable of just about any GIS operation you're used to doing in a desktop GIS. Here we cover typical points-in-polygon queries in PostGIS.

If you're new to joins in SQL, you'll notice a few things about the queries here. First, we select from multiple tables and give each a unique name (so instead of FROM nycc you'll tend to use FROM nycc cc, listings l if your query is over nycc and listings. Second, you'll be grouping the polygons by a unique id. As I'm using CartoDB here, I will group by cartodb_id.

Average

If we have a table called nycc of City Council districts and a table called listings of Airbnb listings, we can find the average price by city council district like so:

SELECT cc.*, AVG(l.price) AS avg_price