custom gmap type


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. if (GBrowserIsCompatible()) {
  2.  
  3. //copyright && copyright collection
  4. var copyOSM = new GCopyrightCollection('<a href="http://www.openstreetmap.org/">OpenStreetMap</a>');
  5.  
  6. // apply the statement to the whole world
  7. copyOSM.addCopyright(new GCopyright(1,
  8. new GLatLngBounds(new GLatLng(-90, -180), new GLatLng(90, 180)), // region
  9. 0, // minimum zoom level
  10. ' ' // no additional copyright message, but empty string hides entire copyright
  11. ));
  12.  
  13. // create a tile layer
  14. var tilesMapnik = new GTileLayer(
  15. copyOSM, // copyright statement
  16. 7, // minimum zoom level
  17. 18, // maximum zoom level
  18. {
  19. // options includes URL template for addressing individual tiles
  20. // X, Y, Z respectively are tile coordinates for lattitude and longitude,
  21. // and the zoom level
  22. tileUrlTemplate: 'http://tile.openstreetmap.org/{Z}/{X}/{Y}.png',
  23. isPng: true // otherwize assumes GIF images
  24. }
  25. );
  26.  
  27. //map type
  28. var mapMapnik = new GMapType(
  29. [tilesMapnik], // list of layers
  30. G_NORMAL_MAP.getProjection(), // borrow the Mercator projection from the standard map
  31. 'OSM' // name should be short enough to fit in button
  32. );
  33.  
  34.  
  35. var map = new GMap2(document.getElementById("map"));
  36. map.setCenter(new GLatLng(37, 0), 4);
  37.  
  38.  
  39. map.addMapType(mapMapnik);
  40. map.addControl(new GLargeMapControl());
  41. map.addControl(new GOverviewMapControl());
  42. map.addControl(new GScaleControl());
  43.  
  44. map.setMapType(mapMapnik);
  45.  
  46. map.enableDoubleClickZoom();
  47. map.enableContinuousZoom();
  48. map.enableScrollWheelZoom();
  49.  
  50.  
  51.  
  52. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.