Карта Google: как повернуть `Groundoverlay` нужна хитрость

Я создаю проект карты для использования, например, добавления фигур и местоположения на карту и сохранения его.

но у меня проблема с наложением на грунт.

Я знаю, что в документе карты Google нет свойства для вращения. но мне нужен способ / трюк, чтобы повернуть изображение наложения любым другим способом.

здесь код

var srcImage = "http://demo/image/uploads/demo.jpg";
var bounds = {
    north: 44.599,
    south: 44.490,
    east: -78.443,
    west: -78.649
}
var overlay = new google.maps.GroundOverlay(srcImage ,bounds);
overlay.setMap(map);

Я использую ползунок для поворота наложения.

$("#overlayslider").slider().on('slide',function(e){
     var angle = e.newVal;
     // i want rotate overlay by angle/degree as per slider
})

Я пробовал с проекцией, но безуспешно.

Любой возможный способ будет оценен.

Любая помощь будет полезна, спасибо.

Пожалуйста, добавьте комментарии по причине голосования против. и как это исправить.

Subhash Chavda 23.10.2018 14:32

Попробуйте overlay.setBearing(120);, где 120 - угол поворота (от 0 до 360), это должно повернуть наложение. Пример: github.com/ionic-team/ionic-native-google-maps/tree/master/…

elveti 23.10.2018 14:57

Эта функция не существует: Uncaught (in promise) TypeError: historicalOverlay.setBearing is not a function.

Daniël Visser 23.10.2018 15:40
overlay.setBearing(120) не работает с функцией карты Google по умолчанию, для этого мне нужно создать пользовательское программирование.
Subhash Chavda 23.10.2018 16:00
Как конвертировать HTML в PDF с помощью jsPDF
Как конвертировать HTML в PDF с помощью jsPDF
В этой статье мы рассмотрим, как конвертировать HTML в PDF с помощью jsPDF. Здесь мы узнаем, как конвертировать HTML в PDF с помощью javascript.
0
4
1 607
2
Перейти к ответу Данный вопрос помечен как решенный

Ответы 2

Ответ принят как подходящий

Вы можете добиться этого, используя настраиваемый оверлей: https://developers.google.com/maps/documentation/javascript/examples/overlay-simple.

Добавьте прослушиватель событий к ползунку наложения в USGSOverlay.prototype.onAdd, а затем установите поворот div при вводе.

document.getElementById('overlayslider').addEventListener('input', function() {
    div.style.transform = 'rotate(' + this.value + 'deg)';
});

А вот пример модифицированного настраиваемого наложения: https://jsfiddle.net/b0tLd46u/4/. Вы можете установить поворот наложения с помощью ползунка диапазона над картой.

Вот мое решение, в основном вдохновленное Этот ответ

rotated-overlay.ts

export class CustomOverlay extends google.maps.OverlayView {
  private div;

  constructor(
    private bounds: google.maps.LatLngBounds,
    private image: string,
    private rotation: number
  ) {
    super();

    // Define a property to hold the image's div. We'll
    // actually create this div upon receipt of the onAdd()
    // method so we'll leave it null for now.
    this.div = null;
  }

  /**
   * onAdd is called when the map's panes are ready and the overlay has been
   * added to the map.
   */
  onAdd() {
    const div = document.createElement('div');
    div.style.borderStyle = 'none';
    div.style.borderWidth = '0px';
    div.style.position = 'absolute';

    // Create the img element and attach it to the div.
    const img = document.createElement('img');
    img.src = this.image;
    img.style.width = '100%';
    img.style.height = '100%';
    img.style.position = 'absolute';
    div.appendChild(img);

    this.div = div;

    // Add the element to the "overlayLayer" pane.
    const panes = this.getPanes();
    panes.overlayLayer.appendChild(div);
  };

  draw() {

    // We use the south-west and north-east
    // coordinates of the overlay to peg it to the correct position and size.
    // To do this, we need to retrieve the projection from the overlay.
    const overlayProjection = this.getProjection();

    // Retrieve the south-west and north-east coordinates of this overlay
    // in LatLngs and convert them to pixel coordinates.
    // We'll use these coordinates to resize the div.
    const sw = overlayProjection.fromLatLngToDivPixel(this.bounds.getSouthWest());
    const ne = overlayProjection.fromLatLngToDivPixel(this.bounds.getNorthEast());

    // Resize the image's div to fit the indicated dimensions.
    const div = this.div;
    div.style.left = sw.x + 'px';
    div.style.top = ne.y + 'px';
    div.style.width = (ne.x - sw.x) + 'px';
    div.style.height = (sw.y - ne.y) + 'px';
    div.style.transform = 'rotate(' + this.rotation + 'deg)';
  };

  // The onRemove() method will be called automatically from the API if
  // we ever set the overlay's map property to 'null'.
  onRemove() {
    this.div.parentNode.removeChild(this.div);
    this.div = null;
  };
};

map-component.ts

public addOverlay(imageUrl: string, rotation: number, bounds: google.maps.LatLngBounds, map: google.maps.Map){
  let overlay = new CustomOverlay(
    bounds,
    imageUrl,
    rotation,
    
  );
  overlay.setMap(map);
}

Другие вопросы по теме