Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4 from bogdanvaduva/master
Browse files Browse the repository at this point in the history
OL3 v3.7.0 problems
  • Loading branch information
schivei committed Jul 16, 2015
2 parents a23619e + 3c5ef57 commit 944c61a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Options
| `layer` | string | `map` | `map`, `terrain`, `terrain+`, `hybrid` and `satellite` | Here you can choose the type of base map |
| `resolutions` | array | `[28..1]` | n array positions | Some image resolutions |
| `origin` | array | `[0,0]` | `[x,y]` | The center map origin |
| `ol_version` | string | `v3.7.0+` | `` | OL3 version |

###Returns `ol.source.XYZ`

Expand Down
8 changes: 8 additions & 0 deletions ol-source-gmaps-tms.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ol.source.GMapsTMS = (options) ->
layer: 'map'
resolutions: resolutions
origin: origin
ol_version = 'v3.7.0+'

if typeof options is 'undefined' or !options
options = defaults
Expand All @@ -18,6 +19,9 @@ ol.source.GMapsTMS = (options) ->
if typeof options.origin is 'undefined' or !options.origin
options.origin = origin

if typeof options.ol_version is 'undefined' or !options.ol_version
options.ol_version = ol_version

type = 'm'

switch options.layer
Expand All @@ -28,6 +32,10 @@ ol.source.GMapsTMS = (options) ->
when 'hybrid' then type = 'y'
else options.layer = 'map'

if options.ol_version == 'v3.7.0+' then
return new ol.source.XYZ
url: 'http://mt.google.com/vt/lyrs=' + type + '&x={x}&y={y}&z={z}'
else
return new ol.source.XYZ
crossOrigin : null
tileUrlFunction : (coord) ->
Expand Down
46 changes: 28 additions & 18 deletions ol-source-gmaps-tms.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {
ol.source.GMapsTMS = function(options) {
var defaults, origin, resolutions, type, _i, _results;
var defaults, origin, resolutions, type, _i, _results,ol_version;
resolutions = (function() {
_results = [];
for (_i = 28; _i >= 1; _i--){ _results.push(_i); }
Expand All @@ -12,6 +12,7 @@
resolutions: resolutions,
origin: origin
};
ol_version = 'v3.7.0+';
if (typeof options === 'undefined' || !options) {
options = defaults;
}
Expand All @@ -24,6 +25,9 @@
if (typeof options.origin === 'undefined' || !options.origin) {
options.origin = origin;
}
if (typeof options.ol_version === 'undefined' || !options.ol_version) {
options.ol_version = ol_version;
}
type = 'm';
switch (options.layer) {
case 'map':
Expand All @@ -44,23 +48,29 @@
default:
options.layer = 'map';
}
return new ol.source.XYZ({
crossOrigin: null,
tileUrlFunction: function(coord) {
var x, y, z;
if (!coord) {
return '';
}
z = coord[0];
x = coord[1];
y = coord[2];
return "http://mt.google.com/vt/lyrs=" + type + "&x=" + x + "&y=" + y + "&z=" + z;
},
tileGrid: new ol.tilegrid.TileGrid({
origin: options.origin,
resolutions: options.resolutions
})
});
if (options.ol_version === 'v3.7.0+') {
return new ol.source.XYZ({
url: 'http://mt.google.com/vt/lyrs=' + type + '&x={x}&y={y}&z={z}'
});
} else {
return new ol.source.XYZ({
crossOrigin: null,
tileUrlFunction: function(coord) {
var x, y, z;
if (!coord) {
return '';
}
z = coord[0];
x = coord[1];
y = coord[2];
return "http://mt.google.com/vt/lyrs=" + type + "&x=" + x + "&y=" + y + "&z=" + z;
},
tileGrid: new ol.tilegrid.TileGrid({
origin: options.origin,
resolutions: options.resolutions
})
});
}
};

}).call(this);

0 comments on commit 944c61a

Please sign in to comment.