Tuesday 10 September 2019

Using OpenLayers 3 or 2 to add layers from Google Maps and Mapserver?


I am beginner in OpenLayers and am starting with the www.openlayers.org documents, which use OpenLayers 3 to teach the basics of OpenLayers. Now, I would like to add layers from Google Maps and Mapserver, but I can't find that in the documents.



I have found many site related to my questions, but all of them use different syntax that I guess are related to OpenLayers 2.



  • for a beginner would you recommend ol3 or ol2 ?

  • if you recommend ol3, where I can find what's new in ol3 syntax?



Answer



If you have to work with a Google base map, OpenLayers 2 will satisfy your needs. As stated in an OpenLayers 3 issue by @ahocevar,



There will be no ol.source.GoogleMaps, unless Google change their policy and allow direct access to their map tiles.




Your only chance to use Google wiht OpenLayers 3 is to make a base map without any controls with Google Maps API, then put an ol.Map instance on the top of it. You have to synchronize the zoom levels and the viewport of the two DOM elements. You can find an example here.


@John Barça's detailed answer on the differences of the two OpenLayers libraries tells everything you have to know about them in the beginning. IMO, you should go with OpenLayers 3, because it will overgrow OL2 very soon. Try to consult with OL3's API, if you're stuck.


If you run into a problem, which you can't resolve with the API or the mailing lists, don't hesitate to share it on GIS StackExchange, the community will try to help you out.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...