我已经阅读了一些有关此事的帖子以及示例链接
但是我发现很难理解他们在示例中是如何做到的:
var gmap = new google.maps.Map(document.getElementById('gmap'), { disableDefaultUI: true, keyboardShortcuts: false, draggable: false, disableDoubleClickZoom: true, scrollwheel: false, streetViewControl: false }); var view = new ol.View({ // make sure the view doesn't go beyond the 22 zoom levels of Google Maps maxZoom: 21 }); view.on('change:center', function() { var center = ol.proj.transform(view.getCenter(), 'EPSG:3857', 'EPSG:4326'); gmap.setCenter(new google.maps.LatLng(center[1], center[0])); }); view.on('change:resolution', function() { gmap.setZoom(view.getZoom()); }); var vector = new ol.layer.Vector({ source: new ol.source.GeoJSON({ url: 'data/geojson/countries.geojson', projection: 'EPSG:3857' }), style: new ol.style.Style({ fill: new ol.style.Fill({ color: 'rgba(255, 255, 255, 0.6)' }), stroke: new ol.style.Stroke({ color: '#319FD3', width: 1 }) }) }); var olMapDiv = document.getElementById('olmap'); var map = new ol.Map({ layers: [vector], interactions: ol.interaction.defaults({ altShiftDragRotate: false, dragPan: false, rotate: false }).extend([new ol.interaction.DragPan({kinetic: null})]), target: olMapDiv, view: view }); view.setCenter([0, 0]); view.setZoom(1); olMapDiv.parentNode.removeChild(olMapDiv); gmap.controls[google.maps.ControlPosition.TOP_LEFT].push(olMapDiv);
我必须创建多少个DOM元素?它是否正确?
我通过像这样的结构得到一个错误.这是我得到的错误:
Cannot read property 'parentNode' of null
有关如何在OL3中实施Google地图的任何线索?
该尝试已弃用,请查看以下内容:https://github.com/mapgears/ol3-google-maps