Skip to content
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
24 changes: 12 additions & 12 deletions examples/BasicExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
* Illustrates how to build a basic WorldWind globe.
*/
requirejs(['./WorldWindShim',
'./LayerManager'],
'./LayerManager'],
function (WorldWind,
LayerManager) {
LayerManager) {
"use strict";

// Tell WorldWind to log only warnings and errors.
Expand All @@ -43,18 +43,18 @@ requirejs(['./WorldWindShim',
// Create and add layers to the WorldWindow.
var layers = [
// Imagery layers.
{layer: new WorldWind.BMNGLayer(), enabled: true},
{layer: new WorldWind.BMNGLandsatLayer(), enabled: false},
{layer: new WorldWind.BingAerialLayer(null), enabled: false},
{layer: new WorldWind.BingAerialWithLabelsLayer(null), enabled: true},
{layer: new WorldWind.BingRoadsLayer(null), enabled: false},
{layer: new WorldWind.OpenStreetMapImageLayer(null), enabled: false},
{ layer: new WorldWind.BMNGLayer(), enabled: true },
{ layer: new WorldWind.BMNGLandsatLayer(), enabled: false },
// {layer: new WorldWind.BingAerialLayer(null), enabled: false},
// {layer: new WorldWind.BingAerialWithLabelsLayer(null), enabled: true},
// {layer: new WorldWind.BingRoadsLayer(null), enabled: false},
{ layer: new WorldWind.OpenStreetMapImageLayer("osm"), enabled: true },
// Add atmosphere layer on top of all base layers.
{layer: new WorldWind.AtmosphereLayer(), enabled: true},
{ layer: new WorldWind.AtmosphereLayer(), enabled: true },
// WorldWindow UI layers.
{layer: new WorldWind.CompassLayer(), enabled: true},
{layer: new WorldWind.CoordinatesDisplayLayer(wwd), enabled: true},
{layer: new WorldWind.ViewControlsLayer(wwd), enabled: true}
{ layer: new WorldWind.CompassLayer(), enabled: true },
{ layer: new WorldWind.CoordinatesDisplayLayer(wwd), enabled: true },
{ layer: new WorldWind.ViewControlsLayer(wwd), enabled: true }
];

for (var l = 0; l < layers.length; l++) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"url": "https://github.com/NASAWorldWind/WebWorldWind.git"
},
"scripts": {
"build": "grunt",
"build": "npm run check-version && grunt",
"check-version": "node tools/versioncheck.js",
"clean": "grunt clean",
"doc": "grunt jsdoc",
"prepare": "npm run build",
Expand Down
3 changes: 1 addition & 2 deletions src/WorldWind.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,9 @@ define([ // PLEASE KEEP ALL THIS IN ALPHABETICAL ORDER BY MODULE NAME (not direc
var WorldWind = {
/**
* The WorldWind version number.
* @default "0.9.0"
* @constant
*/
VERSION: "0.9.0",
VERSION: "0.11.0",

// PLEASE KEEP THE ENTRIES BELOW IN ALPHABETICAL ORDER
/**
Expand Down
97 changes: 17 additions & 80 deletions src/layer/OpenStreetMapImageLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@
* @exports OpenStreetMapImageLayer
*/
define([
'../util/Color',
'../layer/Layer',
'../util/Logger',
'../ogc/wmts/WmtsCapabilities',
'../layer/WmtsLayer'
],
function (Color,
Layer,
Logger,
WmtsCapabilities,
WmtsLayer) {
'../geom/Location',
'../geom/Sector',
'../layer/TiledImageLayer',
'../util/WmsUrlBuilder'
],
function (Location,
Sector,
TiledImageLayer,
WmsUrlBuilder) {
"use strict";

/**
Expand All @@ -52,79 +50,18 @@ define([
* @param {String} displayName This layer's display name. "Open Street Map" if this parameter is
* null or undefined.
*/
var OpenStreetMapImageLayer = function (displayName) {
var OpenStreetMapImageLayer = function (layerName) {
TiledImageLayer.call(this,
Sector.FULL_SPHERE, new Location(36, 36), 16, "image/jpeg", "OpenStreetMap-" + layerName, 256, 256);

Layer.call(this, this.displayName);
this.displayName = "OpenStreetMap";
this.pickEnabled = false;

this.displayName = displayName || "Open Street Map";

this.layer = null;

this.xhr = null;

// TODO: Picking is enabled as a temporary measure for screen credit hyperlinks to work (see Layer.render)
this.pickEnabled = true;
};

OpenStreetMapImageLayer.prototype = Object.create(Layer.prototype);

OpenStreetMapImageLayer.prototype.doRender = function (dc) {

this.configureLayer(dc);

if (this.layer) {
this.layer.opacity = this.opacity;
this.layer.doRender(dc);
this.inCurrentFrame = this.layer.inCurrentFrame;

// Add a screen credit to attribute the data source to OSM and EOX
// The pattern for this attribute is described in the WMTS Capabilities document and demonstrated at EOX
// Maps site: http://maps.eox.at/
if (this.inCurrentFrame) {
dc.screenCreditController.addCredit("OpenStreetMap ©", Color.DARK_GRAY);
dc.screenCreditController.addCredit("EOX.at ©", Color.DARK_GRAY);
}
}
this.urlBuilder = new WmsUrlBuilder("https://worldwind47.arc.nasa.gov/mapcache",
layerName, "", "1.3.0");
};

OpenStreetMapImageLayer.prototype.configureLayer = function (dc) {
if (!this.xhr) {
var self = this;
var canvas = dc.currentGlContext.canvas;
this.xhr = new XMLHttpRequest();
this.xhr.open("GET", "https://tiles.maps.eox.at/wmts/1.0.0/WMTSCapabilities.xml", true);
this.xhr.onreadystatechange = function () {
if (self.xhr.readyState === 4) {
if (self.xhr.status === 200) {
// Create a layer from the WMTS capabilities.
var wmtsCapabilities = new WmtsCapabilities(self.xhr.responseXML);
var wmtsLayerCapabilities = wmtsCapabilities.getLayer("osm");
var wmtsConfig = WmtsLayer.formLayerConfiguration(wmtsLayerCapabilities);
wmtsConfig.title = self.displayName;
self.layer = new WmtsLayer(wmtsConfig);
// Send an event to request a redraw.
var e = document.createEvent('Event');
e.initEvent(WorldWind.REDRAW_EVENT_TYPE, true, true);
canvas.dispatchEvent(e);
} else {
Logger.log(Logger.LEVEL_WARNING,
"OSM retrieval failed (" + xhr.statusText + "): " + url);
}
}
};

this.xhr.onerror = function () {
Logger.log(Logger.LEVEL_WARNING, "OSM retrieval failed: " + url);
};

this.xhr.ontimeout = function () {
Logger.log(Logger.LEVEL_WARNING, "OSM retrieval timed out: " + url);
};

this.xhr.send(null);
}

};
OpenStreetMapImageLayer.prototype = Object.create(TiledImageLayer.prototype);

return OpenStreetMapImageLayer;
}
Expand Down
48 changes: 48 additions & 0 deletions tools/versioncheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const fs = require('fs');
const path = require('path');

// Path to the project root from the script's location
const projectRoot = path.resolve(__dirname, '..');

function getVersionFromPackageJson() {
try {
const packageJsonPath = path.join(projectRoot, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
console.log(`Version number in package.json is: ${packageJson.version}`);
return packageJson.version;
} catch (error) {
console.error(`An error occurred while reading or parsing package.json: ${error.message}`);
process.exit(1);
}
}

function getVersionFromJsFile(filePath) {
try {
const jsFilePath = path.join(projectRoot, filePath);
const jsFileContent = fs.readFileSync(jsFilePath, 'utf8');
const regex = /VERSION:\s*"([^"]+)"/;
Copy link

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern is tightly coupled to a specific format with double quotes. Consider making it more flexible to handle both single and double quotes: /VERSION:\s*["']([^"']+)["']/

Suggested change
const regex = /VERSION:\s*"([^"]+)"/;
const regex = /VERSION:\s*["']([^"']+)["']/;

Copilot uses AI. Check for mistakes.
const match = regex.exec(jsFileContent);
if (!match) {
console.error(`Version number not found in ${filePath}`);
process.exit(1);
}
console.log(`Version number in ${filePath} is: ${match[1]}`);
return match[1];
} catch (error) {
console.error(`An error occurred while reading ${filePath}: ${error.message}`);
process.exit(1);
}
}

function compareVersions(version1, version2) {
if (version1 === version2) {
console.log('Version numbers are consistent between package.json and WorldWind.js');
} else {
console.error(`ERROR: Version numbers do not match between package.json and WorldWind.js`);
process.exit(1);
}
}

const packageVersion = getVersionFromPackageJson();
const jsWorldWindVersion = getVersionFromJsFile('src/WorldWind.js');
compareVersions(packageVersion, jsWorldWindVersion);
Comment on lines +37 to +48
Copy link

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The success message hardcodes 'WorldWind.js' but the function accepts any file path. Consider using the actual file path parameter: console.log('Version numbers are consistent between package.json and ${filePath}');

Suggested change
function compareVersions(version1, version2) {
if (version1 === version2) {
console.log('Version numbers are consistent between package.json and WorldWind.js');
} else {
console.error(`ERROR: Version numbers do not match between package.json and WorldWind.js`);
process.exit(1);
}
}
const packageVersion = getVersionFromPackageJson();
const jsWorldWindVersion = getVersionFromJsFile('src/WorldWind.js');
compareVersions(packageVersion, jsWorldWindVersion);
function compareVersions(version1, version2, filePath) {
if (version1 === version2) {
console.log(`Version numbers are consistent between package.json and ${filePath}`);
} else {
console.error(`ERROR: Version numbers do not match between package.json and ${filePath}`);
process.exit(1);
}
}
const packageVersion = getVersionFromPackageJson();
const jsFilePath = 'src/WorldWind.js';
const jsWorldWindVersion = getVersionFromJsFile(jsFilePath);
compareVersions(packageVersion, jsWorldWindVersion, jsFilePath);

Copilot uses AI. Check for mistakes.
Comment on lines +37 to +48
Copy link

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the success message, the error message hardcodes 'WorldWind.js'. Since compareVersions doesn't know which file was checked, consider passing the file path as a parameter or restructuring the comparison logic.

Suggested change
function compareVersions(version1, version2) {
if (version1 === version2) {
console.log('Version numbers are consistent between package.json and WorldWind.js');
} else {
console.error(`ERROR: Version numbers do not match between package.json and WorldWind.js`);
process.exit(1);
}
}
const packageVersion = getVersionFromPackageJson();
const jsWorldWindVersion = getVersionFromJsFile('src/WorldWind.js');
compareVersions(packageVersion, jsWorldWindVersion);
function compareVersions(version1, version2, jsFilePath) {
if (version1 === version2) {
console.log(`Version numbers are consistent between package.json and ${jsFilePath}`);
} else {
console.error(`ERROR: Version numbers do not match between package.json and ${jsFilePath}`);
process.exit(1);
}
}
const packageVersion = getVersionFromPackageJson();
const jsFilePath = 'src/WorldWind.js';
const jsWorldWindVersion = getVersionFromJsFile(jsFilePath);
compareVersions(packageVersion, jsWorldWindVersion, jsFilePath);

Copilot uses AI. Check for mistakes.