itowns 2.37.0 → 2.38.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -1
- package/changelog.md +101 -0
- package/dist/debug.js +1 -1
- package/dist/debug.js.LICENSE.txt +2 -2
- package/dist/debug.js.map +1 -1
- package/dist/itowns.js +1 -1
- package/dist/itowns.js.LICENSE.txt +2 -2
- package/dist/itowns.js.map +1 -1
- package/dist/itowns_widgets.js +1 -1
- package/dist/itowns_widgets.js.map +1 -1
- package/examples/config.json +4 -1
- package/examples/css/example.css +21 -1
- package/examples/css/widgets.css +118 -6
- package/examples/images/code-logo.svg +43 -0
- package/examples/index.html +5 -5
- package/examples/mars.html +0 -1
- package/examples/misc_orthographic_camera.html +7 -19
- package/examples/vector_tile_3d_mesh.html +155 -0
- package/examples/vector_tile_raster_3d.html +0 -5
- package/examples/view_25d_map.html +6 -19
- package/examples/view_2d_map.html +6 -19
- package/examples/view_3d_map.html +106 -81
- package/examples/widgets_minimap.html +3 -1
- package/examples/widgets_navigation.html +6 -1
- package/examples/widgets_scale.html +96 -0
- package/examples/widgets_searchbar.html +124 -0
- package/lib/Controls/PlanarControls.js +10 -42
- package/lib/Converter/Feature2Mesh.js +225 -61
- package/lib/Converter/Feature2Texture.js +4 -3
- package/lib/Converter/convertToTile.js +10 -5
- package/lib/Core/Feature.js +57 -30
- package/lib/Core/MainLoop.js +136 -62
- package/lib/Core/TileMesh.js +21 -5
- package/lib/Core/View.js +46 -15
- package/lib/Layer/FeatureGeometryLayer.js +37 -10
- package/lib/Layer/GeoidLayer.js +17 -6
- package/lib/Layer/GeometryLayer.js +6 -54
- package/lib/Layer/OrientedImageLayer.js +1 -0
- package/lib/Layer/RasterLayer.js +3 -1
- package/lib/Layer/ReferencingLayerProperties.js +50 -0
- package/lib/Main.js +1 -1
- package/lib/Parser/B3dmParser.js +3 -2
- package/lib/Parser/GeoJsonParser.js +29 -7
- package/lib/Parser/VectorTileParser.js +5 -4
- package/lib/Parser/deprecated/LegacyGLTFLoader.js +3 -3
- package/lib/Process/3dTilesProcessing.js +3 -3
- package/lib/Process/FeatureProcessing.js +36 -86
- package/lib/Process/LayeredMaterialNodeProcessing.js +9 -3
- package/lib/Process/ObjectRemovalHelper.js +4 -0
- package/lib/Provider/3dTilesProvider.js +2 -7
- package/lib/Provider/Fetcher.js +5 -2
- package/lib/Provider/TileProvider.js +18 -2
- package/lib/Renderer/Camera.js +33 -12
- package/lib/Renderer/ColorLayersOrdering.js +3 -1
- package/lib/Renderer/LayeredMaterial.js +32 -7
- package/lib/Renderer/OBB.js +8 -4
- package/lib/Renderer/OrientedImageMaterial.js +8 -5
- package/lib/Renderer/PointsMaterial.js +1 -0
- package/lib/Renderer/RenderMode.js +3 -1
- package/lib/Renderer/Shader/ShaderChunk.js +5 -1
- package/lib/Renderer/c3DEngine.js +9 -6
- package/lib/Source/FileSource.js +8 -1
- package/lib/Source/VectorTilesSource.js +5 -0
- package/lib/Source/WFSSource.js +9 -3
- package/lib/ThreeExtended/{WebGL.js → capabilities/WebGL.js} +8 -7
- package/lib/ThreeExtended/loaders/GLTFLoader.js +3 -4
- package/lib/Utils/DEMUtils.js +3 -1
- package/lib/Utils/gui/Main.js +39 -0
- package/lib/Utils/gui/Minimap.js +195 -0
- package/lib/Utils/gui/Navigation.js +322 -0
- package/lib/Utils/gui/Scale.js +154 -0
- package/lib/Utils/gui/Searchbar.js +299 -0
- package/lib/Utils/gui/Widget.js +119 -0
- package/package.json +27 -22
- package/examples/images/compass.svg +0 -60
- package/examples/images/widget-logo.svg +0 -66
- package/examples/js/Scale.js +0 -41
|
@@ -19,7 +19,7 @@ var _Capabilities = _interopRequireDefault(require("../Core/System/Capabilities"
|
|
|
19
19
|
|
|
20
20
|
var _LayeredMaterial = require("./LayeredMaterial");
|
|
21
21
|
|
|
22
|
-
var _WebGL = require("../ThreeExtended/WebGL");
|
|
22
|
+
var _WebGL = _interopRequireDefault(require("../ThreeExtended/capabilities/WebGL"));
|
|
23
23
|
|
|
24
24
|
var _Label2DRenderer = _interopRequireDefault(require("./Label2DRenderer"));
|
|
25
25
|
|
|
@@ -84,7 +84,10 @@ var c3DEngine = /*#__PURE__*/function () {
|
|
|
84
84
|
this.renderView = function (view) {
|
|
85
85
|
this.renderer.clear();
|
|
86
86
|
this.renderer.render(view.scene, view.camera.camera3D);
|
|
87
|
-
|
|
87
|
+
|
|
88
|
+
if (view.tileLayer) {
|
|
89
|
+
this.label2dRenderer.render(view.tileLayer.object3d, view.camera.camera3D);
|
|
90
|
+
}
|
|
88
91
|
}.bind(this);
|
|
89
92
|
|
|
90
93
|
this.onWindowResize = function (w, h) {
|
|
@@ -116,10 +119,10 @@ var c3DEngine = /*#__PURE__*/function () {
|
|
|
116
119
|
}
|
|
117
120
|
|
|
118
121
|
if (!this.renderer) {
|
|
119
|
-
if (!_WebGL.
|
|
120
|
-
viewerDiv.appendChild(_WebGL.
|
|
121
|
-
} else if (!_WebGL.
|
|
122
|
-
viewerDiv.appendChild(_WebGL.
|
|
122
|
+
if (!_WebGL["default"].isWebGLAvailable()) {
|
|
123
|
+
viewerDiv.appendChild(_WebGL["default"].getErrorMessage(1));
|
|
124
|
+
} else if (!_WebGL["default"].isWebGL2Available()) {
|
|
125
|
+
viewerDiv.appendChild(_WebGL["default"].getErrorMessage(2));
|
|
123
126
|
}
|
|
124
127
|
|
|
125
128
|
throw new Error('WebGL unsupported');
|
package/lib/Source/FileSource.js
CHANGED
|
@@ -107,7 +107,14 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
107
107
|
* .then(function _(geojson) {
|
|
108
108
|
* return itowns.GeoJsonParser.parse(geojson, {
|
|
109
109
|
* in: { crs: 'EPSG:4326' },
|
|
110
|
-
* out: { crs: view.tileLayer.extent.crs
|
|
110
|
+
* out: { crs: view.tileLayer.extent.crs,
|
|
111
|
+
* style: new itowns.Style({
|
|
112
|
+
* fill: {
|
|
113
|
+
* color: new itowns.THREE.Color(0xffcc00),
|
|
114
|
+
* extrusion_height: () => 5000,
|
|
115
|
+
* }),
|
|
116
|
+
* },
|
|
117
|
+
* },
|
|
111
118
|
* });
|
|
112
119
|
* }).then(function _(features) {
|
|
113
120
|
* ariege.source = new itowns.FileSource({
|
|
@@ -184,6 +184,11 @@ var VectorTilesSource = /*#__PURE__*/function (_TMSSource) {
|
|
|
184
184
|
(0, _get2["default"])((0, _getPrototypeOf2["default"])(VectorTilesSource.prototype), "onLayerAdded", this).call(this, options);
|
|
185
185
|
|
|
186
186
|
if (options.out.style) {
|
|
187
|
+
if (options.out.isFeatureGeometryLayer && options.out.accurate) {
|
|
188
|
+
console.warn('With VectorTilesSource and FeatureGeometryLayer, the accurate option is always false');
|
|
189
|
+
options.out.accurate = false;
|
|
190
|
+
}
|
|
191
|
+
|
|
187
192
|
var keys = Object.keys(this.styles);
|
|
188
193
|
keys.forEach(function (k) {
|
|
189
194
|
_this2.styles[k].parent = options.out.style;
|
package/lib/Source/WFSSource.js
CHANGED
|
@@ -107,10 +107,16 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
107
107
|
* });
|
|
108
108
|
*
|
|
109
109
|
* // Create the layer
|
|
110
|
-
* const geometryLayer = new itowns.
|
|
111
|
-
*
|
|
112
|
-
*
|
|
110
|
+
* const geometryLayer = new itowns.FeatureGeometryLayer('mesh_build', {
|
|
111
|
+
* style: new itowns.Style({
|
|
112
|
+
* fill: {
|
|
113
|
+
* color: new itowns.THREE.Color(0xffcc00),
|
|
114
|
+
* base_altitude: (p) => p.altitude,
|
|
115
|
+
* extrusion_height: (p) => p.height,
|
|
116
|
+
* }
|
|
117
|
+
* },
|
|
113
118
|
* source: wfsSource,
|
|
119
|
+
* zoom: { min: 14 },
|
|
114
120
|
* });
|
|
115
121
|
*
|
|
116
122
|
* // Add the layer
|
|
@@ -5,18 +5,18 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports
|
|
8
|
+
exports["default"] = void 0;
|
|
9
9
|
|
|
10
10
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
11
|
|
|
12
12
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
13
|
|
|
14
|
-
var
|
|
15
|
-
function
|
|
16
|
-
(0, _classCallCheck2["default"])(this,
|
|
14
|
+
var WebGL = /*#__PURE__*/function () {
|
|
15
|
+
function WebGL() {
|
|
16
|
+
(0, _classCallCheck2["default"])(this, WebGL);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
(0, _createClass2["default"])(
|
|
19
|
+
(0, _createClass2["default"])(WebGL, null, [{
|
|
20
20
|
key: "isWebGLAvailable",
|
|
21
21
|
value: function isWebGLAvailable() {
|
|
22
22
|
try {
|
|
@@ -80,7 +80,8 @@ var WEBGL = /*#__PURE__*/function () {
|
|
|
80
80
|
return element;
|
|
81
81
|
}
|
|
82
82
|
}]);
|
|
83
|
-
return
|
|
83
|
+
return WebGL;
|
|
84
84
|
}();
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
var _default = WebGL;
|
|
87
|
+
exports["default"] = _default;
|
|
@@ -1120,7 +1120,7 @@ var GLTFTextureTransformExtension = /*#__PURE__*/function () {
|
|
|
1120
1120
|
/**
|
|
1121
1121
|
* Specular-Glossiness Extension
|
|
1122
1122
|
*
|
|
1123
|
-
* Specification: https://github.com/KhronosGroup/glTF/tree/
|
|
1123
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness
|
|
1124
1124
|
*/
|
|
1125
1125
|
|
|
1126
1126
|
/**
|
|
@@ -1144,7 +1144,7 @@ var GLTFMeshStandardSGMaterial = /*#__PURE__*/function (_MeshStandardMaterial) {
|
|
|
1144
1144
|
|
|
1145
1145
|
var specularMapParsFragmentChunk = ['#ifdef USE_SPECULARMAP', ' uniform sampler2D specularMap;', '#endif'].join('\n');
|
|
1146
1146
|
var glossinessMapParsFragmentChunk = ['#ifdef USE_GLOSSINESSMAP', ' uniform sampler2D glossinessMap;', '#endif'].join('\n');
|
|
1147
|
-
var specularMapFragmentChunk = ['vec3 specularFactor = specular;', '#ifdef USE_SPECULARMAP', ' vec4 texelSpecular = texture2D( specularMap, vUv );', '
|
|
1147
|
+
var specularMapFragmentChunk = ['vec3 specularFactor = specular;', '#ifdef USE_SPECULARMAP', ' vec4 texelSpecular = texture2D( specularMap, vUv );', ' // reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture', ' specularFactor *= texelSpecular.rgb;', '#endif'].join('\n');
|
|
1148
1148
|
var glossinessMapFragmentChunk = ['float glossinessFactor = glossiness;', '#ifdef USE_GLOSSINESSMAP', ' vec4 texelGlossiness = texture2D( glossinessMap, vUv );', ' // reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture', ' glossinessFactor *= texelGlossiness.a;', '#endif'].join('\n');
|
|
1149
1149
|
var lightPhysicalFragmentChunk = ['PhysicalMaterial material;', 'material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );', 'vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );', 'float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );', 'material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.', 'material.roughness += geometryRoughness;', 'material.roughness = min( material.roughness, 1.0 );', 'material.specularColor = specularFactor;'].join('\n');
|
|
1150
1150
|
var uniforms = {
|
|
@@ -1727,7 +1727,7 @@ var GLTFParser = /*#__PURE__*/function () {
|
|
|
1727
1727
|
this.nodeNamesUsed = {}; // Use an ImageBitmapLoader if imageBitmaps are supported. Moves much of the
|
|
1728
1728
|
// expensive work of uploading a texture to the GPU off the main thread.
|
|
1729
1729
|
|
|
1730
|
-
if (typeof createImageBitmap !== 'undefined' && /Firefox
|
|
1730
|
+
if (typeof createImageBitmap !== 'undefined' && /Firefox|^((?!chrome|android).)*safari/i.test(navigator.userAgent) === false) {
|
|
1731
1731
|
this.textureLoader = new _three.ImageBitmapLoader(this.options.manager);
|
|
1732
1732
|
} else {
|
|
1733
1733
|
this.textureLoader = new _three.TextureLoader(this.options.manager);
|
|
@@ -2446,7 +2446,6 @@ var GLTFParser = /*#__PURE__*/function () {
|
|
|
2446
2446
|
|
|
2447
2447
|
materialParams.depthWrite = false;
|
|
2448
2448
|
} else {
|
|
2449
|
-
materialParams.format = _three.RGBFormat;
|
|
2450
2449
|
materialParams.transparent = false;
|
|
2451
2450
|
|
|
2452
2451
|
if (alphaMode === ALPHA_MODES.MASK) {
|
package/lib/Utils/DEMUtils.js
CHANGED
|
@@ -352,10 +352,12 @@ function offsetInExtent(point, extent) {
|
|
|
352
352
|
}
|
|
353
353
|
|
|
354
354
|
function _readZ(layer, method, coord, nodes, cache) {
|
|
355
|
+
var _cache$tile;
|
|
356
|
+
|
|
355
357
|
var pt = coord.as(layer.extent.crs, temp.coord1);
|
|
356
358
|
var tileWithValidElevationTexture = null; // first check in cache
|
|
357
359
|
|
|
358
|
-
if (cache && cache
|
|
360
|
+
if (cache !== null && cache !== void 0 && (_cache$tile = cache.tile) !== null && _cache$tile !== void 0 && _cache$tile.material) {
|
|
359
361
|
tileWithValidElevationTexture = tileAt(pt, cache.tile);
|
|
360
362
|
}
|
|
361
363
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports, "Minimap", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _Minimap["default"];
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(exports, "Navigation", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function get() {
|
|
17
|
+
return _Navigation["default"];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, "Scale", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function get() {
|
|
23
|
+
return _Scale["default"];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(exports, "Searchbar", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function get() {
|
|
29
|
+
return _Searchbar["default"];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
var _Navigation = _interopRequireDefault(require("./Navigation"));
|
|
34
|
+
|
|
35
|
+
var _Minimap = _interopRequireDefault(require("./Minimap"));
|
|
36
|
+
|
|
37
|
+
var _Scale = _interopRequireDefault(require("./Scale"));
|
|
38
|
+
|
|
39
|
+
var _Searchbar = _interopRequireDefault(require("./Searchbar"));
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
+
|
|
12
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
+
|
|
14
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
+
|
|
16
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
17
|
+
|
|
18
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
19
|
+
|
|
20
|
+
var _Coordinates = _interopRequireDefault(require("../../Core/Geographic/Coordinates"));
|
|
21
|
+
|
|
22
|
+
var _MainLoop = require("../../Core/MainLoop");
|
|
23
|
+
|
|
24
|
+
var _PlanarView = _interopRequireDefault(require("../../Core/Prefab/PlanarView"));
|
|
25
|
+
|
|
26
|
+
var _Camera = require("../../Renderer/Camera");
|
|
27
|
+
|
|
28
|
+
var _Widget2 = _interopRequireDefault(require("./Widget"));
|
|
29
|
+
|
|
30
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function () { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
31
|
+
|
|
32
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
33
|
+
|
|
34
|
+
var DEFAULT_OPTIONS = {
|
|
35
|
+
minScale: 1 / 500000,
|
|
36
|
+
maxScale: 1 / 5E8,
|
|
37
|
+
zoomRatio: 1 / 30,
|
|
38
|
+
width: 150,
|
|
39
|
+
height: 150,
|
|
40
|
+
position: 'bottom-left'
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* A widget for minimap
|
|
44
|
+
*
|
|
45
|
+
* To use it, you need to link the widgets' stylesheet to your html webpage. This stylesheet is included in
|
|
46
|
+
* [itowns bundles](https://github.com/iTowns/itowns/releases) if you downloaded them, or it can be found in
|
|
47
|
+
* `node_modules/itowns/examples/css` if you installed iTowns with npm. Otherwise, it can be found at
|
|
48
|
+
* [this link](https://raw.githubusercontent.com/iTowns/itowns/master/examples/css/widgets.css). See
|
|
49
|
+
* [this example](http://www.itowns-project.org/itowns/examples/#widgets_minimap) for more details.
|
|
50
|
+
*
|
|
51
|
+
* @extends Widget
|
|
52
|
+
*
|
|
53
|
+
* @property {HTMLElement} domElement An html div containing the minimap.
|
|
54
|
+
* @property {HTMLElement} parentElement The parent HTML container of `this.domElement`.
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
var Minimap = /*#__PURE__*/function (_Widget) {
|
|
58
|
+
(0, _inherits2["default"])(Minimap, _Widget);
|
|
59
|
+
|
|
60
|
+
var _super = _createSuper(Minimap);
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @param {GlobeView} view The iTowns view the minimap should be
|
|
64
|
+
* linked to. Only {@link GlobeView} is
|
|
65
|
+
* supported at the moment.
|
|
66
|
+
* @param {ColorLayer} layer The {@link ColorLayer} that should be
|
|
67
|
+
* displayed on the minimap.
|
|
68
|
+
* @param {Object} [options] The minimap optional configuration.
|
|
69
|
+
* @param {HTMLElement} [options.parentElement=view.domElement] The parent HTML container of the div
|
|
70
|
+
* which contains minimap widgets.
|
|
71
|
+
* @param {number} [options.size] The size of the minimap. It is a number
|
|
72
|
+
* that describes both width and height
|
|
73
|
+
* in pixels of the minimap.
|
|
74
|
+
* @param {number} [options.width=150] The width in pixels of the minimap.
|
|
75
|
+
* @param {number} [options.height=150] The height in pixels of the minimap.
|
|
76
|
+
* @param {string} [options.position='bottom-left'] Defines which position within the
|
|
77
|
+
* `parentElement` the minimap should be
|
|
78
|
+
* displayed to. Possible values are
|
|
79
|
+
* `top`, `bottom`, `left`, `right`,
|
|
80
|
+
* `top-left`, `top-right`, `bottom-left`
|
|
81
|
+
* and `bottom-right`. If the input value
|
|
82
|
+
* does not match one of these, it will
|
|
83
|
+
* be defaulted to `bottom-left`.
|
|
84
|
+
* @param {Object} [options.translate] An optional translation of the minimap.
|
|
85
|
+
* @param {number} [options.translate.x=0] The minimap translation along the page
|
|
86
|
+
* x-axis.
|
|
87
|
+
* @param {number} [options.translate.y=0] The minimap translation along the page
|
|
88
|
+
* y-axis.
|
|
89
|
+
* @param {HTMLElement|string} [options.cursor] An html element or an HTML string
|
|
90
|
+
* describing a cursor showing minimap
|
|
91
|
+
* view camera target position at the
|
|
92
|
+
* center of the minimap.
|
|
93
|
+
* @param {number} [options.minScale=1/2000] The minimal scale the minimap can reach.
|
|
94
|
+
* @param {number} [options.maxScale=1/1_250_000] The maximal scale the minimap can reach.
|
|
95
|
+
* @param {number} [options.zoomRatio=1/30] The ratio between minimap camera zoom
|
|
96
|
+
* and view camera zoom.
|
|
97
|
+
* @param {number} [options.pitch=0.28] The screen pixel pitch, used to compute
|
|
98
|
+
* view and minimap scale.
|
|
99
|
+
*/
|
|
100
|
+
function Minimap(view, layer) {
|
|
101
|
+
var _this;
|
|
102
|
+
|
|
103
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
104
|
+
(0, _classCallCheck2["default"])(this, Minimap);
|
|
105
|
+
|
|
106
|
+
// ---------- BUILD PROPERTIES ACCORDING TO DEFAULT OPTIONS AND OPTIONS PASSED IN PARAMETERS : ----------
|
|
107
|
+
if (!view.isGlobeView) {
|
|
108
|
+
throw new Error('\'Minimap\' plugin only supports \'GlobeView\'. Therefore, the \'view\' parameter must be a ' + '\'GlobeView\'.');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (!layer.isColorLayer) {
|
|
112
|
+
throw new Error('\'layer\' parameter form \'Minimap\' constructor should be a \'ColorLayer\'.');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
_this = _super.call(this, view, options, DEFAULT_OPTIONS);
|
|
116
|
+
_this.minScale = options.minScale || DEFAULT_OPTIONS.minScale;
|
|
117
|
+
_this.maxScale = options.maxScale || DEFAULT_OPTIONS.maxScale; // TODO : it could be interesting to be able to specify a method as zoomRatio parameter. This method could
|
|
118
|
+
// return a zoom ratio from the scale of the minimap.
|
|
119
|
+
|
|
120
|
+
_this.zoomRatio = options.zoomRatio || DEFAULT_OPTIONS.zoomRatio; // ---------- this.domElement SETTINGS SPECIFIC TO MINIMAP : ----------
|
|
121
|
+
|
|
122
|
+
_this.domElement.id = 'widgets-minimap'; // Display a cursor at the center of the minimap, if requested.
|
|
123
|
+
|
|
124
|
+
if (options.cursor) {
|
|
125
|
+
// Wrap cursor domElement inside a div to center it in minimap.
|
|
126
|
+
var cursorWrapper = document.createElement('div');
|
|
127
|
+
cursorWrapper.id = 'cursor-wrapper';
|
|
128
|
+
|
|
129
|
+
_this.domElement.appendChild(cursorWrapper); // Add specified cursor to its wrapper.
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
if (typeof options.cursor === 'string') {
|
|
133
|
+
cursorWrapper.innerHTML = options.cursor;
|
|
134
|
+
} else if (options.cursor instanceof HTMLElement) {
|
|
135
|
+
cursorWrapper.appendChild(options.cursor);
|
|
136
|
+
}
|
|
137
|
+
} // ---------- CREATE A MINIMAP View AND DISPLAY DATA PASSED IN Layer PARAMETER : ----------
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
_this.view = new _PlanarView["default"](_this.domElement, layer.source.extent, {
|
|
141
|
+
camera: {
|
|
142
|
+
type: _Camera.CAMERA_TYPE.ORTHOGRAPHIC
|
|
143
|
+
},
|
|
144
|
+
placement: layer.source.extent,
|
|
145
|
+
// TODO : the default placement should be the view extent for ortho camera
|
|
146
|
+
noControls: true,
|
|
147
|
+
maxSubdivisionLevel: view.tileLayer.maxSubdivisionLevel,
|
|
148
|
+
disableFocusOnStart: true
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
_this.view.addLayer(layer); // TODO : should this promise be returned by constructor so that user can use it ?
|
|
152
|
+
// Prevent the minimap domElement to get focus when clicked, and prevent click event to be propagated to the
|
|
153
|
+
// main view controls.
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
_this.domElement.addEventListener('pointerdown', function (event) {
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
}); // Store minimap view camera3D in constant for code convenience.
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
var camera3D = _this.view.camera.camera3D; // ---------- UPDATE MINIMAP VIEW WHEN UPDATING THE MAIN VIEW : ----------
|
|
162
|
+
// The minimal and maximal value the minimap camera3D zoom can reach in order to stay in the scale limits.
|
|
163
|
+
|
|
164
|
+
var initialScale = _this.view.getScale(options.pitch);
|
|
165
|
+
|
|
166
|
+
var minZoom = camera3D.zoom * _this.maxScale / initialScale;
|
|
167
|
+
var maxZoom = camera3D.zoom * _this.minScale / initialScale; // Coordinates used to transform position vectors from the main view CRS to the minimap view CRS.
|
|
168
|
+
|
|
169
|
+
var mainViewCoordinates = new _Coordinates["default"](view.referenceCrs);
|
|
170
|
+
var viewCoordinates = new _Coordinates["default"](_this.view.referenceCrs);
|
|
171
|
+
var targetPosition = view.controls.getCameraTargetPosition();
|
|
172
|
+
view.addFrameRequester(_MainLoop.MAIN_LOOP_EVENTS.AFTER_RENDER, function () {
|
|
173
|
+
// Update minimap camera zoom
|
|
174
|
+
var distance = view.camera.camera3D.position.distanceTo(targetPosition);
|
|
175
|
+
var scale = view.getScaleFromDistance(options.pitch, distance);
|
|
176
|
+
camera3D.zoom = _this.zoomRatio * maxZoom * scale / _this.minScale;
|
|
177
|
+
camera3D.zoom = Math.min(Math.max(camera3D.zoom, minZoom), maxZoom);
|
|
178
|
+
camera3D.updateProjectionMatrix(); // Update minimap camera position.
|
|
179
|
+
|
|
180
|
+
mainViewCoordinates.setFromVector3(view.controls.getCameraTargetPosition());
|
|
181
|
+
mainViewCoordinates.as(_this.view.referenceCrs, viewCoordinates);
|
|
182
|
+
camera3D.position.x = viewCoordinates.x;
|
|
183
|
+
camera3D.position.y = viewCoordinates.y;
|
|
184
|
+
camera3D.updateMatrixWorld(true);
|
|
185
|
+
|
|
186
|
+
_this.view.notifyChange(camera3D);
|
|
187
|
+
});
|
|
188
|
+
return _this;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return (0, _createClass2["default"])(Minimap);
|
|
192
|
+
}(_Widget2["default"]);
|
|
193
|
+
|
|
194
|
+
var _default = Minimap;
|
|
195
|
+
exports["default"] = _default;
|