O exemplo seguinte, visa a inserção de um mapa na página. Os construtores de mapa do Virtual Earth e dos mapas do SAPO, recebem ambos o id do div onde se deverá inserir o mapa.
var vemap = new VEMap("ve_div");
vemap.LoadMap(new VELatLong(38.7115479, -9.13774));
var smap = new SAPO.Maps.Map('sapo_div');
vemap.HideDashboard();
smap.addControl(new SAPO.Maps.Control.MapTypeControl()); smap.addControl(new SAPO.Maps.Control.NavigationControl());
Neste exemplo altera-se o tipo de vista do mapa para a vista híbrida.
vemap.SetMapStyle(VEMapStyle.Hybrid);
smap.setBaseLayer(smap.getBaseLayers().HYBRID_MAP);
Neste exemplo é adicionado um marcador sobre o mapa.
var pushPin = new VEShape(VEShapeType.Pushpin, new VELatLong(38.7115479, -9.13774)); vemap.AddShape(pushPin);
var marker = new SAPO.Maps.Marker(new OpenLayers.LonLat(-9, 38),
{draggable: true});
smap.addOverlay(marker);
pushPin.SetTitle("<h1>Hello World!</h1>");
pushPin.SetDescription("Hello World!");
var html = '<h1>Hello World!</h1><br />';
marker.registerEvent('click', this, function(marker){ marker.openPopup(html); });
Neste exemplo adiciona-se uma linha sobre o mapa que passa por pontos definidos pelo utilizador.
var polyline = new VEShape(VEShapeType.Polyline, [new VELatLong(31.27559953357264, -3.293155625192997), new VELatLong(40.04179395913183, -1.0079993752842318), new VELatLong(42.22596032057589, -6.281436875073691) ]); polyline.SetLineWidth(3); polyline.SetLineColor(new VEColor(255, 0, 255, 0.5)); vemap.AddShape(polyline);
var polyline = new SAPO.Maps.Polyline(
[new OpenLayers.LonLat(-3.293155625192997, 31.27559953357264),
new OpenLayers.LonLat(-1.0079993752842318, 40.04179395913183),
new OpenLayers.LonLat(-6.281436875073691, 42.22596032057589) ],
{ strokeColor: "#FF00FF",
strokeWidth: 3,
strokeOpacity: 0.5
});
smap.addOverlay(polyline);
Neste exemplo quando se clica em cima da linha, o estilo desta é alterado.
polyline.registerEvent('click', this, function(polyline){
polyline.setStyle({
strokeColor: "#FFFFFF",
strokeWidth: 6,
strokeOpacity: 1
});
Neste exemplo é adicionado um polígono com as arestas definidas nos pontos dados pelo utilizador.
var polyline = new VEShape(VEShapeType.Polygon, [new VELatLong(48.86244306657123, 8.835750624322754), new VELatLong(36.17056935092968, 11.03301624923503), new VELatLong(36.947132080844966, 23.337703748743763), new VELatLong(49.26555120881505, 20.613094373852547) ]); polyline.SetLineWidth(2); polyline.SetLineColor(new VEColor(255, 0, 255, 0.5)); polyline.SetFillColor(new VEColor(255, 0, 255, 0.5)); vemap.AddShape(polyline);
var polygon = new SAPO.Maps.Polygon(
[new OpenLayers.LonLat(8.835750624322754, 48.86244306657123),
new OpenLayers.LonLat(11.03301624923503, 36.17056935092968),
new OpenLayers.LonLat(23.337703748743763, 36.947132080844966),
new OpenLayers.LonLat(20.613094373852547, 49.26555120881505)],
{
strokeColor: "#FF00FF",
strokeOpacity: 0.5,
strokeWidth: 2,
fillColor: '#FF00FF',
fillOpacity: 0.5
});
smap.addOverlay(polygon);
Neste exemplo quando se clica em cima do polígono, o estilo deste é alterado.
polygon.registerEvent('click', this, function(polygon){
polygon.setStyle({
strokeColor: "#FFFFFF",
strokeOpacity: 1,
strokeWidth: 6,
fillColor: '#FFFFFF',
fillOpacity: 1 });
});