Sigo con el tema y extrayendo información. Mi manejo de Javascript es el que es y quizás diga alguna burradilla.
Estoy intentando pasar el ejemplo del ICC con el control y echo en falta algunas funciones que se recogen en la API. Los servidores WMS trabajan en Mercator y necesitan convertir sus datos.
Parte de la solución está en http://code.google.com/intl/es-US/apis/maps/documentation/reference.html#GProjection.fromPixelToLatLng
Paso a hacerte los comentarios de lo que he ido trabajando.
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(41.5580, 1.5906), 7);
map.setUIToDefault();
var license = "<a href='http://www.icc.cat'><strong>Institut Cartogràfic de Catalunya</strong></a>";
var copyright = new GCopyright(1, new GLatLngBounds(new GLatLng(-90, -180), new GLatLng(90, 180)), 0, license);
var copyrightCollection = new GCopyrightCollection("");
copyrightCollection.addCopyright(copyright);
var tileICC= new GTileLayer(copyrightCollection,1,17);
hasta aquí todo se trasvasa sin problemas...
Estos tres miembros no los aporta el constructor pero puede revolverse mediante variables
tileICC.myFormat='image/png';
tileICC.myLayers='mtc250m,';
tileICC.myBaseURL="http://shagrat.icc.es/lizardtech/iserv/ows?";
'aquí llama a la función sin pasarle parámetros pero al función los tiene y los usa
tileICC.getTileUrl=CustomGetTileUrl;
'esto creo que se adapta sin grandes problemas.
var mapaICC = new GTileLayerOverlay(tileICC);
map.addOverlay(mapaICC);
var layerICC=[tileICC,tileICC];
var layer1=[G_NORMAL_MAP.getTileLayers()[0],G_NORMAL_MAP.getTileLayers()[0]];
var custommap1 = new GMapType(layer1, G_NORMAL_MAP.getProjection(),"Mapa", G_NORMAL_MAP);
var custommapICC = new GMapType(layerICC,G_NORMAL_MAP.getProjection(), "WMS ICC", G_SATELLITE_MAP);
map.getMapTypes().length = 0;
//map.addMapType(custommap1);
map.addMapType(custommapICC);
map.setMapType(custommapICC);
map.clearOverlays();
}
}
'Y esta es la función. myLayers toma el valor según el zoom
function CustomGetTileUrl(a,b,c) {
/*
this.myLayers='mtc250m';
if (b>12){
this.myLayers='mtc50m';
}
if (b>14){
this.myLayers='mtc10m';
}
if (b>16){
this.myLayers='mtc5m';
}
*/
this.myLayers='mtc250m,';
if (b>12){
this.myLayers='mtc50m,';
}
if (b>14){
this.myLayers='mtc10m,';
}
if (b>16){
this.myLayers='mtc5m,';
}
this.myStyles="";
var lULP = new GPoint(a.x*256,(a.y+1)*256);
var lLRP = new GPoint((a.x+1)*256,a.y*256);
'Aquí están las funciones de Mercator que se precisan y no están en el control.
var lUL = G_NORMAL_MAP.getProjection().fromPixelToLatLng(lULP,b,c);
var lLR = G_NORMAL_MAP.getProjection().fromPixelToLatLng(lLRP,b,c);
var lBbox=lUL.x+","+lUL.y+","+lLR.x+","+lLR.y;
'conseguido esto creo que estaría operativo el tema de los WMS en el control.
var lSRS="EPSG:4326";
var lURL=this.myBaseURL;
lURL+="&REQUEST=GetMap";
lURL+="&SERVICE=WMS";
lURL+="&VERSION=1.1.1";
lURL+="&LAYERS="+this.myLayers;
lURL+="&STYLES="+this.myStyles;
lURL+="&FORMAT="+this.myFormat;
lURL+="&BGCOLOR=0xFFFFFF";
lURL+="&TRANSPARENT=TRUE";
lURL+="&SRS="+lSRS;
lURL+="&BBOX="+lBbox;
lURL+="&WIDTH=256";
lURL+="&HEIGHT=256";
lURL+="&reaspect=false";
return lURL;
}
Ya me dirás como lo ves... y quizás lo mejor sería borrar de este post el resto de los códigos...