| Conditions | 1 |
| Paths | 2 |
| Total Lines | 123 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /*! |
||
| 9 | function CesiumMiniMap(parentViewer, options) { |
||
| 10 | 'use strict'; |
||
| 11 | |||
| 12 | options = options || {}; |
||
| 13 | var expanded = options.expanded || true; |
||
| 14 | var _viewer, _container, _toggleButton; |
||
| 15 | |||
| 16 | var CESIUM_OPTS = { |
||
| 17 | animation: false, |
||
| 18 | baseLayerPicker: false, |
||
| 19 | fullscreenButton: false, |
||
| 20 | geocoder: false, |
||
| 21 | homeButton: false, |
||
| 22 | infoBox: false, |
||
| 23 | sceneModePicker: false, |
||
| 24 | selectionIndicator: false, |
||
| 25 | timeline: false, |
||
| 26 | navigationHelpButton: false, |
||
| 27 | navigationInstructionsInitiallyVisible: false, |
||
| 28 | orderIndependentTranslucency: false, |
||
| 29 | sceneMode: Cesium.SceneMode.SCENE2D, |
||
|
|
|||
| 30 | mapProjection: new Cesium.WebMercatorProjection() |
||
| 31 | }; |
||
| 32 | |||
| 33 | function _getContainer() { |
||
| 34 | var parentDiv = document.createElement('div'); |
||
| 35 | parentDiv.className = 'cesium-minimap'; |
||
| 36 | parentViewer.bottomContainer.appendChild(parentDiv); |
||
| 37 | return parentDiv; |
||
| 38 | } |
||
| 39 | |||
| 40 | function _addLayer(layer) { |
||
| 41 | _viewer.imageryLayers.addImageryProvider(layer.imageryProvider); |
||
| 42 | } |
||
| 43 | |||
| 44 | function _setupMap(div) { |
||
| 45 | |||
| 46 | CESIUM_OPTS.creditContainer = document.createElement('div'); |
||
| 47 | |||
| 48 | var miniviewer = new Cesium.Viewer(div, CESIUM_OPTS); |
||
| 49 | miniviewer.scene.imageryLayers.removeAll(); |
||
| 50 | |||
| 51 | var miniscene = miniviewer.scene; |
||
| 52 | miniscene.screenSpaceCameraController.enableRotate = false; |
||
| 53 | miniscene.screenSpaceCameraController.enableTranslate = false; |
||
| 54 | miniscene.screenSpaceCameraController.enableZoom = false; |
||
| 55 | miniscene.screenSpaceCameraController.enableTilt = false; |
||
| 56 | miniscene.screenSpaceCameraController.enableLook = false; |
||
| 57 | |||
| 58 | parentViewer.scene.imageryLayers.layerAdded.addEventListener(_addLayer); |
||
| 59 | |||
| 60 | var pos = parentViewer.scene.camera.positionCartographic; |
||
| 61 | pos.height = 22000000.0; |
||
| 62 | miniviewer.scene.camera.setView({ |
||
| 63 | destination: Cesium.Ellipsoid.WGS84.cartographicToCartesian(pos), |
||
| 64 | }); |
||
| 65 | |||
| 66 | _viewer = miniviewer; |
||
| 67 | } |
||
| 68 | |||
| 69 | function _setupListener() { |
||
| 70 | var minicamera = _viewer.scene.camera; |
||
| 71 | var parentCamera = parentViewer.scene.camera; |
||
| 72 | parentCamera.moveEnd.addEventListener(function () { |
||
| 73 | var pos = parentCamera.positionCartographic; |
||
| 74 | pos.height = Math.max(Math.min(pos.height,11000000) * 2, 100000); |
||
| 75 | minicamera.setView({ |
||
| 76 | destination: Cesium.Ellipsoid.WGS84.cartographicToCartesian(pos), |
||
| 77 | orientation: { |
||
| 78 | heading : parentCamera.heading, |
||
| 79 | pitch : parentCamera.pitch |
||
| 80 | } |
||
| 81 | }); |
||
| 82 | }); |
||
| 83 | } |
||
| 84 | |||
| 85 | function _toggle() { |
||
| 86 | expanded = !expanded; |
||
| 87 | |||
| 88 | if (expanded) { |
||
| 89 | _container.style.width = '150px'; |
||
| 90 | _container.style.height = '150px'; |
||
| 91 | _toggleButton.className = _toggleButton.className.replace( |
||
| 92 | ' minimized', |
||
| 93 | '' |
||
| 94 | ); |
||
| 95 | } else { |
||
| 96 | //close |
||
| 97 | _container.style.width = '19px'; |
||
| 98 | _container.style.height = '19px'; |
||
| 99 | _toggleButton.className += ' minimized'; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | function _createToggleButton() { |
||
| 104 | var btn = document.createElement('a'); |
||
| 105 | btn.className = 'minimap-toggle-display'; |
||
| 106 | btn.onclick = function (e) { |
||
| 107 | e.preventDefault(); |
||
| 108 | _toggle(); |
||
| 109 | return false; |
||
| 110 | }; |
||
| 111 | return btn; |
||
| 112 | } |
||
| 113 | |||
| 114 | |||
| 115 | function init() { |
||
| 116 | var div = document.createElement('div'); |
||
| 117 | div.className = 'minimap-container'; |
||
| 118 | |||
| 119 | _container = _getContainer(); |
||
| 120 | _container.appendChild(div); |
||
| 121 | _toggleButton = _createToggleButton(); |
||
| 122 | _container.appendChild(_toggleButton); |
||
| 123 | _setupMap(div); |
||
| 124 | _setupListener(); |
||
| 125 | if (parentViewer.imageryLayers.length) { |
||
| 126 | _addLayer(parentViewer.imageryLayers.get(0)); |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 130 | init(); |
||
| 131 | } |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.