我想知道是否可以在 primefaces 中创建一个 GMap 组件,该组件使用自定义图块来呈现地图。我知道如何在纯 javascript ( http://econym.org.uk/gmap/example_custommap1.htm ) 中做到这一点:
var map = new GMap(document.getElementById("map"));
map.addControl(new GScaleControl());
var copyright = new GCopyright(1,new GLatLngBounds(new GLatLng(53.8136257,-3.0981445),new GLatLng(53.8654855,-2.9663944) ),14, "Ordnance Survey");
var copyrightCollection = new GCopyrightCollection('Map Data:');
copyrightCollection.addCopyright(copyright);
CustomGetTileUrl=function(a,b){
return "tiles/"+a.x+"_"+a.y+".jpg"
}
var tilelayers = [new GTileLayer(copyrightCollection,14,14)];
tilelayers[0].getTileUrl = CustomGetTileUrl;
var custommap = new GMapType(tilelayers, new GMercatorProjection(15), "Old OS");
map.addMapType(custommap);
map.setCenter(new GLatLng(53.852,-3.038), 14, custommap);
但我不知道如何在primefaces中做到这一点。
如果不可能,您是否知道应该如何通过 javascript 修改 GMap 组件以替换 getTileUrl?
编辑
正如 Duncan 注意到的,上面的代码是 v2(我的原始代码是 v3,但真的很乱,所以我从 Internet 上获取了第一个工作片段,没有检查版本......),完整的 v3 代码应该如下所示:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map-canvas { height: 100% }
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
function initialize() {
var mapOptions= {
center : new google.maps.LatLng(0,0),
rotateControl : true,
panControl : true,
zoom : 2,
streetViewControl : false,
mapTypeControlOptions : {
mapTypeIds : ['cv0']
}
};
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
var option = {
getTileUrl : function(coord, zoom) {
var tileRange = 15;
if (coord.y < 0 || coord.y >= tileRange || coord.x < 0 || coord.x >= tileRange) {
return null;
}
var addr = "../map_images/new7778069575062411171/5/" + coord.x + "," + coord.y + ".PNG";
return addr;
},
tileSize : new google.maps.Size(256,256),
maxZoom : 2,
minZoom : 2,
name : "title"
};
map.mapTypes.set('cv0', new google.maps.ImageMapType(option));
map.setMapTypeId('cv0');
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"/>
</body>
</html>