2010.02.26——google map api---折线 多边形
1.GPolyline 折线
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37, 107), 2);
// Create GPolylineOptions argument as an object literal.
// Note that we don't use a constructor.
var polyOptions = {geodesic:true};
var polyline = new GPolyline([
new GLatLng(39.907,116.387),
new GLatLng(39.935,116.407),
new GLatLng(39.924,116.427),
new GLatLng(39.944,116.432)
], "#ff0000", 10, 1, polyOptions);//颜色,粗细,不透明度,测地线
map.addOverlay(polyline);
2.GPolygon 多边形
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(39.9493, 116.3975), 13);
map.addControl(new GSmallMapControl());
GEvent.addListener(map, 'click', function(overlay, latlng) {
var lat = latlng.lat();
var lon = latlng.lng();
var latOffset = 0.01;
var lonOffset = 0.01;
var polygon = new GPolygon([
new GLatLng(lat, lon - lonOffset),
new GLatLng(lat + latOffset, lon),
new GLatLng(lat, lon + lonOffset),
new GLatLng(lat - latOffset, lon),
new GLatLng(lat, lon - lonOffset)
], "#f33f00", 5, 1, "#ff0000", 0.2);//边框颜色,边框粗细,边框透明度,填充颜色,填充不透明度
map.addOverlay(polygon);
});
3.GPolygon非常有用,但是它不能创建图像,
而GGroundOverlay 在地图中创建矩形图像叠加层
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(36.0, 113), 12);
var boundaries = new GLatLngBounds(new GLatLng(35.5, 112), new GLatLng(36.5, 114));
//GGroundOverlay 的构造函数将图像的网址和图像的 GLatLngBounds 作为参数。GLatLngBounds 实例代表矩形
var oldmap = new GGroundOverlay("http://www.lib.utexas.edu/maps/historical/newark_nj_1922.jpg", boundaries);
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.addOverlay(oldmap);