Моя карта не будет двигаться с открытыми слоями 6.2 и angular 9, даже с взаимодействием DragRotateAndZoom - PullRequest
1 голос
/ 21 февраля 2020

Я пытаюсь создать карту, и, как я вижу на других сайтах и ​​примерах, каждый может перемещать свою карту с помощью щелчка мышью и перетаскивания. Но моя карта вообще не двигается, кто-нибудь знает, что я сделал не так?

Это компоненты.ts и файлы компонентов. html, которые я использую. Я следовал инструкциям на https://openlayers.org/en/latest/doc/tutorials/bundle.html, не устанавливая посылку, потому что я использую angular.

map.component.ts

ngOnInit(): void {
  this.mapInit();
  }

   mapInit() {
   var mousePositionControl = new MousePosition({
         coordinateFormat: createStringXY(4),
         projection: 'EPSG:4326',
         // comment the following two lines to have the mouse position
         // be placed within the map.
         className: 'custom-mouse-position',
         target: document.getElementById('mouse-position'),
         undefinedHTML: ' '
       });

          var source = new OSM();
          var overviewMapControl = new OverviewMap({
            layers: [
              new TileLayer({
                source: source
              })
            ]
          });

          this.map = new Map({
          target: 'map',
          interactions: defaultInteractions().extend([
              new DragRotateAndZoom
            ]),
            layers: [
              new TileLayer({
                source: source
              }),
            ],
            view: new View({
              center: fromLonLat([19.833549, 45.267136]),
              zoom: 7
            }),
            controls: defaultControls().extend([
            overviewMapControl,
            new FullScreen(),
            mousePositionControl,
            new ZoomToExtent({
            extent: [
               813079.7791264898, 5929220.284081122,
               848966.9639063801, 5936863.986909639,
             ]
             })
            ])
          });

map.component. html

<html lang="en">
<head>
  <title>Drag, Rotate, and Zoom</title>
  <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=fetch,requestAnimationFrame,Element.prototype.classList,URL"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.1.1/build/ol.js"></script>

</head>
<body>
<div id="map" class="map"></div>
<div id="mouse-position"></div>
</body>
</html>

1 Ответ

3 голосов
/ 22 февраля 2020

Это то же самое, что и эта проблема: https://github.com/openlayers/openlayers/issues/10663

Последняя версия ol. css не включена в HTML.

Добавить:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.2.1/css/ol.css"> 
...