Use Swisstopo map with gwtopenmaps.openlayers.client.layer.WMTS in Java

244 views
Skip to first unread message

chrf...@gmail.com

unread,
Aug 11, 2015, 4:15:03 PM8/11/15
to GeoAdmin API
Hi all

I'm trying to add swisstopo as an additional openlayers client layer to the Traccar Web UI. It uses GWT in Java.

My current code snippet looks as follows: (displaying should be implemented properly since it works for OSM, Mapbox, Google etc..)

WMTSOptions wmts_options = new WMTSOptions("http://wmts7.geo.admin.ch/", "ch.swisstopo.pixelkarte-farbe/", "default", "21781");
wmts_options
.setName(mapType.getName());
wmts_options
.setRequestEncoding(RequestEncoding.REST);
wmts_options
.setFormatSuffix("jpeg");
wmts_options
.setProjection("EPSG:21781");
wmts_options
.setUnits("m");
wmts_options
.setFormat("image/jpeg");
wmts_options
.setBuffer(0);
wmts_options
.setLayerOpacity(1.0);
wmts_options
.setIsBaseLayer(true);
wmts_options
.setMaxExtent(new Bounds(420000, 30000, 900000, 350000));
wmts_options
.setTileOrigin(new LonLat(420000, 350000));
double[] resolutions = {4000, 3750, 3500, 3250, 3000, 2750, 2500, 2250, 2000, 1750, 1500, 1250, 1000, 750, 650.0, 500.0, 250.0, 100.0, 50.0, 20.0, 10.0, 5.0, 2.5, 2.0, 1.5, 1.0, 0.5};
wmts_options
.setResolutions(resolutions);
wmts_options.setAttribution("<a href='http://www.geo.admin.ch/internet/geoportal/en/home.html'>Pixelmap / geo.admin.ch</a>");
           
WMTS res
= new WMTS(wmts_options);

WMSParams time_param = new WMSParams();
time_param
.setTimeFilter("20140520");
res
.mergeNewParams(time_param);

return
res;

I don't get any valid tile but the attribution is shown properly.

Do you see any error? What am I doing wrong?

I'm currently running it on localhost. How can I relate the request with my webaccess account?

Thanks a lot

Christian

Marc Monnerat

unread,
Aug 12, 2015, 2:46:36 AM8/12/15
to geoadmin-api
Hello Christian,

Looks correct, your have all parameters, including the timestamp.

What kind of error code do you get ? 

If you get a 204 for most tile, you are probably using the wrong tilematrixset. The one called '21781' is 'swissgrid', which is not compatible with OSM, Google Map, and so on. You have to use Web-Mercator one.


If you get 403, then you have to have to register first your domain to get acces to the tiles http://www.swisstopo.ch/webaccess and then put the registred domain in you request. The first intend of WMTS in our case was Web application, though it perfectly work with fat client.

Regards,

Marc


Christian Frick

unread,
Aug 13, 2015, 9:03:01 AM8/13/15
to GeoAdmin API
Hi Marc

Thanks for your answer. There where several problems. First of all the transformation from EPSG:21781 did not work properly and therefore the limitation set by setMaxExtent blocked the request for tiles. Additionally, your mixing-up with col and rows in the WMTS requests caused additional problems. Furthermore, even by using http://spatialreference.org/ref/epsg/21781/proj4js/ for transformation between EPSG:21781 and EPSG:3857, the tile requests did not work properly.

I finally solved the problem by just using a gwtopenmaps.openlayers.client.layer.XYZ() object:

xyzOptions = new XYZOptions();
xyzOptions
.setSphericalMercator(true);
xyzOptions
.setNumZoomLevels(20);
xyzOptions
.setAttribution("<a href='http://www.geo.admin.ch/internet/geoportal/en/home.html'>Pixelmap / geo.admin.ch</a>");
return new XYZ(mapType.getName(),
       
"http://wmts10.geo.admin.ch/1.0.0/ch.swisstopo.pixelkarte-farbe/default/20151231/3857/${z}/${x}/${y}.jpeg",
        xyzOptions
);

Best regards, 

Christian

jol...@gmail.com

unread,
Oct 10, 2016, 11:11:20 AM10/10/16
to GeoAdmin API
hello

I'm looking to add additionnal openlayers also (French IGN maps ) into Traccar Web UI.
could you kindly share how you deal with that from traccar web sources ?

Thanks
Pascal

Marc Monnerat

unread,
Oct 11, 2016, 10:51:30 AM10/11/16
to geoadmin-api
Hello Pascal,

I don't know traccar, but if it uses OpenLayers 3, you may have a look at this code pen example, showing how to use Google Mercator WMTS source. For WGS1984, it is basically the same. Additional info may be found on this page.

Note: You have to register, to use BGDI's WMTS services. For more info

Regards,

Marc

--
You received this message because you are subscribed to the Google Groups "GeoAdmin API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geoadmin-api+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-- ἡ φύσις οὐδὲν ποιεῖ ἅλματα.
Reply all
Reply to author
Forward
0 new messages