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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
function calculateBBOX(coordinates,zoomlvl){
var bbox = '479406.21274558,6807170.2079419,484298.18255515,6812062.1777515';
var lULP = new google.maps.Point(coordinates.x*256,(coordinates.y+1)*256);
var lLRP = new google.maps.Point((coordinates.x+1)*256,coordinates.y*256);
var projectionMap = new MercatorProjection();
var lULg = projectionMap.fromDivPixelToSphericalMercator(lULP, zoomlvl);
var lLRg = projectionMap.fromDivPixelToSphericalMercator(lLRP, zoomlvl);
var lUL_Latitude = lULg.y;
var lUL_Longitude = lULg.x;
var lLR_Latitude = lLRg.y;
var lLR_Longitude = lLRg.x;
//GJ: there is a bug when crossing the -180 longitude border (tile does not render) - this check seems to fix it
if (lLR_Longitude < lUL_Longitude){
lLR_Longitude = Math.abs(lLR_Longitude);
}
bbox= lUL_Longitude + "," + lUL_Latitude + "," + lLR_Longitude + "," + lLR_Latitude;
return bbox;
}
function bound(value, opt_min, opt_max) {
if (opt_min != null) value = Math.max(value, opt_min);
if (opt_max != null) value = Math.min(value, opt_max);
return value;
}
function degreesToRadians(deg) {
return deg * (Math.PI / 180);
}
function radiansToDegrees(rad) {
return rad / (Math.PI / 180);
}
function MercatorProjection() {
var MERCATOR_RANGE = 256;
this.pixelOrigin_ = new google.maps.Point(
MERCATOR_RANGE / 2, MERCATOR_RANGE / 2);
this.pixelsPerLonDegree_ = MERCATOR_RANGE / 360;
this.pixelsPerLonRadian_ = MERCATOR_RANGE / (2 * Math.PI);
};
MercatorProjection.prototype.fromLatLngToPoint = function(latLng, opt_point) {
var me = this;
var point = opt_point || new google.maps.Point(0, 0);
var origin = me.pixelOrigin_;
point.x = origin.x + latLng.lng() * me.pixelsPerLonDegree_;
// NOTE(appleton): Truncating to 0.9999 effectively limits latitude to
// 89.189. This is about a third of a tile past the edge of the world tile.
var siny = bound(Math.sin(degreesToRadians(latLng.lat())), -0.9999, 0.9999);
point.y = origin.y + 0.5 * Math.log((1 + siny) / (1 - siny)) * -me.pixelsPerLonRadian_;
return point;
};
MercatorProjection.prototype.fromDivPixelToLatLng = function(pixel, zoom) {
var me = this;
var origin = me.pixelOrigin_;
var scale = Math.pow(2, zoom);
var lng = (pixel.x / scale - origin.x) / me.pixelsPerLonDegree_;
var latRadians = (pixel.y / scale - origin.y) / -me.pixelsPerLonRadian_;
var lat = radiansToDegrees(2 * Math.atan(Math.exp(latRadians)) - Math.PI / 2);
return new google.maps.LatLng(lat, lng);
};
MercatorProjection.prototype.fromDivPixelToSphericalMercator = function(pixel, zoom) {
var me = this;
var coord = me.fromDivPixelToLatLng(pixel, zoom);
var r= 6378137.0;
var x = r* degreesToRadians(coord.lng());
var latRad = degreesToRadians(coord.lat());
var y = (r/2) * Math.log((1+Math.sin(latRad))/ (1-Math.sin(latRad)));
return new google.maps.Point(x,y);
};
function initialize(init) {
if(map) {
map.unbindAll()
}
geocoder = new google.maps.Geocoder();
sv = new google.maps.StreetViewService();
var latlng = new google.maps.LatLng(start.split(',')[0],start.split(',')[1]);
counter = 0;
function CoordMapType(tileSize) {
this.tileSize = tileSize;
}
CoordMapType.prototype.getTile = function(coord, zoom, ownerDocument) {
var div = ownerDocument.createElement('div');
var bbox = calculateBBOX(coord,zoom);
var url = 'https://wxs.ign.fr/VOTRECLEAPI/inspire/v/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&LAYERS=BU.Building,AD.Address&STYLES=&CRS=EPSG:3857&BBOX='+bbox+'&WIDTH=256&HEIGHT=256&FORMAT=image/png&TRANSPARENT=TRUE&EXCEPTIONS=XML';
div.innerHTML = '<img src="'+url+'" />';
div.style.width = this.tileSize.width + 'px';
div.style.height = this.tileSize.height + 'px';
return div;
};
var mapOptions = {
zoom: 11,
center: latlng,
streetViewControl: true,
mapTypeId: 'roadmap',
mapTypeId: 'IGNLayer',
mapTypeId: 'hybrid',
center: new google.maps.LatLng(48.689179,2.510981),
zoom: 10,
mapTypeControlOptions: {
mapTypeIds: ['IGNLayer','roadmap','hybrid']
}
}
map = new google.maps.Map($('#map-canvas')[0],mapOptions);
map.overlayMapTypes.insertAt(0, new CoordMapType(new google.maps.Size(256, 256)));
var myStyles =[
{
"featureType": "poi",
"elementType": "all",
"stylers": [
{ "visibility": "off" }
]
},{
"featureType": "transit",
"stylers": [
{ "visibility": "off" }
]
}
]
map.setOptions({styles: myStyles});
} |
Partager