Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Im trying to add StreetView functionality to my OpenLayers web app, and would like to add the overlay showing StreetView availability to the map itself. I have seen an example of it being done successfully here, but i cannot get the code to work in my own solution. Specifically :

var layer = new OpenLayers.Layer.Google("Google Street", {sphericalMercator: true});

layer.mapObject.addOverlay(new GStreetviewOverlay());

results in the error:

layer.mapObject is null

Has anyone got any idea what i might be doing wrong, and if so, how can i fix this?

Thanks in advance!

C

share|improve this question

3 Answers 3

up vote 4 down vote accepted

Openlayers with Streetview

requires the GeoExt ux extension

all the code is available - so you can see what you are missing

(if you could post a live link to your current map - users could debug it for you.)

enter image description here

http://api.geo.admin.ch/main/wsgi/doc/build/api/streetview.html

share|improve this answer
2  
+1 - this demo works. It is by the same author too, but more recent. –  geographika Sep 6 '11 at 16:09
    
Would you know of any other way of using the StreetView Overlay Layer in OpenLayers without using GeoExt? –  CatchingMonkey Sep 7 '11 at 11:11
    
Only for Google Maps v2 (deprecated) fuzzytolerance.info/code/… API Key required. –  Mapperz Sep 7 '11 at 13:58

To use Google layers and meet licensing requirements you have to access Google layers through the Google API. When you add a Google layer to an OpenLayers map OpenLayers loads the Google API.

The layer.mapObject (as opposed to layer.map which is the OL map object) should give you a reference to the Google Map. As this is null something has gone wrong loading the Google API. You can check in FireBug if it has loaded correctly.

The example you point to may be using the older Google 2 API rather than version 3. You no longer need an API key and can add in the Google API using:

<script src="http://maps.google.com/maps/api/js?sensor=false"></script>

Have a look at the unit tests for the Google v3 API layers which may help you.

Remember the StreetView also needs Flash in the browser.

share|improve this answer
    
Hi there, thanks for your help. I'm not at my desk right now so I'm not going to be able to test your suggestions, but here's what I know: I'm definitely loading the Google Maps API v3. I have implemented StreetView in Web Apps before, but this time I'm looking to get the overlay on the map as well. Im wondering though if its a browser thing. The website I gave a link for works fine in IE (8) but not in Firefox... any ideas? –  CatchingMonkey Sep 5 '11 at 20:28
    
The demo doesn't work for me in FF6, IE8 or IE9. It seems to only show either a map or a street view.. –  geographika Sep 5 '11 at 20:44
    
Hmmm, the website seems to work in my IE8 here.... going to consult the OpenLayers user list as well now! –  CatchingMonkey Sep 6 '11 at 9:12

The reason why layer.mapObject is null is that the mapObject property is created after that the layer is added to the map. Try this:

var layer = new OpenLayers.Layer.Google("Google Street", {sphericalMercator: true});
map.addLayer(layer);
layer.mapObject.addOverlay(new GStreetviewOverlay());
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.