Permalink
Browse files

#85 added bing, openstreetmap background layers

  • Loading branch information...
1 parent 8f80b09 commit 2de31fe4dc4e6b573939e974c9dc9adb254717ac @jywarren committed Mar 9, 2012
@@ -150,13 +150,15 @@ def create
:author => params[:author],
:email => params[:email],
:license => params[:license],
+ :tiles => params[:tiles],
:location => params[:location]})
rescue
@map = Map.new({
:name => params[:name],
:description => params[:description],
:author => params[:author],
:license => params[:license],
+ :tiles => params[:tiles],
:email => params[:email]})
end
else
@@ -167,6 +169,7 @@ def create
:description => params[:description],
:email => params[:email],
:license => params[:license],
+ :tiles => params[:tiles],
:location => params[:location]})
end
if Rails.env.development? && @map.save || verify_recaptcha(:model => @map, :message => "ReCAPTCHA thinks you're not a human!") && @map.save
@@ -24,6 +24,7 @@
<script src="/javascripts/OpenLayers.js" type="text/javascript" charset="utf-8"></script>
<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=<%= APP_CONFIG["google_maps_api_key"] %>' type='text/javascript'></script>
+ <script src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&mkt=en-us"></script>
</head>
<body>
@@ -68,6 +68,14 @@
<option value="copyright" label="No license; copyright only" />
</select>
+ <br />
+ <label for="license">Select a background layer to stitch against. You'll be able to switch later.</label><br />
+ <select name="tiles">
+ <option value="google" label="Google Maps" />
+ <option value="bing" label="Bing Maps" />
+ <option value="osm" label="OpenStreetMap" />
+ </select>
+
<p><input type="submit" value="Save"></p>
<% end %>
</div>
@@ -2,6 +2,8 @@
<p>To properly stitch your aerial imagery together, it can be useful to have a background map for reference. Choose from these sources of satellite imagery:</p>
+<p><a href="javascript:void(0);" onClick="Knitter.start_openlayers('osm');Modalbox.hide();">OpenStreetMap layer</a> (<a href="http://creativecommons.org/licenses/by-sa/3.0/" target="_blank">CC-BY-SA</a>)</p>
+<p><a href="javascript:void(0);" onClick="Knitter.start_openlayers('bing');Modalbox.hide();">Bing Maps layer</a></p>
<p><a href="javascript:void(0);" onClick="Knitter.start_openlayers('google');Modalbox.hide();">Google Maps layer</a></p>
<!--<p><a href="javascript:void(0);" onClick="Knitter.start_openlayers('TMS',prompt('Enter a TMS URI','http://maps.grassrootsmapping.org/chandeleur-may-9-balloon/'));Modalbox.hide();">TMS layer</a> (enter a URL) (experimental)</p>-->
<p><a href="javascript:void(0);" onClick="Knitter.start_openlayers('TMS',prompt('Enter a TMS URI','http://hypercube.telascience.org/tilecache/tilecache.py/1.0.0/NewWorld_google/'));Modalbox.hide();">TMS layer</a> (enter a URL) (experimental)</p>
View
@@ -66,15 +66,15 @@ var Knitter = {
if (format == 'WMS') {
map = new OpenLayers.Map('map', { controls: [],
projection: spher_merc,
- displayProjection: spher_merc,
+ displayProjection: spher_merc,
maxExtent: new OpenLayers.Bounds(-180,-90,180,90),
});
} else {
map = new OpenLayers.Map('map', { controls: [],
tileOrigin: new OpenLayers.LonLat(0,0).transform(latlon,spher_merc),
- units: "m",
+ units: "m",
projection: latlon,
- displayProjection: spher_merc,
+ displayProjection: spher_merc,
maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34),
maxResolution: 156543.0339
});
@@ -99,23 +99,33 @@ var Knitter = {
numZoomLevels: 23,
maxZoomLevel: 22,
resolutions: [156543.03390625, 78271.516953125, 39135.7584765625,
- 19567.87923828125, 9783.939619140625, 4891.9698095703125,
- 2445.9849047851562, 1222.9924523925781, 611.4962261962891,
- 305.74811309814453, 152.87405654907226, 76.43702827453613,
- 38.218514137268066, 19.109257068634033, 9.554628534317017,
- 4.777314267158508, 2.388657133579254, 1.194328566789627,
- 0.5971642833948135, 0.25, 0.1, 0.05],
+ 19567.87923828125, 9783.939619140625, 4891.9698095703125,
+ 2445.9849047851562, 1222.9924523925781, 611.4962261962891,
+ 305.74811309814453, 152.87405654907226, 76.43702827453613,
+ 38.218514137268066, 19.109257068634033, 9.554628534317017,
+ 4.777314267158508, 2.388657133579254, 1.194328566789627,
+ 0.5971642833948135, 0.25, 0.1, 0.05],
serverResolutions: [156543.03390625, 78271.516953125, 39135.7584765625,
- 19567.87923828125, 9783.939619140625,
- 4891.9698095703125, 2445.9849047851562,
- 1222.9924523925781, 611.4962261962891,
- 305.74811309814453, 152.87405654907226,
- 76.43702827453613, 38.218514137268066,
- 19.109257068634033, 9.554628534317017,
- 4.777314267158508, 2.388657133579254,
- 1.194328566789627, 0.5971642833948135]
+ 19567.87923828125, 9783.939619140625,
+ 4891.9698095703125, 2445.9849047851562,
+ 1222.9924523925781, 611.4962261962891,
+ 305.74811309814453, 152.87405654907226,
+ 76.43702827453613, 38.218514137268066,
+ 19.109257068634033, 9.554628534317017,
+ 4.777314267158508, 2.388657133579254,
+ 1.194328566789627, 0.5971642833948135]
} );
map.addLayer(gsat)
+ } else if (layer == 'osm') {
+ var osm = new OpenLayers.Layer.TMS( "OpenStreetMap",
+ "http://tile.openstreetmap.org/",
+ { type: 'png', getURL: osm_getTileURL, displayOutsideMaxExtent: true, attribution: '<a href="http://www.openstreetmap.org/">OpenStreetMap</a>'} );
+ map.addLayer(osm)
+ } else if (layer == 'bing') {
+ var apiKey = "AhYrUtF-jMIlTiblfgB_spQXBgc3u1_4h1mrgm_vEmyrnHLbA8v8452MolECULTX"
+ //Only in later versions of OpenLayers: //var bingsat = new OpenLayers.Layer.Bing("Aerial", {type: "Aerial", apiKey:apiKey, sphericalMercator:true});
+ var bingsat = new OpenLayers.Layer.VirtualEarth("Virtual Earth Aerial", {'type': VEMapStyle.Aerial, 'sphericalMercator': true, numZoomLevels: 20 });
+ map.addLayer(bingsat)
} else if (layer == 'yahoo') {
var yahoosat = new OpenLayers.Layer.Yahoo("Yahoo Satellite", {type: YAHOO_MAP_SAT, sphericalMercator: true, numZoomLevels: 22});
map.addLayer(yahoosat)
@@ -130,11 +140,11 @@ var Knitter = {
Config.tile_url = tile_url || Config.tile_url
var tms = new OpenLayers.Layer.TMS( "OpenLayers TMS", Config.tile_url,
{ //projection: latlon,
- //displayProjection: spher_merc,
+ //displayProjection: spher_merc,
//getURL: Knitter.overlay_getTileURL,
//maxResolution:156543.0339,
- //units: "m",
- //maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34),
+ //units: "m",
+ //maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34),
//tileOrigin: new OpenLayers.LonLat(0,0).transform(latlon,spher_merc),
numZoomLevels: 22,
serviceVersion: '.',
@@ -176,7 +186,7 @@ var Knitter = {
if (Config.tile_switcher) {
var switcherControl = new OpenLayers.Control.LayerSwitcher()
map.addControl(switcherControl);
- switcherControl.maximizeControl();
+ switcherControl.maximizeControl();
}
Knitter.openLayersDraw()
Glop.observe('glop:draw', Knitter.openLayersDraw)
@@ -227,7 +237,7 @@ var Knitter = {
z = z + 1;
}
if (mapBounds.intersectsBounds( bounds ) && z >= mapMinZoom && z <= mapMaxZoom ) {
- //console.log( this.url + z + "/" + x + "/" + y + "." + this.type);
+ //console.log( this.url + z + "/" + x + "/" + y + "." + this.type);
return this.url + z + "/" + x + "/" + y + "." + this.type;
} else {
return "http://www.maptiler.org/img/none.png";
@@ -302,11 +312,11 @@ var Knitter = {
if (lat > maxlat) maxlat = lat
if (lon < minlon) minlon = lon
if (lat < minlat) minlat = lat
- lonsum += lon
- latsum += lat
+ lonsum += lon
+ latsum += lat
loncount += 1
latcount += 1
- })
+ })
}
},this)
if (latcount > 0) Cartagen.go_to((maxlat+minlat)/2,(maxlon+minlon)/2,Map.zoom)
@@ -347,3 +357,19 @@ var Knitter = {
})
},
}
+
+function osm_getTileURL(bounds) {
+ var res = this.map.getResolution();
+ var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
+ var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
+ var z = this.map.getZoom();
+ var limit = Math.pow(2, z);
+
+ if (y < 0 || y >= limit) {
+ return "http://www.maptiler.org/img/none.png";
+ } else {
+ x = ((x % limit) + limit) % limit;
+ return this.url + z + "/" + x + "/" + y + "." + this.type;
+ }
+}
+

0 comments on commit 2de31fe

Please sign in to comment.