Google Maps integration
GeoWebCache can support Google Maps clients.
Please see the Google Maps API documentation on details on creating custom Google Maps demos. To integrate a layer served by GeoWebCache with Google Maps, you can use the following HTML code as a template.
<!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps with GeoWebCache</title>
<script src='http://maps.google.com/maps?file=api&v=2&key=GOOGLE_MAPS_API_KEY'></script>
<script type="text/javascript">
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(39, -96), 4);
var tilelayer = new GTileLayer(null, null, null, {
tileUrlTemplate: 'http://EXAMPLE.COM:PORT/GEOWEBCACHE_PATH/gmaps?layers=YOUR_LAYER&zoom={Z}&x={X}&y={Y}',
isPng:true,
opacity:0.5 }
);
var myTileLayer = new GTileLayerOverlay(tilelayer);
map.addOverlay(myTileLayer);
}
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width: 500px; height: 300px"></div>
</body>
</html>
A few notes on the above template:
1.
<script src='http://maps.google.com/maps?file=api&v=2&key=GOOGLE_MAPS_API_KEY'></script>
Replace the string GOOGLE_MAPS_API_KEY with a valid Google Maps API key. Sign up for a key.
2.
tileUrlTemplate: 'http://EXAMPLE.COM:PORT/GEOWEBCACHE_PATH/gmaps?layers=YOUR_LAYER&zoom={Z}&x={X}&y={Y}',
This line is where the URL containing the layer served by GeoWebCache is explicitly invoked. Change EXAMPLE.COM:PORT to your website and port number. Change GEOWEBCACHE_PATH to the path of your GeoWebCache instance (Examples: /geowebcache or /geoserver/gwc/service). Change YOUR_LAYER to the name of your layer (Example: topp:states)
For more information on syntax in this example, please see the Google Maps API documentation.
