diff options
| -rw-r--r-- | www/index.html | 1 | ||||
| -rw-r--r-- | www/js/config.js-example | 4 | ||||
| -rw-r--r-- | www/js/map-bing-ol.js | 58 | ||||
| -rw-r--r-- | www/js/map-bing.js | 22 | ||||
| -rw-r--r-- | www/js/map-fms.js | 72 | 
5 files changed, 99 insertions, 58 deletions
diff --git a/www/index.html b/www/index.html index 5cd55ae..ca8607a 100644 --- a/www/index.html +++ b/www/index.html @@ -48,6 +48,7 @@          <script type="text/javascript" src="js/OpenLayers.fixmystreet.js"></script>          <script type="text/javascript" src="js/map-OpenLayers.js"></script>          <script type="text/javascript" src="js/map-bing-ol.js"></script> +        <script type="text/javascript" src="js/map-fms.js"></script>          <script type="text/javascript" src="js/locate.js"></script>          <script type="text/javascript" src="js/strings.js"></script> diff --git a/www/js/config.js-example b/www/js/config.js-example index 3e69b2d..75c66f9 100644 --- a/www/js/config.js-example +++ b/www/js/config.js-example @@ -28,6 +28,6 @@ var CONFIG = {      // Set to 1 to log debug messages to the console      DEBUG: 0, -    // Whether the FMS installation is within the United Kingdom. Should not need to change. -    isUK: 0 +    // Bing Maps API key if needed +    BING_MAPS_API_KEY: ''  }; diff --git a/www/js/map-bing-ol.js b/www/js/map-bing-ol.js index c349f41..2c5c635 100644 --- a/www/js/map-bing-ol.js +++ b/www/js/map-bing-ol.js @@ -1,4 +1,4 @@ -function set_map_config() { +function _set_map_config() {      var nav_opts = { zoomWheelEnabled: false };      //if (fixmystreet.page == 'around' && $('html').hasClass('mobile')) {          nav_opts = {}; @@ -11,6 +11,10 @@ function set_map_config() {          fixmystreet.nav_control,          new OpenLayers.Control.PanZoomFMS({id: 'fms_pan_zoom' })      ]; +} + +function set_map_config(perm) { +    _set_map_config();      fixmystreet.map_type = OpenLayers.Layer.Bing;  } @@ -20,19 +24,9 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {      setMap: function() {          OpenLayers.Layer.XYZ.prototype.setMap.apply(this, arguments);          this.updateAttribution(); -        this.map.events.register("moveend", this, this.updateAttribution);      }, -    updateAttribution: function() { -        var z = this.map.getZoom() + this.zoomOffset; -        var copyrights; -        var logo = ''; -        if (z >= 16 && CONFIG.isUK) { -            copyrights = 'Contains Ordnance Survey data © Crown copyright and database right 2010'; -        } else { -            logo = '<a href="http://www.bing.com/maps/"><img border=0 src="http://dev.virtualearth.net/Branding/logo_powered_by.png"></a>'; -            copyrights = '© 2011 <a href="http://www.bing.com/maps/">Microsoft</a>. © AND, Navteq, Ordnance Survey'; -        } +    _updateAttribution: function(copyrights, logo) {          this.attribution = OpenLayers.String.format(this.attributionTemplate, {              logo: logo,              copyrights: copyrights @@ -45,16 +39,20 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {          }      }, +    updateAttribution: function() { +        var copyrights = '© 2011 <a href="https://www.bing.com/maps/">Microsoft</a>. © AND, Navteq'; +        var logo = '<a href="https://www.bing.com/maps/"><img border=0 src="//dev.virtualearth.net/Branding/logo_powered_by.png"></a>'; +        this._updateAttribution(copyrights, logo); +    }, +      initialize: function(name, options) {          var url = [];          options = OpenLayers.Util.extend({              /* Below line added to OSM's file in order to allow minimum zoom level */ -            maxResolution: 156543.0339/Math.pow(2, options.zoomOffset || 0), -            numZoomLevels: 18, -            transitionEffect: "resize", +            maxResolution: 156543.03390625/Math.pow(2, options.zoomOffset || 0), +            numZoomLevels: 19,              sphericalMercator: true,              buffer: 0 -            //attribution: "© Microsoft / OS 2010"          }, options);          var newArguments = [name, url, options];          OpenLayers.Layer.XYZ.prototype.initialize.apply(this, newArguments); @@ -86,24 +84,7 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {              OpenLayers.Util.indexOf(this.serverResolutions, res) :              this.map.getZoom() + this.zoomOffset; -        var url; -        if (z >= 16 && CONFIG.isUK) { -            url = [ -                "http://tilma.mysociety.org/sv/${z}/${x}/${y}.png", -                "http://a.tilma.mysociety.org/sv/${z}/${x}/${y}.png", -                "http://b.tilma.mysociety.org/sv/${z}/${x}/${y}.png", -                "http://c.tilma.mysociety.org/sv/${z}/${x}/${y}.png" -            ]; -        } else { -            var type = ''; -            if (z > 10 && CONFIG.isUK) { type = '&productSet=mmOS'; } -            url = [ -                "http://ecn.t0.tiles.virtualearth.net/tiles/r${id}.png?g=701" + type, -                "http://ecn.t1.tiles.virtualearth.net/tiles/r${id}.png?g=701" + type, -                "http://ecn.t2.tiles.virtualearth.net/tiles/r${id}.png?g=701" + type, -                "http://ecn.t3.tiles.virtualearth.net/tiles/r${id}.png?g=701" + type -            ]; -        } +        var url = this.get_urls(bounds, z);          var s = '' + x + y + z;          url = this.selectUrl(s, url); @@ -112,5 +93,14 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {          return path;      }, +    get_urls: function(bounds, z) { +        return [ +            "https://ecn.t0.tiles.virtualearth.net/tiles/r${id}.png?g=3467", +            "https://ecn.t1.tiles.virtualearth.net/tiles/r${id}.png?g=3467", +            "https://ecn.t2.tiles.virtualearth.net/tiles/r${id}.png?g=3467", +            "https://ecn.t3.tiles.virtualearth.net/tiles/r${id}.png?g=3467" +        ]; +    }, +      CLASS_NAME: "OpenLayers.Layer.Bing"  }); diff --git a/www/js/map-bing.js b/www/js/map-bing.js deleted file mode 100644 index 715a8ef..0000000 --- a/www/js/map-bing.js +++ /dev/null @@ -1,22 +0,0 @@ -$(function(){ -    var centre = new Microsoft.Maps.Location( fixmystreet.latitude, fixmystreet.longitude ); -    var map = new Microsoft.Maps.Map(document.getElementById("map"), { -        credentials: fixmystreet.key, -        mapTypeId: Microsoft.Maps.MapTypeId.ordnanceSurvey, -        center: centre, -        zoom: 15, -        enableClickableLogo: false, -        enableSearchLogo: false, -        showCopyright: false, -        showDashboard: true, -        showLogo: false, -        showScalebar: false -    }); -        //minZoomLevel: 14, -        //numZoomLevels: 4 - -    Microsoft.Maps.Events.addHandler(map, "viewchangestart", function(e) { -        /* Doesn't work */ -        if (map.getTargetZoom() < 12) { return false; } -    }); -}); diff --git a/www/js/map-fms.js b/www/js/map-fms.js new file mode 100644 index 0000000..598665b --- /dev/null +++ b/www/js/map-fms.js @@ -0,0 +1,72 @@ +var fms_tile_base = [ [ '', 'a-', 'b-', 'c-' ], 'https://{S}tilma.mysociety.org/sv' ]; + +function set_map_config(perm) { +    _set_map_config(); +    fixmystreet.map_type = OpenLayers.Layer.BingUK; +} + +OpenLayers.Layer.BingUK = OpenLayers.Class(OpenLayers.Layer.Bing, { +    uk_bounds: [ +        new OpenLayers.Bounds(-6.6, 49.8, 1.102680, 51), +        new OpenLayers.Bounds(-5.4, 51, 2.28, 54.94), +        new OpenLayers.Bounds(-5.85, 54.94, -1.15, 55.33), +        new OpenLayers.Bounds(-9.35, 55.33, -0.7, 60.98) +    ], + +    in_uk: function(c) { +        c = c.clone(); +        c.transform( +            fixmystreet.map.getProjectionObject(), +            new OpenLayers.Projection("EPSG:4326") +        ); +        if ( this.uk_bounds[0].contains(c.lon, c.lat) || this.uk_bounds[1].contains(c.lon, c.lat) || this.uk_bounds[2].contains(c.lon, c.lat) || this.uk_bounds[3].contains(c.lon, c.lat) ) { +            return true; +        } +        return false; +    }, + +    setMap: function() { +        OpenLayers.Layer.Bing.prototype.setMap.apply(this, arguments); +        this.map.events.register("moveend", this, this.updateAttribution); +    }, + +    updateAttribution: function() { +        var z = this.map.getZoom() + this.zoomOffset; +        var copyrights; +        var logo = ''; +        var c = this.map.getCenter(); +        var in_uk = c ? this.in_uk(c) : true; +        if (z >= 16 && in_uk) { +            copyrights = 'Contains Ordnance Survey data © Crown copyright and database right 2014'; +        } else { +            logo = '<a href="https://www.bing.com/maps/"><img border=0 src="https://dev.virtualearth.net/Branding/logo_powered_by.png"></a>'; +            copyrights = '© 2011 <a href="https://www.bing.com/maps/">Microsoft</a>. © AND, Navteq, Ordnance Survey'; +        } +        this._updateAttribution(copyrights, logo); +    }, + +    get_urls: function(bounds, z) { +        var urls; +        var in_uk = this.in_uk(bounds.getCenterLonLat()); +        if (z >= 16 && in_uk) { +            urls = []; +            for (var i=0; i< fms_tile_base[0].length; i++) { +                urls.push( fms_tile_base[1].replace('{S}', fms_tile_base[0][i]) + "/${z}/${x}/${y}.png" ); +            } +        } else { +            var type = ''; +            if (z > 10 && in_uk) { +                type = '&productSet=mmOS&key=' + CONFIG.BING_MAPS_API_KEY; +            } +            urls = [ +                "https://ecn.t0.tiles.virtualearth.net/tiles/r${id}.png?g=3467" + type, +                "https://ecn.t1.tiles.virtualearth.net/tiles/r${id}.png?g=3467" + type, +                "https://ecn.t2.tiles.virtualearth.net/tiles/r${id}.png?g=3467" + type, +                "https://ecn.t3.tiles.virtualearth.net/tiles/r${id}.png?g=3467" + type +            ]; +        } +        return urls; +    }, + +    CLASS_NAME: "OpenLayers.Layer.BingUK" +});  | 
