Add generic map type config for maps that can be handled by simple URL pattern substitution.

This commit is contained in:
Oliver Jowett 2015-10-26 12:59:38 +00:00
parent 482d3a1d38
commit f8a3c46139
2 changed files with 33 additions and 13 deletions

View file

@ -40,6 +40,20 @@ SiteLon = 9.0;
SiteName = "My Radar Site"; // tooltip of the marker SiteName = "My Radar Site"; // tooltip of the marker
// Extra map types to include. These work for maps with 256x256 tiles where a
// URL can be constructed by simple substition of x/y tile number and zoom level
var ExtraMapTypes = {
'OpenStreetMap' : 'http://tile.openstreetmap.org/{z}/{x}/{y}.png',
// NB: the following generally only cover the US
'Sectional Charts' : 'http://wms.chartbundle.com/tms/1.0.0/sec/{z}/{x}/{y}.png?origin=nw',
'Terminal Charts' : 'http://wms.chartbundle.com/tms/1.0.0/tac/{z}/{x}/{y}.png?origin=nw',
'World Charts' : 'http://wms.chartbundle.com/tms/1.0.0/wac/{z}/{x}/{y}.png?origin=nw',
'IFR Low Charts' : 'http://wms.chartbundle.com/tms/1.0.0/enrl/{z}/{x}/{y}.png?origin=nw',
'IFR Area Charts' : 'http://wms.chartbundle.com/tms/1.0.0/enra/{z}/{x}/{y}.png?origin=nw',
'IFR High Charts' : 'http://wms.chartbundle.com/tms/1.0.0/enrh/{z}/{x}/{y}.png?origin=nw'
};
// -- Marker settings ------------------------------------- // -- Marker settings -------------------------------------
// These settings control the coloring of aircraft by altitude. // These settings control the coloring of aircraft by altitude.

View file

@ -306,6 +306,10 @@ function end_load_history() {
} }
function generic_gettile(template, coord, zoom) {
return template.replace('{x}', coord.x).replace('{y}', coord.y).replace('{z}', zoom)
}
// Initalizes the map and starts up our timers to call various functions // Initalizes the map and starts up our timers to call various functions
function initialize_map() { function initialize_map() {
// Load stored map settings if present // Load stored map settings if present
@ -336,10 +340,13 @@ function initialize_map() {
for(var type in google.maps.MapTypeId) { for(var type in google.maps.MapTypeId) {
mapTypeIds.push(google.maps.MapTypeId[type]); mapTypeIds.push(google.maps.MapTypeId[type]);
} }
// Push OSM on to the end
mapTypeIds.push("OSM");
mapTypeIds.push("dark_map"); mapTypeIds.push("dark_map");
for (var type in ExtraMapTypes) {
mapTypeIds.push(type);
}
// Styled Map to outline airports and highways // Styled Map to outline airports and highways
var styles = [ var styles = [
{ {
@ -423,18 +430,17 @@ function initialize_map() {
}; };
GoogleMap = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); GoogleMap = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
GoogleMap.mapTypes.set("dark_map", styledMap);
//Define OSM map type pointing at the OpenStreetMap tile server // Define the extra map types
GoogleMap.mapTypes.set("OSM", new google.maps.ImageMapType({ for (var type in ExtraMapTypes) {
getTileUrl: function(coord, zoom) { GoogleMap.mapTypes.set(type, new google.maps.ImageMapType({
return "http://tile.openstreetmap.org/" + zoom + "/" + coord.x + "/" + coord.y + ".png"; getTileUrl: generic_gettile.bind(null, ExtraMapTypes[type]),
},
tileSize: new google.maps.Size(256, 256), tileSize: new google.maps.Size(256, 256),
name: "OpenStreetMap", name: type,
maxZoom: 18 maxZoom: 18
})); }));
}
GoogleMap.mapTypes.set("dark_map", styledMap);
// Listeners for newly created Map // Listeners for newly created Map
google.maps.event.addListener(GoogleMap, 'center_changed', function() { google.maps.event.addListener(GoogleMap, 'center_changed', function() {