| 1 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
|---|
| 2 |
<head> |
|---|
| 3 |
<style type="text/css"> |
|---|
| 4 |
#map { |
|---|
| 5 |
width: 100%; |
|---|
| 6 |
height: 512px; |
|---|
| 7 |
border: 1px solid black; |
|---|
| 8 |
background-color: red; |
|---|
| 9 |
} |
|---|
| 10 |
</style> |
|---|
| 11 |
|
|---|
| 12 |
<!-- this gmaps key generated for http://openlayers.org/dev/ --> |
|---|
| 13 |
<script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script> |
|---|
| 14 |
<!-- Localhost key --> |
|---|
| 15 |
<!-- <script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTS6gjckBmeABOGXIUiOiZObZESPg'></script>--> |
|---|
| 16 |
<script src="../lib/OpenLayers.js"></script> |
|---|
| 17 |
<script type="text/javascript"> |
|---|
| 18 |
var lon = 5; |
|---|
| 19 |
var lat = 40; |
|---|
| 20 |
var zoom = 17; |
|---|
| 21 |
var map, layer; |
|---|
| 22 |
|
|---|
| 23 |
function init(){ |
|---|
| 24 |
map = new OpenLayers.Map( 'map' , |
|---|
| 25 |
{ controls: [new OpenLayers.Control.MouseDefaults()] , 'numZoomLevels':20}); |
|---|
| 26 |
|
|---|
| 27 |
var satellite = new OpenLayers.Layer.Google( "Google Satellite" , {type: G_SATELLITE_MAP, 'maxZoomLevel':18} ); |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
map.addLayers([satellite]); |
|---|
| 31 |
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", |
|---|
| 32 |
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic', 'transparent':true}, |
|---|
| 33 |
{isBaseLayer: false} ); |
|---|
| 34 |
layer.setVisibility(false); |
|---|
| 35 |
var twms = new OpenLayers.Layer.WMS( "World Map", |
|---|
| 36 |
"http://world.freemap.in/cgi-bin/mapserv?", |
|---|
| 37 |
{map: '/www/freemap.in/world/map/factbooktrans.map', transparent:'true', |
|---|
| 38 |
layers: 'factbook', 'format':'png'}, {'reproject': true} ); |
|---|
| 39 |
map.addLayer(twms); |
|---|
| 40 |
markers = new OpenLayers.Layer.Markers("markers"); |
|---|
| 41 |
map.addLayer(markers); |
|---|
| 42 |
|
|---|
| 43 |
map.setCenter(new OpenLayers.LonLat(10.205188,48.857593), 5); |
|---|
| 44 |
map.addControl( new OpenLayers.Control.LayerSwitcher() ); |
|---|
| 45 |
map.addControl( new OpenLayers.Control.PanZoomBar() ); |
|---|
| 46 |
|
|---|
| 47 |
} |
|---|
| 48 |
|
|---|
| 49 |
function add() { |
|---|
| 50 |
|
|---|
| 51 |
var url = 'http://boston.openguides.org/markers/AQUA.png'; |
|---|
| 52 |
var sz = new OpenLayers.Size(10, 17); |
|---|
| 53 |
var calculateOffset = function(size) { |
|---|
| 54 |
return new OpenLayers.Pixel(-(size.w/2), -size.h); |
|---|
| 55 |
}; |
|---|
| 56 |
var icon = new OpenLayers.Icon(url, sz, null, calculateOffset); |
|---|
| 57 |
var barcelona = new OpenLayers.LonLat(2.13134765625, |
|---|
| 58 |
41.37062534198901); |
|---|
| 59 |
marker = new OpenLayers.Marker(barcelona, icon); |
|---|
| 60 |
markers.addMarker(marker); |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
function remove() { |
|---|
| 64 |
markers.removeMarker(marker); |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
</script> |
|---|
| 68 |
</head> |
|---|
| 69 |
<body onload="init()"> |
|---|
| 70 |
<h1>OpenLayers With Google Layer Example</h1> |
|---|
| 71 |
<div id="map"></div> |
|---|
| 72 |
<div style="background-color:green" onclick="add()"> click to add a marker to the map</div> |
|---|
| 73 |
<div style="background-color:red" onclick="remove()"> click to remove the marker from the map</div> |
|---|
| 74 |
</body> |
|---|
| 75 |
</html> |
|---|