我可以显示自定义图块,但浏览器也在它们下面加载Google的标准地图图块。如果用户平移到边缘,这会降低性能,并使地图看起来很奇怪。任何想法如何防止法线贴图图层?
最后,ui-gmap-map-type
即使保留了parent,我仍然避免使用该指令ui-gmap-google-map
。相反,我等待google.maps
&$scope.map.control
对象加载,然后使用该mapTypes.set()
方法指向我自己的图像图块集。
index.html
<ui-gmap-google-map control='map.control'>
<!-- marker & polygon directives -->
</ui-gmap-google-map>
controller.js
$scope.map = {
control: {}
};
uiGmapGoogleMapApi.then(function(maps) {
var moonMapType = new maps.ImageMapType({
getTileUrl: function(coord, zoom) {
var normalizedCoord = getNormalizedCoord(coord, zoom);
if (!normalizedCoord) {
return null;
}
var bound = Math.pow(2, zoom);
return 'http://mw1.google.com/mw-planetary/lunar/lunarmaps_v1/clem_bw' +
'/' + zoom + '/' + normalizedCoord.x + '/' +
(bound - normalizedCoord.y - 1) + '.jpg';
},
tileSize: new maps.Size(256, 256),
maxZoom: 9,
minZoom: 0,
radius: 1738000,
name: 'Moon'
});
$scope.$watch("map.control", function( mapControl, emptyObj ) {
mapControl.mapTypes.set('moon', moonMapType);
mapControl.setMapTypeId('moon');
});
}
// Normalizes the coords that tiles repeat across the x axis (horizontally)
// like the standard Google map tiles.
function getNormalizedCoord(coord, zoom) {
var y = coord.y;
var x = coord.x;
// tile range in one direction range is dependent on zoom level
// 0 = 1 tile, 1 = 2 tiles, 2 = 4 tiles, 3 = 8 tiles, etc
var tileRange = 1 << zoom;
// don't repeat across y-axis (vertically)
if (y < 0 || y >= tileRange) {
return null;
}
// repeat across x-axis
if (x < 0 || x >= tileRange) {
x = (x % tileRange + tileRange) % tileRange;
}
return {x: x, y: y};
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句