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,19 +430,18 @@ function initialize_map() {
}; };
GoogleMap = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); GoogleMap = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
//Define OSM map type pointing at the OpenStreetMap tile server
GoogleMap.mapTypes.set("OSM", new google.maps.ImageMapType({
getTileUrl: function(coord, zoom) {
return "http://tile.openstreetmap.org/" + zoom + "/" + coord.x + "/" + coord.y + ".png";
},
tileSize: new google.maps.Size(256, 256),
name: "OpenStreetMap",
maxZoom: 18
}));
GoogleMap.mapTypes.set("dark_map", styledMap); GoogleMap.mapTypes.set("dark_map", styledMap);
// Define the extra map types
for (var type in ExtraMapTypes) {
GoogleMap.mapTypes.set(type, new google.maps.ImageMapType({
getTileUrl: generic_gettile.bind(null, ExtraMapTypes[type]),
tileSize: new google.maps.Size(256, 256),
name: type,
maxZoom: 18
}));
}
// 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() {
localStorage['CenterLat'] = GoogleMap.getCenter().lat(); localStorage['CenterLat'] = GoogleMap.getCenter().lat();