Skip to content

Instantly share code, notes, and snippets.

@wewindy
wewindy / gradients.ts
Created March 30, 2022 10:27
web-color-gradients
export const Rainbow_7: string[] = [
'rgb(255, 0, 0)',
'rgb(255, 165, 0)',
'rgb(255, 255, 0)',
'rgb(0, 255, 0)',
'rgb(0, 255, 255)',
'rgb(0, 0, 255)',
'rgb(139, 0, 255)'
]
@wewindy
wewindy / local-highlight.js
Created May 23, 2022 06:17
CesiumLocalHighlight
fetch('./some-region.geojson').then(res => res.json()).then(data => {
let features = data.features;
let positionArray = [];
// 获取区域的经纬度坐标
for (let i = 0; i < features[0].geometry.coordinates[0].length; i++) {
let coor = features[0].geometry.coordinates[0][i];
positionArray.push(coor[0]);
positionArray.push(coor[1]);
}
@wewindy
wewindy / wkt-geojson.d.ts
Created May 24, 2022 10:17
WKTString-Geojson Transformer
export interface IGeoJson {
type: 'Feature' | 'Point' | 'LineString' | 'Polygon' | 'MultiPoint' | 'MultiLineString' | 'MultiPolygon' | 'GeometryCollection';
coordinates?: any[];
geometry?: IGeoJson;
geometries?: IGeoJson[];
crs?: string | {
type: string;
properties: {
name: string;
};
@wewindy
wewindy / esm-package.md
Created July 11, 2022 15:36 — forked from sindresorhus/esm-package.md
Pure ESM package

Pure ESM package

The package linked to from here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@wewindy
wewindy / skylinePostProcessStage.ts
Created October 31, 2022 08:30
Cesium Skyline PostProcessStage
const fragmentShaderText = /* glsl */`uniform sampler2D colorTexture;
uniform sampler2D depthTexture;
varying vec2 v_textureCoordinates;
void main() {
float depth = czm_readDepth(depthTexture, v_textureCoordinates);
vec4 color = texture2D(colorTexture, v_textureCoordinates);
if (depth < 1.0 - 0.000001) {
gl_FragColor = color;
@wewindy
wewindy / coplanar-real3d-space-polygon.js
Last active July 6, 2023 11:43
cesium-polyline-primitive
const viewer = new Cesium.Viewer("cesiumContainer");
const scene = viewer.scene;
const positions = [
new Cesium.Cartesian3(1000, 500, 100),
new Cesium.Cartesian3(1000, -500, 0),
new Cesium.Cartesian3(-1000, -500, 0),
new Cesium.Cartesian3(-1000, 500, 100),
];
const polygonGeometry = Cesium.CoplanarPolygonGeometry.fromPositions({
@wewindy
wewindy / Cesium Sandcastle DepthColorMap.js
Last active September 19, 2023 13:43
Canvas2D RGBA-TypeArray ImageBitmap ImageData
function appendTextureViewCanvas(id) {
const root = viewer.container.parentNode;
const cesiumCanvas = viewer.canvas;
const canvas = document.createElement('canvas');
canvas.id = id;
canvas.setAttribute('width', cesiumCanvas.clientWidth);
canvas.setAttribute('height', cesiumCanvas.clientHeight);
canvas.style.width = `${Math.floor(cesiumCanvas.clientWidth / 4)}px`;
canvas.style.height = `${Math.floor(cesiumCanvas.clientHeight / 4)}px`;
@wewindy
wewindy / a_or_b_segmentLine_entity.js
Last active September 18, 2023 11:03
「CesiumJS」Draw Dynamic Segment Line
const viewer = new Cesium.Viewer("cesiumContainer");
viewer.scene.globe.depthTestAgainstTerrain = true;
const handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
const getWC = (windowPosition) => {
return viewer.scene.pickPosition(windowPosition);
};
const FILL_COLOR = Cesium.Color.fromBytes(255, 101, 41, 255 * 0.6);
const OUTLINE_COLOR = Cesium.Color.fromBytes(255, 255, 255, 255 * 0.8);
@wewindy
wewindy / limit-cesiumjs-camera-tilt.js
Created September 19, 2023 20:01
Limit CesiumJS Camera Tilt
const viewer = new Cesium.Viewer("cesiumContainer");
const globe = viewer.scene.globe;
const camera = viewer.scene.camera;
const scratchNormal = new Cesium.Cartesian3();
const previousPosition = new Cesium.Cartesian3();
const previousDirection = new Cesium.Cartesian3();
const previousUp = new Cesium.Cartesian3();
const previousRight = new Cesium.Cartesian3();
@wewindy
wewindy / main.js
Created December 15, 2023 17:07
quaternion-rotation-3d
const viewer = new Cesium.Viewer("cesiumContainer", {
msaaSamples: 4,
});
const origin = Cesium.Cartesian3.fromDegrees(112.5, 22.3);
const targetENU = Cesium.Cartesian3.fromElements(
Math.sqrt(1 / 2) * 200,
Math.sqrt(1 / 2) * 200,
); // east-north 平面上的一点
const enuMat = Cesium.Transforms.eastNorthUpToFixedFrame(origin);