Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var overlay;
- USGSOverlay.prototype = new google.maps.OverlayView();
- var info = new google.maps.InfoWindow();
- function initialize() {
- var mapOptions = {
- zoom: 0,
- disableDefaultUI: true,
- streetViewControl: false,
- navigationControl: false,
- zoomControl: false,
- scaleControl: false,
- scrollwheel: false,
- disableDoubleClickZoom: true,
- center: new google.maps.LatLng(28.70, -127.50),
- mapTypeId: google.maps.MapTypeId.ROADMAP
- };
- var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
- var marker = new google.maps.Marker({
- position: map.getCenter(),
- map: map
- });
- var swBound = new google.maps.LatLng(62.281819, -150.287132);
- var neBound = new google.maps.LatLng(62.400471, -150.005608);
- var bounds = new google.maps.LatLngBounds(swBound, neBound);
- var allowedBounds = new google.maps.LatLngBounds(
- new google.maps.LatLng(28.70, -127.50),
- new google.maps.LatLng(48.85, -55.90)
- );
- var boundLimits = {
- maxLat : allowedBounds.getNorthEast().lat(),
- maxLng : allowedBounds.getNorthEast().lng(),
- minLat : allowedBounds.getSouthWest().lat(),
- minLng : allowedBounds.getSouthWest().lng()
- };
- var lastValidCenter = map.getCenter();
- var newLat, newLng;
- google.maps.event.addListener(map, 'center_changed', function() {
- center = map.getCenter();
- if (allowedBounds.contains(center)) {
- lastValidCenter = map.getCenter();
- return;
- }
- newLat = lastValidCenter.lat();
- newLng = lastValidCenter.lng();
- if(center.lng() > boundLimits.minLng && center.lng() < boundLimits.maxLng){
- newLng = center.lng();
- }
- if(center.lat() > boundLimits.minLat && center.lat() < boundLimits.maxLat){
- newLat = center.lat();
- }
- map.panTo(new google.maps.LatLng(newLat, newLng));
- });
- var srcImage = 'assets/pics/floorImage.jpg';
- overlay = new USGSOverlay(bounds, srcImage, map);
- }
- function USGSOverlay(bounds, image, map) {
- this.bounds_ = bounds;
- this.image_ = image;
- this.map_ = map;
- this.div_ = null;
- this.setMap(map);
- }
- USGSOverlay.prototype.onAdd = function() {
- var div = document.createElement('div');
- div.style.borderStyle = '0';
- div.style.borderWidth = '100%';
- div.style.position = 'b';
- var img = document.createElement('img');
- img.src = this.image_;
- img.style.width = '800px';
- img.style.height = '500px';
- img.style.position = 'absolute';
- div.appendChild(img);
- this.div_ = div;
- var panes = this.getPanes();
- panes.overlayLayer.appendChild(div);
- };
- USGSOverlay.prototype.draw = function() {
- var overlayProjection = this.getProjection();
- var sw = overlayProjection.fromLatLngToDivPixel(this.bounds_.getSouthWest());
- var ne = overlayProjection.fromLatLngToDivPixel(this.bounds_.getNorthEast());
- var div = this.div_;
- div.style.left = sw.x + '10';
- div.style.top = ne.y + '10';
- div.style.width = (ne.x - sw.x) + '';
- div.style.height = (sw.y - ne.y) + '50';
- };
- USGSOverlay.prototype.onRemove = function() {
- this.div_.parentNode.removeChild(this.div_);
- this.div_ = null;
- };
- google.maps.event.addDomListener(window, 'load', initialize);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement