Adding a Google map layer to Openlayer. What is the requirement?

I have been using google map layer with my application since a year, and suddenly it stops working. Is a Key required to use the google map API? My code is as follows.

map = new OpenLayers.Map('mapDiv');
map.addControl(new OpenLayers.Control.LayerSwitcher());

var gphy = new OpenLayers.Layer.Google(
    "Google Physical",
    {type: google.maps.MapTypeId.TERRAIN}
);
var gmap = new OpenLayers.Layer.Google(
    "Google Streets", // the default
    {numZoomLevels: 20}
);
var ghyb = new OpenLayers.Layer.Google(
    "Google Hybrid",
    {type: google.maps.MapTypeId.HYBRID, numZoomLevels: 20}
);
var gsat = new OpenLayers.Layer.Google(
    "Google Satellite",
    {type: google.maps.MapTypeId.SATELLITE, numZoomLevels: 22}
);

map.addLayers([gphy, gmap, ghyb, gsat]);

// Google.v3 uses EPSG:900913 as projection, so we have to
// transform our coordinates
map.setCenter(new OpenLayers.LonLat(10.2, 48.9).transform(
    new OpenLayers.Projection("EPSG:4326"),
    map.getProjectionObject()
), 5);

I have nested the whole script library. If one day I select Google Satellite, and then try to use Google Streets or another option than Maps to download the application.

+4
source share
1 answer

Google API , . v3.21, OpenLayers 2.13.1 . , 3.21 Google, Google.

I , , openlayers: https://github.com/UMS/openlayers/tree/release-2.13.1_ums

2.13.1 dist.

, bower:

{
    "dependencies": {
        "openlayers": "git://github.com/ums/openlayers.git#release-2.13.1_ums"
    },
    "overrides": {
        "openlayers": {
            "main": [
                "dist/OpenLayers.js",
                "theme/default/style.css",
                "theme/default/img/"
            ]
        }
    }
}

: https://github.com/openlayers/openlayers/issues/1450 - , cherry: https://github.com/v5analytics/openlayers/commit/5c6a7f4540b7d70261e9483d3a3770cfbfc72001

Javascript API Google Maps: 8092: : OpenLayers

+4

Source: https://habr.com/ru/post/1616322/


All Articles