aboutsummaryrefslogtreecommitdiffstats
path: root/web/js/map-wmts-base.js
blob: c407e76dba12c2be7ba3f8d9b010a7a3b13e6bf8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Functionality required by all OpenLayers WMTS base maps

fixmystreet.maps.setup_wmts_base_map = function() {
    fixmystreet.map_type = OpenLayers.Layer.WMTS;

    // Set DPI - default is 72
    OpenLayers.DOTS_PER_INCH = fixmystreet.wmts_config.tile_dpi;

    fixmystreet.map_options = {
        maxExtent: this.layer_bounds,
        units: 'm',
        scales: fixmystreet.wmts_config.scales
    };

    fixmystreet.layer_options = [];
    $.each(fixmystreet.wmts_config.layer_names, function(i, v) {
        fixmystreet.layer_options.push({
            projection: new OpenLayers.Projection(fixmystreet.wmts_config.map_projection),
            name: v,
            layer: v,
            formatSuffix: fixmystreet.wmts_config.tile_suffix.replace(".", ""),
            matrixSet: fixmystreet.wmts_config.matrix_set,
            requestEncoding: "REST",
            url: fixmystreet.wmts_config.tile_urls[i],
            style: fixmystreet.wmts_config.layer_style,
            matrixIds: fixmystreet.maps.matrix_ids,
            tileOrigin: new OpenLayers.LonLat(fixmystreet.wmts_config.origin_x, fixmystreet.wmts_config.origin_y)
        });
    });

    // Give main code a new bbox_strategy that translates between
    // lat/lon and our WMTS layer's coordinates
    fixmystreet.bbox_strategy = new OpenLayers.Strategy.ReprojectBBOX({
        ratio: 1
    });
};

OpenLayers.Strategy.ReprojectBBOX = OpenLayers.Class(OpenLayers.Strategy.BBOX, {
    getMapBounds: function() {
        // Get the map bounds but return them in lat/lon, not
        // local coordinates
        if (this.layer.map === null) {
            return null;
        }

        var localBounds = this.layer.map.getExtent();
        // Transform bound corners into WGS84
        localBounds.transform( new OpenLayers.Projection(fixmystreet.wmts_config.map_projection), new OpenLayers.Projection("EPSG:4326") );
        return localBounds;
    },

    CLASS_NAME: "OpenLayers.Strategy.ReprojectBBOX"
});