Skip to content

Instantly share code, notes, and snippets.

View Scarysize's full-sized avatar

Franz Scarysize

View GitHub Profile
// from https://github.com/mapbox/mapbox-gl-shaders/blob/master/src/raster.fragment.glsl
void main() {
// lookup color from tile texture
vec4 color0 = texture2D(u_image0, v_pos0);
// lookup color from parent tile texture
vec4 color1 = texture2D(u_image1, v_pos1);
// cross-fade tile and parent colors based on zoom
vec4 color = color0 * u_opacity0 + color1 * u_opacity1;
vec3 rgb = color.rgb;
/**
* @param {array} valueMap The mapping between grey and data values
* @param {function} colorFunction The color mapping function, which defaults to returning a transparent color
*/
function createColorTexture(valueMap, colorFunction = () => 'transparent') {
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
const width = 256; // number of possible pixel color values, 0..255
const height = 1;
#ifdef GL_ES
precision mediump float;
#else
#define lowp
#define mediump
#define highp
#endif
// the grey scale raster tile as a texture
uniform sampler2D u_image0;
#include <node.h>
#include <string>
#include "Sources/Classes.hpp"
namespace nnselector {
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
'use strict';
const Point = require('point-geometry');
const LngLat = require('../geo/lng_lat');
const LngLatBounds = require('../geo/lng_lat_bounds');
const intersect = require('turf-intersect');
const bboxPolygon = require('turf-bbox-polygon');
module.exports = createTileIntersect();
@Scarysize
Scarysize / 0_addSourceWithBounds.js
Last active October 22, 2016 14:51
Setup for mapbox-gl to avoid tile requests to tiles which are located on the outside of a given bounding box.
import createTileIntersect from './testTileIntersection';
/**
* @param {string} id The source id
* @param {object} options The source options object
* @param {object} boundingBox Format: {sw: {lng, lat}, ne: {lng, lat}}
* @param {mapbox.Map} map The map to add the source to
*/
export default function addSourceWithBounds(id, options, boundingBox, map) {
map.addSource(id, options);
function unproject(point, zoom) {
return {
lng: xLng(point.x, zoom),
lat: yLat(point.y, zoom)
};
}
function xLng(x, zoom) {
return x * 360 / Math.pow(2, zoom) - 180;
}
function convert(lngLatBounds) {
return {
topLeft: {
lng: lngLatBounds.sw.lng,
lat: lngLatBounds.ne.lat
},
bottomRight: {
lng: lngLatBounds.ne.lng,
lat: lngLatBounds.sw.lat
}
import intersect from './intersect';
export default function createTileIntersect() {
let tileCache = {};
let lastBbox = null;
return (boundingBox, tile) => {
if (!boundingBox) {
return true;
}

Build the docker image and start the container.

Start Xvfb in the container via

$ /etc/init.d/xvfb start

Run Chrome with working WebGL in kiosk mode