Following on from this question: Identify what projection this Australian map uses? <- this is the sort of map i want to load in
I need help changing the bits necessary in this example of Lambert Projection in Google Maps to make it work with Australian tiles instead: Lambert equal area azimuthal projection Google Map which apparently uses these formulae: Lambert Conformal Conic Projection -- from Wolfram MathWorld
Here is my attempts so far, changing what i think needs changing, but it must not be enough
- its a bit confusing for me, im a web developer
- i will be adding the tiles at a later stage
- in my version i made it so when you click around it shows the coords, but as you do this the ones it shows are not in australia, so thus my problem
- in the original demo it centers and loads tiles 001 & 101, in mine it does not
- in my version i made it try to load all tiles so you can see which ones in the error console
Thanks for your time.
Heres is the original javascript it uses as seen at that site: (you may notice it uses google maps api v2, not the latest v3 available due to its age)
var phi0 = 10*Math.PI/180;
var phi1 = 20*Math.PI/180;
var phi2 = 70*Math.PI/180;
var n = (Math.log(Math.cos(phi1)) - Math.log(Math.cos(phi2)))/
(-Math.log(Math.tan(phi1/2 + Math.PI/4)) + Math.log(Math.tan(phi2/2 + Math.PI/4)));
var rho0 = (Math.cos(phi1)*Math.pow(Math.tan(phi1/2 + Math.PI/4),n))/
(n*Math.pow(Math.tan(phi0/2 + Math.PI/4),n));
function ConformalConicLambertProjection() {};
ConformalConicLambertProjection.prototype = new GProjection();
ConformalConicLambertProjection.prototype.fromPixelToLatLng = function(pixel, z) {
var x1 = (-0.0034375*(Math.pow(2,7 + z) - pixel.x))/Math.pow(2,z);
var y1 = -0.0017254901960784311*Math.pow(2,1 - z)*
(pixel.y - 405.68181818181824*Math.pow(2,-1 + z));
var rho = Math.sqrt(2.143305952697287 + Math.pow(x1,2) -
2.9280067982826044*y1 + Math.pow(y1,2));
var t = Math.asin(x1/rho);
var lng = 78.17779218926289*t-100;
var lat = 28.64788975654*(-3.141592653589793 +
4*Math.atan(2.004758218840869/Math.pow(rho,1.3644598756425434575)));
return new GLatLng(lat, lng);
};
ConformalConicLambertProjection.prototype.fromLatLngToPixel = function(latLng, z) {
var t = Math.PI/180*(100 + latLng.lng())*n;
var rho = (Math.cos(phi1)*Math.pow(Math.tan(phi1/2. + Math.PI/4.),n))/
(n*Math.pow(Math.tan((Math.PI/180*latLng.lat())/2. + Math.PI/4.),n));
var x1 = rho*Math.sin(t);
var y1 = rho0 - rho*Math.cos(t);
x = Math.round(Math.pow(2,z)*(128 + 290.9090909090909*x1));
y = Math.round(Math.pow(2,-1 + z)*(405.68181818181824 - 579.5454545454546*y1));
return new GPoint(x,y);
};
ConformalConicLambertProjection.prototype.tileCheckRange = function(tileIndex, zoom, bs) {
if(0 <= tileIndex.x && tileIndex.x < Math.pow(2,zoom) &&
0 <= tileIndex.y && tileIndex.y < Math.pow(2,zoom-1)) {
return true;}
else { return false; };
};
function load() {
if (GBrowserIsCompatible()) {
var lambertTileLayer = new GTileLayer(
new GCopyrightCollection(), 1, 4);
lambertTileLayer.getTileUrl = function(tile, zoom) {
return "Tiles/ConformalConicLambertTile_" + tile.x + "_" + tile.y + "_" + zoom + ".png";
};
var lambertMap = new GMapType([lambertTileLayer],
new ConformalConicLambertProjection(), "ConformalConicLambert",
{tileSize:256});
var map = new GMap2(document.getElementById("map"), {mapTypes:[lambertMap]});
// Add the controls
map.addControl(new GSmallZoomControl());
map.setCenter(new GLatLng(37.9251,-100), 1);
} else {
document.getElementById('map').style.backgroundColor = '#DDDDDD';
document.getElementById('map').innerHTML = 'Sorry, your browser does not appear to be compatible with Google maps.';
}
}
var x1 = rho*Math.sin(t); var y1 = rho0 - rho*Math.cos(t)clearly implement equations (1) and (2) on the Mathworld site, you can be reasonably confident this is a version of the LCC and not the Lambert equal area azimuthal projection. But I agree with @mkennedy: hard-coding the parameters makes this code almost unreadable and practically unmaintainable. If I had to use it I would start over with the MathWorld equations and make it flexible enough to vary all the parameters. – whuber Sep 06 '13 at 01:29