Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add geographic scale multiplier #216

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .babelrc
100644 → 100755
Empty file.
Empty file modified .editorconfig
100644 → 100755
Empty file.
Empty file modified .eslintrc
100644 → 100755
Empty file.
Empty file modified .github/PULL_REQUEST_TEMPLATE.md
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .jscsrc
100644 → 100755
Empty file.
Empty file modified .npmignore
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified dist/vizicities-worker.js
100644 → 100755
Empty file.
Empty file modified dist/vizicities-worker.min.js
100644 → 100755
Empty file.
Empty file modified dist/vizicities-worker.min.js.map
100644 → 100755
Empty file.
Empty file modified dist/vizicities.css
100644 → 100755
Empty file.
Empty file modified dist/vizicities.js
100644 → 100755
Empty file.
Empty file modified dist/vizicities.min.js
100644 → 100755
Empty file.
Empty file modified dist/vizicities.min.js.map
100644 → 100755
Empty file.
Empty file modified examples/all-the-things/index.html
100644 → 100755
Empty file.
Empty file modified examples/all-the-things/main.css
100644 → 100755
Empty file.
Empty file modified examples/all-the-things/main.js
100644 → 100755
Empty file.
Empty file modified examples/basic/index.html
100644 → 100755
Empty file.
Empty file modified examples/basic/main.css
100644 → 100755
Empty file.
Empty file modified examples/basic/main.js
100644 → 100755
Empty file.
Empty file modified examples/colour-by-height/index.html
100644 → 100755
Empty file.
Empty file modified examples/colour-by-height/main.css
100644 → 100755
Empty file.
Empty file modified examples/colour-by-height/main.js
100644 → 100755
Empty file.
Empty file modified examples/geojson/index.html
100644 → 100755
Empty file.
Empty file modified examples/geojson/main.css
100644 → 100755
Empty file.
Empty file modified examples/geojson/main.js
100644 → 100755
Empty file.
Empty file modified examples/interactive/index.html
100644 → 100755
Empty file.
Empty file modified examples/interactive/main.css
100644 → 100755
Empty file.
Empty file modified examples/interactive/main.js
100644 → 100755
Empty file.
Empty file modified examples/lots-of-features/index.html
100644 → 100755
Empty file.
Empty file modified examples/lots-of-features/main.css
100644 → 100755
Empty file.
Empty file modified examples/lots-of-features/main.js
100644 → 100755
Empty file.
Empty file modified examples/mta-routes/index.html
100644 → 100755
Empty file.
Empty file modified examples/mta-routes/main.css
100644 → 100755
Empty file.
Empty file modified examples/mta-routes/main.js
100644 → 100755
Empty file.
Empty file modified examples/tile-events/index.html
100644 → 100755
Empty file.
Empty file modified examples/tile-events/main.css
100644 → 100755
Empty file.
Empty file modified examples/tile-events/main.js
100644 → 100755
Empty file.
Empty file modified examples/vendor/TweenMax.min.js
100644 → 100755
Empty file.
Empty file modified examples/vendor/chroma.min.js
100644 → 100755
Empty file.
Empty file modified examples/vendor/three.js
100644 → 100755
Empty file.
Empty file modified examples/vendor/three.min.js
100644 → 100755
Empty file.
Empty file modified examples/vendor/threex.rendererstats.js
100644 → 100755
Empty file.
Empty file modified examples/web-workers-all-the-things/index.html
100644 → 100755
Empty file.
Empty file modified examples/web-workers-all-the-things/main.css
100644 → 100755
Empty file.
Empty file modified examples/web-workers-all-the-things/main.js
100644 → 100755
Empty file.
Empty file modified examples/web-workers-all-the-things/vizicities-worker.js
100644 → 100755
Empty file.
Empty file modified examples/web-workers-basic/index.html
100644 → 100755
Empty file.
Empty file modified examples/web-workers-basic/main.css
100644 → 100755
Empty file.
Empty file modified examples/web-workers-basic/main.js
100644 → 100755
Empty file.
Empty file modified examples/web-workers-basic/vizicities-worker.js
100644 → 100755
Empty file.
Empty file modified examples/web-workers-geojson/index.html
100644 → 100755
Empty file.
Empty file modified examples/web-workers-geojson/main.css
100644 → 100755
Empty file.
Empty file modified examples/web-workers-geojson/main.js
100644 → 100755
Empty file.
Empty file modified examples/web-workers-geojson/vizicities-worker.js
100644 → 100755
Empty file.
Empty file modified examples/web-workers-outlines/index.html
100644 → 100755
Empty file.
Empty file modified examples/web-workers-outlines/main.css
100644 → 100755
Empty file.
Empty file modified examples/web-workers-outlines/main.js
100644 → 100755
Empty file.
Empty file modified examples/web-workers-outlines/vizicities-worker.js
100644 → 100755
Empty file.
Empty file modified gulpfile.babel.js
100644 → 100755
Empty file.
Empty file modified package.json
100644 → 100755
Empty file.
Empty file modified src/World.js
100644 → 100755
Empty file.
Empty file modified src/controls/Controls.Orbit.js
100644 → 100755
Empty file.
Empty file modified src/controls/index.js
100644 → 100755
Empty file.
Empty file modified src/engine/Camera.js
100644 → 100755
Empty file.
Empty file modified src/engine/DOMRenderer2D.js
100644 → 100755
Empty file.
Empty file modified src/engine/DOMRenderer3D.js
100644 → 100755
Empty file.
Empty file modified src/engine/DOMScene2D.js
100644 → 100755
Empty file.
Empty file modified src/engine/DOMScene3D.js
100644 → 100755
Empty file.
Empty file modified src/engine/EffectComposer.js
100644 → 100755
Empty file.
Empty file modified src/engine/Engine.js
100644 → 100755
Empty file.
Empty file modified src/engine/Picking.js
100644 → 100755
Empty file.
Empty file modified src/engine/PickingMaterial.js
100644 → 100755
Empty file.
Empty file modified src/engine/PickingScene.js
100644 → 100755
Empty file.
Empty file modified src/engine/PickingShader.js
100644 → 100755
Empty file.
Empty file modified src/engine/Renderer.js
100644 → 100755
Empty file.
Empty file modified src/engine/Scene.js
100644 → 100755
Empty file.
50 changes: 28 additions & 22 deletions src/geo/Geo.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ Geo.MAX_LATITUDE = 85.0511287798;
Geo.ECC = 0.081819191;
Geo.ECC2 = 0.081819191 * 0.081819191;

