[OpenLayers-Dev] Panning is disabled when viewing Googe Layers

Christopher Schmidt crschmidt at metacarta.com
Tue Nov 18 15:18:45 EST 2008


On Tue, Nov 18, 2008 at 12:01:39PM -0800, Malte wrote:
> 
> Hi everybody,
> I've got a problem when switching from OSM Mapnik to a Google Layer. If
> Mapnik is activated panning and zooming works like a charm. But when I
> switch to Google Layer only zooming works. Can somebody give me a hint, how
> to solve this problem? Is the VectorLayer the cause?

Your maxExtent is wrong. 
1. You can't use maxExtent with a Google Layer.
2. Your extent should be in Map Units, which means you shoul call
.transform() on it.
3. restrictedExtent probably does what you want, since you shouldn't be
using maxExtent.

> function init() {
> 	map = new OpenLayers.Map ("map", {
> 	controls:[
> 		new OpenLayers.Control.Navigation(),
> 		new OpenLayers.Control.PanZoomBar(),
> 		new OpenLayers.Control.Attribution(),
> 		new OpenLayers.Control.LayerSwitcher()],
> 		maxExtent: new OpenLayers.Bounds(8.112,49.9312, 8.3262, 50.0942),
> 		maxResolution: 156543.0399,
> 		numZoomLevels: 19,
> 		units: 'm',
> 		projection: new OpenLayers.Projection("EPSG:900913"),
> 		displayProjection: new OpenLayers.Projection("EPSG:4326")
> 	} );
> 			  
> 	vectorLayer = new OpenLayers.Layer.Vector(
> 		"POIs",
> 		{
> 			styleMap: new OpenLayers.StyleMap({
> 				// Set the external graphic and background graphic images.
> 				externalGraphic: "http://openlayers.org/dev/img/marker-gold.png",
> 				backgroundGraphic:
> "http://openlayers.org/dev/examples/marker_shadow.png",
> 				
> 				// Makes sure the background graphic is placed correctly relative
> 				// to the external graphic.
> 				backgroundXOffset: 0,
> 				backgroundYOffset: -7,
> 				
> 				// Set the z-indexes of both graphics to make sure the background
> 				// graphics stay in the background (shadows on top of markers looks
> 				// odd; let's not do that).
> 				graphicZIndex: MARKER_Z_INDEX,
> 				backgroundGraphicZIndex: SHADOW_Z_INDEX,
> 				
> 				pointRadius: 10
> 			}),
> 			isBaseLayer: false,
> 			rendererOptions: {yOrdering: true}
> 		}
> 	)
> 	var layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
> 	var layerTilesAtHome = new OpenLayers.Layer.OSM.Osmarender("Osmarender");
> 	var layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
> 	var cycleattrib = 'OpenCycleMap.org - the  http://www.openstreetmap.org
> OpenStreetMap  Cycle Map<br />'
> 		   + ' http://www.gravitystorm.co.uk/shine/cycle-info/ Key and More Info 
> | Help | Stuff<br />'
> 		   + 'Created by  http://www.gravitystorm.co.uk Andy Allan  and Dave
> Stubbs<br />'
> 		   + 'Sponsored by  http://www.cloudmade.com CloudMade  <br />';			 
> 	var gphy = new OpenLayers.Layer.Google("Google Physical",{type:
> G_PHYSICAL_MAP, sphericalMercator: true });
> 	var gmap = new OpenLayers.Layer.Google("Google Streets",{
> sphericalMercator: true });
> 	var ghyb = new OpenLayers.Layer.Google("Google Hybrid",{type: G_HYBRID_MAP,
> sphericalMercator: true });
> 	var gsat = new OpenLayers.Layer.Google("Google Satellite",{type:
> G_SATELLITE_MAP, sphericalMercator: true });
> 	map.addLayers([layerMapnik, layerTilesAtHome, gphy, gmap, ghyb, gsat,
> vectorLayer]);
> 	
> 	var sf = new OpenLayers.Control.SelectFeature(vectorLayer, {'onSelect':
> popup});
>     map.addControl(sf);
>     sf.activate();
> 				
> 	map.zoomToMaxExtent();
> 	
> 	var lonLat = new OpenLayers.LonLat(lon, lat).transform(new
> OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
> 	map.setCenter (lonLat, zoom);
> } 
> 
> Greetings,
> Malte
> -- 
> View this message in context: http://www.nabble.com/Panning-is-disabled-when-viewing-Googe-Layers-tp20564773p20564773.html
> Sent from the OpenLayers Dev mailing list archive at Nabble.com.
> 
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev

-- 
Christopher Schmidt
MetaCarta



More information about the Dev mailing list