WebWorldWind/examples/Measurements.js
Endia Irizarry ca3f7f68b5 Move layer manager to the end of examples from Annotations to ParseURL (#727)
* Add issue template for submitting issues

* Add pull request template

* Change "Note:" in pull request template

* Change "Note:" in pull request template

* Add CONTRIBUTING.md

- This CONTRIBUTING.md replaces "HowToContribute.md". The content in "HowToContribute.md" replaced, but merely ported to the new CONTRIBUTING.md.
- This document explains the expectations for contributing to the Web WorldWind repository. It includes information on how to submit a bug report, new feature suggestion, or a pull request.
- It also guides the user on the appropriate way to contact the WorldWind team with questions.

* Move contributing list under correct heading.

The list to contributing to Web WorldWind (reporting a bug, suggesting a new feature, creating a pull request) was under the wrong heading (Asking Questions). It is now under Contributing.

* Fix spacing

* Add bullet points

* Update CONTRIBUTING.md

Add bullet points to table of contents.

* Update CONTRIBUTING.md

- Deleted the opening sentences which offer an invitation to change WorldWind standards.
- Add Resources content about the WorldWind website, forum, and administrative contact.

* Fix spacing in CONTRIBUTING.md

- Fixed spacing in the last lines of CONTRIBUTING.md so that they are double-spaced.

* Fix email link in CONTRIBUTING.md

* Change "World Wind" to "WorldWind"

* Add layer manager to the end of examples
2018-06-04 15:34:08 -05:00

95 lines
3.9 KiB
JavaScript

/*
* Copyright 2015-2017 WorldWind Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Illustrates how to measure distances and areas.
*/
requirejs([
'./LayerManager',
'./WorldWindShim'
],
function (LayerManager,
WorldWind) {
'use strict';
var calcBtn = document.getElementById('calc');
calcBtn.addEventListener('click', doCalc, false);
var geoDistSpan = document.getElementById('geo-dist');
var distSpan = document.getElementById('dist');
var terrainDistSpan = document.getElementById('terrain-dist');
var projectedAreaSpan = document.getElementById('projected-area');
var terrainAreaSpan = document.getElementById('terrain-area');
// Tell WorldWind to log only warnings and errors.
WorldWind.Logger.setLoggingLevel(WorldWind.Logger.LEVEL_WARNING);
// Create the WorldWinow.
var wwd = new WorldWind.WorldWindow('canvasOne');
// Create and add layers to the WorldWindow.
// Imagery layers.
var BNMGLayer = new WorldWind.BMNGLayer();
var AtmosphereLayer = new WorldWind.AtmosphereLayer();
var pathLayer = new WorldWind.RenderableLayer('Path');
// WorldWindow UI layer.
var CoordinatesDisplayLayer = new WorldWind.CoordinatesDisplayLayer(wwd);
wwd.addLayer(BNMGLayer);
// Add atmosphere layer on top of base imagery layer.
wwd.addLayer(AtmosphereLayer);
wwd.addLayer(pathLayer);
wwd.addLayer(CoordinatesDisplayLayer);
var pathPositions = [
new WorldWind.Position(41.8267, -98.7686, 0),
new WorldWind.Position(32.6658, -99.6049, 0),
new WorldWind.Position(34.1708, -111.0846, 0),
new WorldWind.Position(42.7502, -111.0705, 0),
new WorldWind.Position(41.8267, -98.7686, 0)
];
var pathAttributes = new WorldWind.ShapeAttributes(null);
pathAttributes.outlineColor = WorldWind.Color.BLUE;
pathAttributes.interiorColor = new WorldWind.Color(0, 1, 1, 0.5);
var path = new WorldWind.Path(pathPositions, pathAttributes);
path.altitudeMode = WorldWind.CLAMP_TO_GROUND;
path.followTerrain = true;
pathLayer.addRenderable(path);
wwd.redraw();
var lengthMeasurer = new WorldWind.LengthMeasurer(wwd);
var areaMeasurer = new WorldWind.AreaMeasurer(wwd);
function doCalc() {
var distance = lengthMeasurer.getLength(pathPositions, false, WorldWind.GREAT_CIRCLE);
var terrainDistance = lengthMeasurer.getLength(pathPositions, true, WorldWind.GREAT_CIRCLE);
var geographicDistance = lengthMeasurer.getGeographicDistance(pathPositions, WorldWind.GREAT_CIRCLE);
var area = areaMeasurer.getArea(pathPositions, false);
var terrainArea = areaMeasurer.getArea(pathPositions, true);
geoDistSpan.textContent = (geographicDistance / 1e3).toFixed(3);
distSpan.textContent = (distance / 1e3).toFixed(3);
terrainDistSpan.textContent = (terrainDistance / 1e3).toFixed(3);
projectedAreaSpan.textContent = (area / 1e6).toFixed(3);
terrainAreaSpan.textContent = (terrainArea / 1e6).toFixed(3);
}
// Create a layer manager for controlling layer visibility.
var layerManager = new LayerManager(wwd);
});