| 1 |
// -*- mode: javascript; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
| 2 |
"use strict"; |
| 3 |
|
| 4 |
// Base layers configuration |
| 5 |
|
| 6 |
function createBaseLayers() { |
| 7 |
var layers = []; |
| 8 |
|
| 9 |
var world = []; |
| 10 |
var us = []; |
| 11 |
|
| 12 |
world.push(new ol.layer.Tile({ |
| 13 |
source: new ol.source.OSM(), |
| 14 |
name: 'osm', |
| 15 |
title: 'OpenStreetMap', |
| 16 |
type: 'base', |
| 17 |
})); |
| 18 |
|
| 19 |
if (BingMapsAPIKey) { |
| 20 |
world.push(new ol.layer.Tile({ |
| 21 |
source: new ol.source.BingMaps({ |
| 22 |
key: BingMapsAPIKey, |
| 23 |
imagerySet: 'Aerial' |
| 24 |
}), |
| 25 |
name: 'bing_aerial', |
| 26 |
title: 'Bing Aerial', |
| 27 |
type: 'base', |
| 28 |
})); |
| 29 |
world.push(new ol.layer.Tile({ |
| 30 |
source: new ol.source.BingMaps({ |
| 31 |
key: BingMapsAPIKey, |
| 32 |
imagerySet: 'Road' |
| 33 |
}), |
| 34 |
name: 'bing_roads', |
| 35 |
title: 'Bing Roads', |
| 36 |
type: 'base', |
| 37 |
})); |
| 38 |
} |
| 39 |
|
| 40 |
if (MapzenAPIKey) { |
| 41 |
world.push(createMapzenLayer()); |
| 42 |
} |
| 43 |
|
| 44 |
if (ChartBundleLayers) { |
| 45 |
var chartbundleTypes = { |
| 46 |
sec: "Sectional Charts", |
| 47 |
tac: "Terminal Area Charts", |
| 48 |
hel: "Helicopter Charts", |
| 49 |
enrl: "IFR Enroute Low Charts", |
| 50 |
enra: "IFR Area Charts", |
| 51 |
enrh: "IFR Enroute High Charts" |
| 52 |
}; |
| 53 |
|
| 54 |
for (var type in chartbundleTypes) { |
| 55 |
us.push(new ol.layer.Tile({ |
| 56 |
source: new ol.source.TileWMS({ |
| 57 |
url: 'http://wms.chartbundle.com/wms', |
| 58 |
params: {LAYERS: type}, |
| 59 |
projection: 'EPSG:3857', |
| 60 |
attributions: 'Tiles courtesy of <a href="http://www.chartbundle.com/">ChartBundle</a>' |
| 61 |
}), |
| 62 |
name: 'chartbundle_' + type, |
| 63 |
title: chartbundleTypes[type], |
| 64 |
type: 'base', |
| 65 |
group: 'chartbundle'})); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
var nexrad = new ol.layer.Tile({ |
| 70 |
name: 'nexrad', |
| 71 |
title: 'NEXRAD', |
| 72 |
type: 'overlay', |
| 73 |
opacity: 0.5, |
| 74 |
visible: false |
| 75 |
}); |
| 76 |
us.push(nexrad); |
| 77 |
|
| 78 |
var refreshNexrad = function() { |
| 79 |
// re-build the source to force a refresh of the nexrad tiles |
| 80 |
var now = new Date().getTime(); |
| 81 |
nexrad.setSource(new ol.source.XYZ({ |
| 82 |
url : 'http://mesonet{1-3}.agron.iastate.edu/cache/tile.py/1.0.0/nexrad-n0q-900913/{z}/{x}/{y}.png?_=' + now, |
| 83 |
attributions: 'NEXRAD courtesy of <a href="http://mesonet.agron.iastate.edu/">IEM</a>' |
| 84 |
})); |
| 85 |
}; |
| 86 |
|
| 87 |
refreshNexrad(); |
| 88 |
window.setInterval(refreshNexrad, 5 * 60000); |
| 89 |
|
| 90 |
if (world.length > 0) { |
| 91 |
layers.push(new ol.layer.Group({ |
| 92 |
name: 'world', |
| 93 |
title: 'Worldwide', |
| 94 |
layers: world |
| 95 |
})); |
| 96 |
} |
| 97 |
|
| 98 |
if (us.length > 0) { |
| 99 |
layers.push(new ol.layer.Group({ |
| 100 |
name: 'us', |
| 101 |
title: 'US', |
| 102 |
layers: us |
| 103 |
})); |
| 104 |
} |
| 105 |
|
| 106 |
return layers; |
| 107 |
} |
| 108 |
|
| 109 |
function createMapzenLayer() { |
| 110 |
// draw earth with a fat stroke; |
| 111 |
// force water above earth |
| 112 |
|
| 113 |
var earthStyle = new ol.style.Style({ |
| 114 |
fill: new ol.style.Fill({ |
| 115 |
color: '#a06000' |
| 116 |
}), |
| 117 |
stroke: new ol.style.Stroke({ |
| 118 |
color: '#a06000', |
| 119 |
width: 5.0 |
| 120 |
}), |
| 121 |
zIndex: 0 |
| 122 |
}); |
| 123 |
|
| 124 |
var waterStyle = new ol.style.Style({ |
| 125 |
fill: new ol.style.Fill({ |
| 126 |
color: '#0040a0' |
| 127 |
}), |
| 128 |
stroke: new ol.style.Stroke({ |
| 129 |
color: '#0040a0', |
| 130 |
width: 1.0 |
| 131 |
}), |
| 132 |
zIndex: 1 |
| 133 |
}); |
| 134 |
|
| 135 |
var boundaryStyle = new ol.style.Style({ |
| 136 |
stroke: new ol.style.Stroke({ |
| 137 |
color: '#804000', |
| 138 |
width: 2.0 |
| 139 |
}), |
| 140 |
zIndex: 2 |
| 141 |
}); |
| 142 |
|
| 143 |
var dashedBoundaryStyle = new ol.style.Style({ |
| 144 |
stroke: new ol.style.Stroke({ |
| 145 |
color: '#804000', |
| 146 |
width: 1.0, |
| 147 |
lineDash: [4, 4], |
| 148 |
}), |
| 149 |
zIndex: 2 |
| 150 |
}); |
| 151 |
|
| 152 |
var styleMap = { |
| 153 |
earth: earthStyle, |
| 154 |
|
| 155 |
water: waterStyle, |
| 156 |
basin: waterStyle, |
| 157 |
dock: waterStyle, |
| 158 |
lake: waterStyle, |
| 159 |
ocean: waterStyle, |
| 160 |
riverbank: waterStyle, |
| 161 |
river: waterStyle, |
| 162 |
|
| 163 |
country: boundaryStyle, |
| 164 |
disputed: dashedBoundaryStyle, |
| 165 |
indefinite: dashedBoundaryStyle, |
| 166 |
indeterminate: dashedBoundaryStyle, |
| 167 |
line_of_control: dashedBoundaryStyle |
| 168 |
}; |
| 169 |
|
| 170 |
return new ol.layer.VectorTile({ |
| 171 |
name: 'mapzen_vector', |
| 172 |
title: 'Mapzen coastlines and water', |
| 173 |
type: 'base', |
| 174 |
renderMode: 'image', |
| 175 |
renderOrder: function(a,b) { |
| 176 |
return a.get('sort_key') - b.get('sort_key'); |
| 177 |
}, |
| 178 |
source: new ol.source.VectorTile({ |
| 179 |
url: '//vector.mapzen.com/osm/earth,water,boundaries/{z}/{x}/{y}.topojson?api_key=' + MapzenAPIKey, |
| 180 |
format: new ol.format.TopoJSON(), |
| 181 |
attributions: [ |
| 182 |
new ol.Attribution({ |
| 183 |
html: 'Tiles courtesy of <a href="http://mapzen.com">Mapzen</a>' |
| 184 |
}), |
| 185 |
new ol.Attribution({ |
| 186 |
html: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' |
| 187 |
}) |
| 188 |
], |
| 189 |
|
| 190 |
tileGrid: ol.tilegrid.createXYZ({ |
| 191 |
preload: 3, |
| 192 |
maxZoom: 14, |
| 193 |
tileSize: [512, 512] |
| 194 |
}), |
| 195 |
|
| 196 |
wrapX: true |
| 197 |
}), |
| 198 |
|
| 199 |
style: function (feature) { |
| 200 |
return (styleMap[feature.get('kind')]); |
| 201 |
} |
| 202 |
}); |
| 203 |
} |