| 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: blue; |
|---|
| 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=ABQIAAAA9XNhd8q0UdwNC7YSO4YZghSPUCi5aRYVveCcVYxzezM4iaj_gxQ9t-UajFL70jfcpquH5l1IJ-Zyyw'></script> |
|---|
| 14 |
<!-- Localhost key --> |
|---|
| 15 |
<!-- <script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTS6gjckBmeABOGXIUiOiZObZESPg'></script>--> |
|---|
| 16 |
<script type="text/javascript" src="http://clients.multimap.com/API/maps/1.1/metacarta_04"></script> |
|---|
| 17 |
<script src='http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js'></script> |
|---|
| 18 |
<script src="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=euzuro-openlayers"></script> |
|---|
| 19 |
<script src="../lib/OpenLayers.js"></script> |
|---|
| 20 |
<script type="text/javascript"> |
|---|
| 21 |
var lon = 5; |
|---|
| 22 |
var lat = 40; |
|---|
| 23 |
var zoom = 5; |
|---|
| 24 |
var map, markers; |
|---|
| 25 |
var barcelona = new OpenLayers.LonLat(2.13134765625, |
|---|
| 26 |
41.37062534198901); |
|---|
| 27 |
var madrid = new OpenLayers.LonLat(-3.6968994140625, |
|---|
| 28 |
40.428314208984375); |
|---|
| 29 |
|
|---|
| 30 |
function init(){ |
|---|
| 31 |
map = new OpenLayers.Map( 'map' ); |
|---|
| 32 |
|
|---|
| 33 |
var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", |
|---|
| 34 |
"http://labs.metacarta.com/wms/vmap0", |
|---|
| 35 |
{layers: 'basic'} ); |
|---|
| 36 |
var google = new OpenLayers.Layer.Google( "Google Hybrid" , {type: G_HYBRID_MAP }); |
|---|
| 37 |
var ve = new OpenLayers.Layer.VirtualEarth( "VE"); |
|---|
| 38 |
var yahoo = new OpenLayers.Layer.Yahoo( "Yahoo"); |
|---|
| 39 |
var mm = new OpenLayers.Layer.MultiMap( "MultiMap"); |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
map.addLayers([wms, google, ve, yahoo, mm]); |
|---|
| 43 |
|
|---|
| 44 |
markers = new OpenLayers.Layer.Markers("markers"); |
|---|
| 45 |
map.addLayer(markers); |
|---|
| 46 |
|
|---|
| 47 |
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom); |
|---|
| 48 |
map.addControl( new OpenLayers.Control.LayerSwitcher() ); |
|---|
| 49 |
map.addControl( new OpenLayers.Control.MousePosition() ); |
|---|
| 50 |
|
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
function add() { |
|---|
| 54 |
var url = 'http://boston.openguides.org/markers/AQUA.png'; |
|---|
| 55 |
var sz = new OpenLayers.Size(10, 17); |
|---|
| 56 |
var calculateOffset = function(size) { |
|---|
| 57 |
return new OpenLayers.Pixel(-(size.w/2), -size.h); |
|---|
| 58 |
}; |
|---|
| 59 |
var icon = new OpenLayers.Icon(url, sz, null, calculateOffset); |
|---|
| 60 |
marker = new OpenLayers.Marker(barcelona, icon); |
|---|
| 61 |
markers.addMarker(marker); |
|---|
| 62 |
|
|---|
| 63 |
marker = new OpenLayers.Marker(madrid, icon.clone()); |
|---|
| 64 |
markers.addMarker(marker); |
|---|
| 65 |
|
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
function remove() { |
|---|
| 69 |
markers.removeMarker(marker); |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
</script> |
|---|
| 73 |
</head> |
|---|
| 74 |
<body onload="init()"> |
|---|
| 75 |
<h1>OpenLayers With WMS, Google, VE Example</h1> |
|---|
| 76 |
<div id="map"></div> |
|---|
| 77 |
<div style="background-color:green" onclick="add()"> click to add a marker to the map</div> |
|---|
| 78 |
<div style="background-color:red" onclick="remove()"> click to remove the marker from the map</div> |
|---|
| 79 |
</body> |
|---|
| 80 |
</html> |
|---|