Any help is very apreciated
I work with a local italian projection (EPSG:3003 Monte Mario Italy zone 1) and I had loaded this projection in my project for evitate to reproject all of my data.
I had created the tile pyramid with the last version of gdal2tiles (the version shipped with the last version of maptiler open source [see http://trac.osgeo.org/gdal/ticket/2052] to be able to generate jpeg tiles instead of png tiles)
my problem is that I don't be able to assign the correct extent to my page. If I assign to the montemarioProjection the extent for italy, also this extent is applied to my map, but my map contains only the municipality of modena. My extent of tms of modena, calculated by gdal2tiles, seems to be ignored.
when i try to pan to a certain coordinate point in monte mario coordinate system, map goes in a wrong place, because is not positioned well.
some examples: (HERE I HAD ASSIGNED TO MONTE MARIO ONLY MODENA EXTENT AS EXTENT, NOT ITALY)
EXAMPLE 1 http://cartografia.localhost/test_tms_ol3/ol3_ortofoto.html
(HERE I HAD ASSIGNED TO MONTE MARIO HIS REAL EXTENT AND TRIED TO FORCE MAP ORIGIN, BUT IT WAS IGNORED. I HAVE TO REMOVE extent parameter from ol.layer.tile and ol.view)
EXAMPLE 2 http://cartografia.localhost/test_tms_ol3/ol3_ortofoto2.html
code to force map origin (it does nothing)
origin: tileGrid: new ol.tilegrid.TileGrid({
//tileGrid: new ol.tilegrid.XYZ({
origin: tms_origin,
resolutions: tms_resolutions
}),
IF LOOK AT MOUSEPOSITION CONTROL, THE COORDINATES IS WRONG IN EXAMPLE 1 AND 2
HERE IS ALL OF MY CODE FROM EXAMPLE 1
var tms_extent = [ 1640349.34499999997206, 4935769.97499999962747, 1659997.04499999992549, 4956992.87500000000000 ];
var tms_origin = [1640349.34499999997206, 4935769.97499999962747];
//RESOLUTIONS NOT USED IN MY PROJECT
//102.39999999999979, 51.19999999999990, 25.59999999999995,
var tms_resolutions = [
12.79999999999997, 6.39999999999999, 3.19999999999999, 1.60000000000000,
0.80000000000000, 0.40000000000000, 0.20000000000000, 0.10000000000000
];
var city_center = [ 1652769.73, 4945475.55 ];
var monteMarioSystemCode = 'EPSG:3003';
var projectionMonteMario = ol.proj.get(monteMarioSystemCode);
//var extent_italia_monte_mario = [1290679.24, 4194066.17, 2226886.34, 5259894.49];
//projectionMonteMario.setExtent(extent_italia_monte_mario);
projectionMonteMario.setExtent(tms_extent);
//var tms_extent = ol.proj.transformExtent([1640349.345, 4935769.975, 1659997.045, 4956992.875], 'EPSG:3003', 'EPSG:4326');
//var city_center = ol.proj.transform([1652783, 4945465], 'EPSG:3003', 'EPSG:4326');
var map = new ol.Map({
controls: ol.control.defaults({ attribution: false }).extend(
[ new ol.control.ZoomSlider(),
new ol.control.ScaleLine(),
new ol.control.MousePosition({
coordinateFormat: ol.coordinate.createStringXY(4),
projection: monteMarioSystemCode,
// comment the following two lines to have the mouse position
// be placed within the map.
//className: 'custom-mouse-position',
//target: document.getElementById('mouse-position'),
undefinedHTML: ' '
})
]),
layers : [ new ol.layer.Tile({
extent : tms_extent,
//minResolution : tms_resolutions[7],
//maxResolution : tms_resolutions[0],
source : new ol.source.XYZ({
/* alternative */
//source: new ol.source.TileImage({
crossOrigin : null,
//experimental parameter
projection : monteMarioSystemCode,
//experimental parameter
//maxZoom : 10,
//experimental parameter. documentation the documentation says to remove this attribute (not supported)
//minZoom : 3,
//experimental parameter
//tilePixelRatio : 1,
//experimental parameter
//tileSize : 256,
//experimental parameter (necessary because gdal2tiles generate tiles in TMS mode not in XYZ mode)
tileUrlFunction : function(coordinate) {
if (coordinate == null) {
return "";
}
// type of ol.TileCoord is recently changed to an array of three numbers: [z, x, y]
var z = coordinate[0];
var x = coordinate[1];
var y = (1 << z) - coordinate[2] - 1;
return 'http://mappe-t.comune.modena.it/ortofoto/2014/tms2014/' + z + '/' + x + '/' + y + '.jpg';
},
//this works only for tiles generated in XYZ format, es maptiler pro
//url : 'http://mappe-t.comune.modena.it/ortofoto/2014/tms2014/{z}/{x}/{y}.jpg'
//experimental parameter (inherited from ol.source.TileImage)
/*
tileGrid: new ol.tilegrid.TileGrid({
//tileGrid: new ol.tilegrid.XYZ({
origin: tms_origin,
resolutions: tms_resolutions
}),
*/
})
}) ],
renderer : 'canvas',
target : 'map',
view : new ol.View({
projection : monteMarioSystemCode,
center : city_center,
//experimental parameter
extent : tms_extent,
//maxResolution : tms_resolutions[0],
//minResolution : tms_resolutions[7],
maxZoom : 10,
minZoom : 3,
//resolution : tms_resolutions[0],
//resolutions : tms_resolutions,
zoom : 3,
//zoomFactor : 2
})
});
map.getView().fitExtent(tms_extent, map.getSize());
and here code from example 2
var tms_extent = [ 1640349.34499999997206, 4935769.97499999962747, 1659997.04499999992549, 4956992.87500000000000 ];
var tms_origin = [1640349.34499999997206, 4935769.97499999962747];
//RESOLUTIONS NOT USED IN MY PROJECT
//102.39999999999979, 51.19999999999990, 25.59999999999995,
var tms_resolutions = [
12.79999999999997, 6.39999999999999, 3.19999999999999, 1.60000000000000,
0.80000000000000, 0.40000000000000, 0.20000000000000, 0.10000000000000
];
var city_center = [ 1652769.73, 4945475.55 ];
var monteMarioSystemCode = 'EPSG:3003';
var projectionMonteMario = ol.proj.get(monteMarioSystemCode);
var extent_italia_monte_mario = [1290679.24, 4194066.17, 2226886.34, 5259894.49];
projectionMonteMario.setExtent(extent_italia_monte_mario);
//projectionMonteMario.setExtent(tms_extent);
//var tms_extent = ol.proj.transformExtent([1640349.345, 4935769.975, 1659997.045, 4956992.875], 'EPSG:3003', 'EPSG:4326');
//var city_center = ol.proj.transform([1652783, 4945465], 'EPSG:3003', 'EPSG:4326');
var map = new ol.Map({
controls: ol.control.defaults({ attribution: false }).extend(
[ new ol.control.ZoomSlider(),
new ol.control.ScaleLine(),
new ol.control.MousePosition({
coordinateFormat: ol.coordinate.createStringXY(4),
projection: monteMarioSystemCode,
// comment the following two lines to have the mouse position
// be placed within the map.
//className: 'custom-mouse-position',
//target: document.getElementById('mouse-position'),
undefinedHTML: ' '
})
]),
layers : [ new ol.layer.Tile({
//extent : tms_extent,
//minResolution : tms_resolutions[7],
//maxResolution : tms_resolutions[0],
source : new ol.source.XYZ({
/* alternative */
//source: new ol.source.TileImage({
crossOrigin : null,
//experimental parameter
projection : monteMarioSystemCode,
//experimental parameter
//maxZoom : 10,
//experimental parameter. documentation the documentation says to remove this attribute (not supported)
//minZoom : 3,
//experimental parameter
//tilePixelRatio : 1,
//experimental parameter
//tileSize : 256,
//experimental parameter (necessary because gdal2tiles generate tiles in TMS mode not in XYZ mode)
tileUrlFunction : function(coordinate) {
if (coordinate == null) {
return "";
}
// type of ol.TileCoord is recently changed to an array of three numbers: [z, x, y]
var z = coordinate[0];
var x = coordinate[1];
var y = (1 << z) - coordinate[2] - 1;
return 'http://mappe-t.comune.modena.it/ortofoto/2014/tms2014/' + z + '/' + x + '/' + y + '.jpg';
},
//this works only for tiles generated in XYZ format, es maptiler pro
//url : 'http://mappe-t.comune.modena.it/ortofoto/2014/tms2014/{z}/{x}/{y}.jpg'
//experimental parameter (inherited from ol.source.TileImage)
tileGrid: new ol.tilegrid.TileGrid({
//tileGrid: new ol.tilegrid.XYZ({
origin: tms_origin,
resolutions: tms_resolutions
}),
})
}) ],
renderer : 'canvas',
target : 'map',
view : new ol.View({
projection : monteMarioSystemCode,
center : city_center,
//experimental parameter
//extent : tms_extent,
//maxResolution : tms_resolutions[0],
//minResolution : tms_resolutions[7],
maxZoom : 10,
minZoom : 3,
//resolution : tms_resolutions[0],
//resolutions : tms_resolutions,
zoom : 3,
//zoomFactor : 2
})
});/*
CONFIGURATION PARAMETERS DESUMED FROM gdal2tiles generated file
http://mappe.comune.modena.it/ortofoto/2014/tilemapresource.xml
*/
var tms_resolutions_2014 = [ 102.39999999999979, 51.19999999999990, 25.59999999999995, 12.79999999999997,
6.39999999999999, 3.19999999999999, 1.60000000000000, 0.80000000000000,
0.40000000000000, 0.20000000000000, 0.10000000000000 ];
var extent_ortofoto_2014 = [1640349.34499999997206, 4935769.97499999962747, 1659997.04499999992549, 4956992.87500000000000];
/* CONFIGURATION PARAMETERS DESUMED FROM http://epsg.io/3003 */
var coordSystemCode = 'EPSG:3003';
var projectionMonteMario = ol.proj.get(coordSystemCode);
//var extent_italy_monte_mario = [1290679.24, 4194066.17, 2226886.34, 5259894.49];
var extent_italy_monte_mario = [1290650.93, 4192956.42, 2226749.10, 5261004.57];
projectionMonteMario.setExtent(extent_italy_monte_mario);
//TMS LAYER. IS CONFIGURED AS A CUSTOM TileImage source
var tmsModena = new ol.layer.Tile({
preload: 1,
source: new ol.source.TileImage({
crossOrigin: null,
extent: extent_ortofoto_2014,
projection: projectionMonteMario,
tileGrid: new ol.tilegrid.TileGrid({
extent: extent_ortofoto_2014,
origin: [extent_ortofoto_2014[0], extent_ortofoto_2014[1]],
resolutions: tms_resolutions_2014
}),
tileUrlFunction: function(coordinate) {
if (coordinate === null) return undefined;
// TMS Style URL
var z = coordinate[0];
var x = coordinate[1];
var y = coordinate[2];
var url = 'http://mappe.comune.modena.it/ortofoto/2014/'+z+'/'+ x +'/'+y +'.jpg';
return url;
}
})
});
...
<?xml version="1.0" encoding="utf-8"?> <TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0"> <Title>J133-12H7h54 tiled.tiff</Title> <Abstract></Abstract> <SRS>EPSG:3857</SRS> <BoundingBox minx="17.34140082382990" miny="60.27332260300220" maxx="17.43368067888432" maxy="60.31931836578014"/> <Origin x="17.34140082382990" y="60.27332260300220"/> <TileFormat width="256" height="256" mime-type="image/png" extension="png"/> <TileSets profile="mercator"> <TileSet href="1" units-per-pixel="78271.51695000000473" order="1"/> <TileSet href="2" units-per-pixel="39135.75847500000236" order="2"/> <TileSet href="3" units-per-pixel="19567.87923750000118" order="3"/> <TileSet href="4" units-per-pixel="9783.93961875000059" order="4"/> <TileSet href="5" units-per-pixel="4891.96980937500030" order="5"/> <TileSet href="6" units-per-pixel="2445.98490468750015" order="6"/> <TileSet href="7" units-per-pixel="1222.99245234375007" order="7"/> <TileSet href="8" units-per-pixel="611.49622617187504" order="8"/> <TileSet href="9" units-per-pixel="305.74811308593752" order="9"/> <TileSet href="10" units-per-pixel="152.87405654296876" order="10"/> <TileSet href="11" units-per-pixel="76.43702827148438" order="11"/> <TileSet href="12" units-per-pixel="38.21851413574219" order="12"/> <TileSet href="13" units-per-pixel="19.10925706787109" order="13"/> </TileSets> </TileMap>
var resolutions = [ 78271.51695000000473, 39135.75847500000236, 19567.87923750000118, 9783.93961875000059,
4891.96980937500030, 2445.98490468750015, 1222.99245234375007, 611.49622617187504,
305.74811308593752, 152.87405654296876, 76.43702827148438, 38.21851413574219, 19.10925706787109];
var extent = [60.27332260300220, 17.34140082382990, 60.31931836578014, 17.43368067888432];
var coordSystemCode = 'EPSG:3857';
var projectiono = ol.proj.get(coordSystemCode);
var tms = new ol.layer.Tile({
preload: 1,
source: new ol.source.TileImage({
crossOrigin: null,
extent: extent,
projection: projection,
tileGrid: new ol.tilegrid.TileGrid({
extent: extent,
origin: [extent[0], extent[1]],
resolutions: resolution }),
tileUrlFunction: function(coordinate) {
if (coordinate === null) return undefined;
var z = coordinate[0];
var x = coordinate[1];
var y = coordinate[2];
var url = 'http://localhost/maps/'+z+'/'+ x +'/'+y +'.png';
return url;
}
})
});
var view = new ol.View({
projection: 'EPSG:3857',
center: center,
zoom: 2 });
var osm = new ol.layer.Tile({
source: new ol.source.OSM()
});
var map = new ol.Map({
layers: [
osm,tms ],
renderer: 'canvas',
target: 'map',
view: view
});