2

I'm using a Custom Map Source for MOBAC that is based on a beanshell script (see below) which renders perfectly in MOBAC. Now, I'd be keen to do the same in QGIS and wonder if it is possible to implement the same source in the OpenLayers Plugin? Admittedly I'm completely new to OpenLayers so please excuse me if this approach turns out to be foolish. Or maybe there is an alternative to use this map source as base map in QGIS?

/** 
beanshell code to use the online maps from bergfex

put it into your "mapsources"-directory...

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>

**/


static import java.lang.Math.*;

name = "Bergfex";

tileType = "png";

tileSize = 256; // optional
minZoom = 8;   // optional
maxZoom = 15;   // optional

/**
This method is called for each tile: 
input parameters for this script: "zoom", "x" and "y"
**/

random = new Random( System.currentTimeMillis() );

String getTileUrl( int zoom, int x, int y ) {
    // String baseurl = "http://s2.bergfex.at/images/amap/";
    String baseurl = "http://s" + random.nextInt(10) + ".bergfex.at/images/amap/";
    String xBase = "";
    if (zoom > 13)
        xBase = Integer.toString(x).substring(0, zoom - 12) + "/";
    return baseurl + zoom + "/" + xBase + zoom + "_" + x + "_" + y + ".png";
} 
2

I wrote a detailed tutorial for incorporating other tiles in openlayers plugin here:

Easiest way to create historical street maps using QGIS

Only problem with your tiles is the storage path, looking like

http://s2.bergfex.at/images/amap/12/12_2200_1434.png

and still different for zoom levels >13.

But this should be managable by inserting some code.


EDIT

This one is working for me until zoomlevel 13:

    var osm = new OpenLayers.Layer.OSM(
    "Bergfex",
    "http://s2.bergfex.at/images/amap/${z}/${z}_${x}_${y}.png",
    {
        eventListeners: {
          "loadstart": layerLoadStart,
          "loadend": layerLoadEnd
        }
      }
    );
    map.addLayer(osm);
  • Thanks Andre! ..the tutorial is straight forward, but I got no idea how to deal with the path and its alteration with zoom level - any chance you'd help me with that? – Kay Sep 5 '13 at 13:56
  • Okay, I found something promising at dev.openlayers.org. I then tried to follow the tutorial but copied special code pieces from there: dev.openlayers.org/sandbox/ahocevar/bergfex. This should load the bergfex tiles ontop of an openstreetmap in OpenLayers QGIS. It works for the OSM-tiles but not for the bergfex tiles.. Any ideas? Here's the html I added to the path C:\Users\Kay\.qgis\python\plugins\openlayers_plugin\html gist.github.com/gimoya/6450983 – Kay Sep 5 '13 at 14:37
  • Adding two layers might not been supported by the plugin. I got it working up to zoom 13, see my extended answer. – AndreJ Sep 5 '13 at 15:34
  • Thanks Andre! I got it now - see the working script here: gist.github.com/gimoya/6450983. Strangely I had to remove the eventlistener to get it working... – Kay Sep 5 '13 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.