Skip to content

Instantly share code, notes, and snippets.

@mapsam
mapsam / README.md
Created November 24, 2014 21:50
Leaflet layer toggling

Showing the functionality of toggling layers in Leaflet while preserving their reference for later usage (i.e. turning the layer back on). This is useful when working with many layers in leaflet and turning opacity to 0 won't cut it because it can have negative effects when hover and click events require properly layered DOM elements.

Important takeaways:

  • It's important to scope your data to access it globally, or at least within your appropriate scope.
  • Turn off a layer by referencing its variable using the removeLayer() method.
  • Turn on a layer by referencing its variable using the addLayer() method.
@mapsam
mapsam / README.md
Last active June 18, 2023 20:20
D3: Queue.js

A look at Queue.js and how you can load multiple files before running the rest of the code. Simple visualization of populated places in the USA. Files loaded:

  • US States - topojson
  • Populated Places - geojson
@mapsam
mapsam / README.md
Last active June 11, 2023 11:59
Namecheap > Github pages

Namecheap > Github pages

Pointing your domains to a gh-pages branch requires three steps.

  1. Add the Github IPs as A records on Namecheap.
    185.199.108.153
    185.199.109.153
    185.199.110.153
    185.199.111.153
@mapsam
mapsam / README.md
Created April 25, 2014 00:37
Inline SVG partial for WordPress

Good for acting on specific pieces of your SVG object instead of just link as an <img> you can bring the entire object into your HTML. You need two things:

  1. SVG file with a double extension ending with .php - e.g. logo.svg.php
  2. WP include statement with the built-in function get_template_part
<?php
get_template_part( 'includes/partials/logo', 'logo.svg' );
?>
@mapsam
mapsam / gallery.css
Last active May 14, 2021 12:57
Wordpress ACF Lightbox
@mapsam
mapsam / README.md
Created December 14, 2015 19:30
Outer & Inner loop drawings, TopoJSON

This example shows how geometries with inner loops and outer loops build themselves in opposite direction. The outer loop (red) builds clockwise, while the inner loop (blue) builds counter-clockwise. This is important in order to confidently account for negative MultiPolygons instead of separate Polygon features. Here's a good summary of the importance in winding order.

@mapsam
mapsam / geojson.js
Last active January 12, 2019 01:10
javascript geojson creation loop
var geojson = {};
geojson['type'] = 'FeatureCollection';
geojson['features'] = [];
for (var k in data) {
var newFeature = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [parseFloat(data[k].lng), parseFloat(data[k].lon)]
@mapsam
mapsam / get_latlng.html
Created February 27, 2015 21:27
Retrieve the Latitude and Longitude values from the Census geocoding API
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
<style>
body {
background: MediumAquaMarine;
}
@mapsam
mapsam / usage.js
Created March 1, 2016 01:58
node-mapnik usage example
var fs = require('fs');
var map = new mapnik.Map(256, 256),
img = new mapnik.Image(256, 256),
data = fs.readFileSync('/path/to/data.shp'),
vectortile = new mapnik.VectorTile(0,0,0);
// add shapefile to vector tile
vectortile.addData(data, function(err) {
if (err) throw err;
@mapsam
mapsam / test.geojson
Created October 8, 2016 17:50
mapbox-tile-copy geojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.