function TestOverlay(bounds) { this._bounds = bounds; } TestOverlay.prototype = new GOverlay(); TestOverlay.prototype.initialize = function(map) { var div = document.createElement("div"); div.style.border = "2px solid #888888"; div.style.position = "absolute"; map.getPane(G_MAP_MAP_PANE).appendChild(div); this._map = map; this._div = div; } TestOverlay.prototype.remove = function() { this._div.parentNode.removeChild(this._div); } TestOverlay.prototype.copy = function() { return new Rectangle(this._bounds); } TestOverlay.prototype.redraw = function(force) { if (!force) return; var c1 = this._map.fromLatLngToDivPixel(this._bounds.getSouthWest()); var c2 = this._map.fromLatLngToDivPixel(this._bounds.getNorthEast()); this._div.style.width = Math.abs(c2.x - c1.x) + "px"; this._div.style.height = Math.abs(c2.y - c1.y) + "px"; this._div.style.left = (Math.min(c2.x, c1.x) - 2) + "px"; this._div.style.top = (Math.min(c2.y, c1.y) - 2) + "px"; } function initialize() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(37.4419, -122.1419), 13); map.addControl(new GSmallMapControl()); var bounds = map.getBounds(); var southWest = bounds.getSouthWest(); var northEast = bounds.getNorthEast(); var lngDelta = (northEast.lng() - southWest.lng()) / 3; var latDelta = (northEast.lat() - southWest.lat()) / 4; var rectBounds = new GLatLngBounds( new GLatLng(southWest.lat() + latDelta, southWest.lng() + lngDelta), new GLatLng(northEast.lat() - latDelta, northEast.lng() - lngDelta)); map.addOverlay(new TestOverlay(rectBounds)); } } ​
var baseIcon = new GIcon(G_DEFAULT_ICON); baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png"; baseIcon.iconSize = new GSize(20, 34); baseIcon.shadowSize = new GSize(37, 34); baseIcon.iconAnchor = new GPoint(9, 34);
Source: https://habr.com/ru/post/125118/
All Articles