// Multiplier is used to expand or compress the WebGL coordinate space relative
// to the EPSG:3857 / Pseudo-Mercator coordinate space (metres).
//
// This is useful for keeping coordinate calculations to smaller numbers and
// helps increase accuracy of things like the z-buffer, object intersection,
// and camera near and far clipping.
//
// A multiplier of 1 would mean a 1:1 mapping between WebGL and EPSG:3857
// coordinates (1 EPSG:3857 metre === 1 WebGL unit)
//
// A multiplier of 0.1 would mean a 1:0.1 mapping between WebGL and EPSG:3857
// coordinates (1 EPSG:3857 metre === 0.1 WebGL units)
Geo.multiplier = 0.1;

Geo.project = function(latlon) {
var d = Math.PI / 180;
var max = Geo.MAX_LATITUDE;
Expand Down Expand Up @@ -38,13 +52,20 @@ Geo.latLonToPoint = function(latlon) {
var projected = Geo.project(latlon);
projected.y *= -1;

projected.x *= Geo.multiplier;
projected.y *= Geo.multiplier;

return projected;
};

// Converts pixel / WebGL coords to geo coords
// This just reverses the Y axis to match WebGL
Geo.pointToLatLon = function(point) {
var _point = Point(point.x, point.y * -1);

_point.x /= Geo.multiplier;
_point.y /= Geo.multiplier;

return Geo.unproject(_point);
};

Expand Down Expand Up @@ -114,36 +135,21 @@ Geo.metresToWorld = function(metres, pointScale) {
//
// Latitude scale is chosen because it fluctuates more than longitude
var projectedMetres = Geo.metresToProjected(metres, pointScale);

var scale = Geo.scale();

// Scale projected metres
var scaledMetres = (scale * projectedMetres);

return scaledMetres;
return projectedMetres * Geo.multiplier;
};

// Convert world (WebGL) units to a value in real metres
Geo.worldToMetres = function(worldUnits, pointScale) {
var scale = Geo.scale();

var projectedUnits = worldUnits / scale;
var projectedUnits = worldUnits;
var realMetres = Geo.projectedToMetres(projectedUnits, pointScale);

return realMetres;
return realMetres / Geo.multiplier;
};

// If zoom is provided, returns the map width in pixels for a given zoom
// Else, provides fixed scale value
// Returns the world width in pixels for a given zoom, assuming tile dimensions
// of 256x256 pixels
Geo.scale = function(zoom) {
// If zoom is provided then return scale based on map tile zoom
if (zoom >= 0) {
return 256 * Math.pow(2, zoom);
// Else, return fixed scale value to expand projected coordinates from
// their 0 to 1 range into something more practical
} else {
return 1;
}
return 256 * Math.pow(2, zoom);
};

// Returns zoom level for a given scale value
Expand Down Expand Up @@ -193,7 +199,7 @@ Geo.distance = function(latlon1, latlon2, accurate) {
};

Geo.bounds = (function() {
var d = Geo.R * Math.PI;
var d = Geo.R * Math.PI * Geo.multiplier;
return [[-d, -d], [d, d]];
})();

Expand Down
Empty file modified src/geo/LatLon.js
100644 → 100755
Empty file.
Empty file modified src/geo/Point.js
100644 → 100755
Empty file.
Empty file modified src/layer/GeoJSONLayer.js
100644 → 100755
Empty file.
Empty file modified src/layer/GeoJSONWorkerLayer.js
100644 → 100755
Empty file.
Empty file modified src/layer/Layer.js
100644 → 100755
Empty file.
Empty file modified src/layer/LayerGroup.js
100644 → 100755
Empty file.
Empty file modified src/layer/TopoJSONLayer.js
100644 → 100755
Empty file.
Empty file modified src/layer/TopoJSONWorkerLayer.js
100644 → 100755
Empty file.
Empty file modified src/layer/environment/EnvironmentLayer.js
100644 → 100755
Empty file.
Empty file modified src/layer/environment/Sky.js
100644 → 100755
Empty file.
Empty file modified src/layer/environment/Skybox.js
100644 → 100755
Empty file.
Empty file modified src/layer/geometry/PointLayer.js
100644 → 100755
Empty file.
Empty file modified src/layer/geometry/PolygonLayer.js
100644 → 100755
Empty file.
Empty file modified src/layer/geometry/PolylineLayer.js
100644 → 100755
Empty file.
Empty file modified src/layer/tile/GeoJSONTile.js
100644 → 100755
Empty file.
Empty file modified src/layer/tile/GeoJSONTileLayer.js
100644 → 100755
Empty file.
Empty file modified src/layer/tile/ImageTile.js
100644 → 100755
Empty file.
Empty file modified src/layer/tile/ImageTileLayer.js
100644 → 100755
Empty file.
Empty file modified src/layer/tile/ImageTileLayerBaseMaterial.js
100644 → 100755
Empty file.
Empty file modified src/layer/tile/Tile.js
100644 → 100755
Empty file.
Empty file modified src/layer/tile/TileCache.js
100644 → 100755
Empty file.
Empty file modified src/layer/tile/TileLayer.js
100644 → 100755
Empty file.
Empty file modified src/layer/tile/TopoJSONTileLayer.js
100644 → 100755
Empty file.
Empty file modified src/util/Buffer.js
100644 → 100755
Empty file.
Empty file modified src/util/GeoJSON.js
100644 → 100755
Empty file.
Empty file modified src/util/Stringify.js
100644 → 100755
Empty file.
Empty file modified src/util/Worker.js
100644 → 100755
Empty file.
Empty file modified src/util/WorkerPool.js
100644 → 100755
Empty file.
Empty file modified src/util/WorkerPoolWorker.js
100644 → 100755
Empty file.
Empty file modified src/util/extrudePolygon.js
100644 → 100755
Empty file.
Empty file modified src/util/index.js
100644 → 100755
Empty file.
Empty file modified src/util/wrapNum.js
100644 → 100755
Empty file.
Empty file modified src/vendor/BoxHelper.js
100644 → 100755
Empty file.
Empty file modified src/vendor/CSS2DRenderer.js
100644 → 100755
Empty file.
Empty file modified src/vendor/CSS3DRenderer.js
100644 → 100755
Empty file.
Empty file modified src/vendor/CopyShader.js
100644 → 100755
Empty file.
Empty file modified src/vendor/EffectComposer.js
100644 → 100755
Empty file.
Empty file modified src/vendor/FXAAShader.js
100644 → 100755
Empty file.
Empty file modified src/vendor/HorizontalTiltShiftShader.js
100644 → 100755
Empty file.
Empty file modified src/vendor/MaskPass.js
100644 → 100755
Empty file.
Empty file modified src/vendor/OrbitControls.js
100644 → 100755
Empty file.
Empty file modified src/vendor/RenderPass.js
100644 → 100755
Empty file.
Empty file modified src/vendor/ShaderPass.js
100644 → 100755
Empty file.
Empty file modified src/vendor/VerticalTiltShiftShader.js
100644 → 100755
Empty file.
Empty file modified src/vizicities-worker.js
100644 → 100755
Empty file.
Empty file modified src/vizicities.css
100644 → 100755
Empty file.
Empty file modified src/vizicities.js
100644 → 100755
Empty file.
Empty file modified test/.eslintrc
100644 → 100755
Empty file.
Empty file modified test/runner.html
100644 → 100755
Empty file.
Empty file modified test/setup/browser.js
100644 → 100755
Empty file.
Empty file modified test/setup/node.js
100644 → 100755
Empty file.
Empty file modified test/setup/setup.js
100644 → 100755
Empty file.
10 changes: 4 additions & 6 deletions test/unit/Geo.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,12 @@ describe('Geo', () => {
});

describe('#scale', () => {
it('defaults to 1', () => {
var scale = Geo.scale();
expect(scale).to.equal(1);
});

it('uses the zoom level if provided', () => {
it('returns scale for given zoom level', () => {
var scale = Geo.scale(1);
expect(scale).to.equal(512);

scale = Geo.scale(2);
expect(scale).to.equal(1024);
});
});

Expand Down
Empty file modified test/unit/vizicities.js
100644 → 100755
Empty file.