[OpenLayers-Users] Newbie Projection Troubles
bmcbride
bmcbride at cha-llp.com
Wed Jun 18 17:44:42 EDT 2008
Hello,
I'm working with the spherical-mercator example and trying to add a WMS
layer, which is in EPSG:4326. The WMS (NYC Imagery) layer will not render
on the map and I'm sure it has to do with either projection, maxResolution,
or maxExtent variables, but I cannot figure it out. Any help would be
greatly appreciated. The code is below:
// make map available for easy debugging
var map;
// avoid pink tiles
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
OpenLayers.Util.onImageLoadErrorColor = "transparent";
function init(){
var options = {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
units: "m",
maxResolution: 156543.0339,
maxExtent: new OpenLayers.Bounds(-20037508, -20037508,
20037508, 20037508.34)
};
map = new OpenLayers.Map('map', options);
// create Google Mercator layers
var gmap = new OpenLayers.Layer.Google(
"Google Streets",
{'sphericalMercator': true}
);
var gsat = new OpenLayers.Layer.Google(
"Google Satellite",
{type: G_SATELLITE_MAP, 'sphericalMercator': true}
);
var ghyb = new OpenLayers.Layer.Google(
"Google Hybrid",
{type: G_HYBRID_MAP, 'sphericalMercator': true}
);
// create Virtual Earth layers
var veroad = new OpenLayers.Layer.VirtualEarth(
"Virtual Earth Roads",
{'type': VEMapStyle.Road, 'sphericalMercator': true}
);
var veaer = new OpenLayers.Layer.VirtualEarth(
"Virtual Earth Aerial",
{'type': VEMapStyle.Aerial, 'sphericalMercator': true}
);
var vehyb = new OpenLayers.Layer.VirtualEarth(
"Virtual Earth Hybrid",
{'type': VEMapStyle.Hybrid, 'sphericalMercator': true}
);
// create Yahoo layer
var yahoo = new OpenLayers.Layer.Yahoo(
"Yahoo Street",
{'sphericalMercator': true}
);
var yahoosat = new OpenLayers.Layer.Yahoo(
"Yahoo Satellite",
{'type': YAHOO_MAP_SAT, 'sphericalMercator': true}
);
var yahoohyb = new OpenLayers.Layer.Yahoo(
"Yahoo Hybrid",
{'type': YAHOO_MAP_HYB, 'sphericalMercator': true}
);
// create OSM layer
var mapnik = new OpenLayers.Layer.TMS(
"OpenStreetMap (Mapnik)",
"http://tile.openstreetmap.org/",
{
type: 'png', getURL: osm_getTileURL,
displayOutsideMaxExtent: true,
attribution: ' http://www.openstreetmap.org/
OpenStreetMap '
}
);
// create OSM layer
var osmarender = new OpenLayers.Layer.TMS(
"OpenStreetMap (Tiles at Home)",
"http://tah.openstreetmap.org/Tiles/tile.php/",
{
type: 'png', getURL: osm_getTileURL,
displayOutsideMaxExtent: true,
attribution: ' http://www.openstreetmap.org/
OpenStreetMap '
}
);
// create WMS layer
var wms = new OpenLayers.Layer.WMS(
"World Map",
"http://world.freemap.in/tiles/",
{'layers': 'factbook-overlay', 'format':'png'},
{
'opacity': 0.4,
'isBaseLayer': false,'wrapDateLine': true
}
);
var nysdop = new OpenLayers.Layer.WMS(
"NYSDOP",
"http://imsortho.cr.usgs.gov/servlet/com.esri.wms.Esrimap/USGS_EDC_Ortho_NYSDOP_Grid?",
{'layers': "NY_NYC_2006_2FT_NC"},{projection:"EPSG:4326"}
);
// create a vector layer for drawing
var vector = new OpenLayers.Layer.Vector("Editable Vectors");
map.addLayers([gmap, gsat, ghyb, nysdop, veroad, veaer, vehyb,
yahoo, yahoosat, yahoohyb, mapnik, osmarender,
wms, vector]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.EditingToolbar(vector));
map.addControl(new OpenLayers.Control.Permalink());
map.addControl(new OpenLayers.Control.MousePosition());
if (!map.getCenter()) {map.zoomToMaxExtent()}
}
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 OpenLayers.Util.getImagesLocation() + "404.png";
} else {
x = ((x % limit) + limit) % limit;
return this.url + z + "/" + x + "/" + y + "." + this.type;
}
}
The following example works fine, but I need the commercial imagery and OSM
mapnik data available...
var map = null;
function init(){
map = new OpenLayers.Map('map');
var ol_wms = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0",
{layers: 'basic'}
);
var nysdop = new OpenLayers.Layer.WMS(
"NYSDOP",
"http://imsortho.cr.usgs.gov/servlet/com.esri.wms.Esrimap/USGS_EDC_Ortho_NYSDOP_Grid?",
{layers: "NY_NYC_2006_2FT_NC"}
);
map.addLayers([ol_wms, nysdop]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.zoomToMaxExtent();
}
--
View this message in context: http://www.nabble.com/Newbie-Projection-Troubles-tp17157211p17157211.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list