Skip to content

Instantly share code, notes, and snippets.

View Scarysize's full-sized avatar

Franz Scarysize

View GitHub Profile
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;
}
@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);
'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();
#include <node.h>
#include <string>
#include "Sources/Classes.hpp"
namespace nnselector {
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
#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;
/**
* @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;
// 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;
{
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true,
"es6": true
},
"plugins": [
"react"
],
/* style.css */
.title {
font-weight: 700;
}
/* js-file */
import styles from './style.css';
//...
titleElement.className = styles.title;
function MeteoGroupInteractiveMap(domElement, options) {
constructor(domElement, options) {
// Do we want to hide this?
// We might need to hide this in closures for map functionalities (zoom, pan etc.)
// IMO we should definitly hide it.
this.map = new google.maps.Map(domElement, options);
// better:
const map = new google.maps.Map(domElement, options);
this.setupMapControls(map);