Viglino / ol-ext

Cool extensions for Openlayers (ol) - animated clusters, CSS popup, Font Awesome symbol renderer, charts for statistical map (pie/bar), layer switcher, wikipedia layer, animations, canvas filters.
https://viglino.github.io/ol-ext/
Other
1.24k stars 462 forks source link

Placemark with stopEvent:false and perspective map #546

Closed berkayoruc closed 3 years ago

berkayoruc commented 3 years ago

When placemark(stop Event:false) is used with perspective map, placemark is rendered at top-left of canvas not true location.

asd

Code:

<DOCTYPE html>
<html>
<head>
<!--
  Copyright (c) 2015-2019 Jean-Marc VIGLINO, 
  released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
-->
  <title>Perspective ol Map</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <meta name="description" content="Perspective ol map" />
  <meta name="keywords" content="openlayers, layer, 3D, perspective, animation" />

  <!-- jQuery -->
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>

  <!-- Openlayers -->
  <link rel="stylesheet" href="https://openlayers.org/en/latest/css/ol.css" />
  <script type="text/javascript" src="https://openlayers.org/en/latest/build/ol.js"></script>
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL,Object.assign"></script>

  <!-- ol-ext -->
  <link rel="stylesheet" href="../../dist/ol-ext.css" />
  <script type="text/javascript" src="../../dist/ol-ext.js"></script>

  <link rel="stylesheet" href="../style.css" />
  <style>
    #map {
      width: 800px;
      height: 600px;
      z-index: 0;
    }
    .placemark .content * {
      color: inherit!important;
    }
    .ol-overlay-container {
      width: 20px;
      height: 20px;
      border: 1px solid #08F;
      border-radius: 10px;
      background-color: rgba(0,128,255,.5);
      cursor: move;
      position: relative;
      font-family: Arial, Helvetica, sans-serif;
      text-align: center;
    }
    .ol-popup {
      text-align: center;
      cursor: move;
    }
  </style>
</head>
<body >
  <a href="https://github.com/Viglino/ol-ext" class="icss-github-corner"><i></i></a>
  <a href="../../index.html">
    <h1>Perspective ol map</h1>
  </a>
  <div class="info">
    <p>
      <i>ol/PerspectiveMap</i> displays a map with a perspective effect by pitching the map.
    </p>
    <p>
      <span class="experimental">Experimental</span> tested on Chrome and Edge. Not working on Firefox.
    </p>
  </div>

  <!-- DIV pour la carte -->
  <div id="map"></div>

  <div class="options">
    <ul>
      <li>
        <label>Perspective:</label>
        <input id="angle" type="range" step=1 min=0 max=30 onchange="map.setPerspective(this.value)" value=0 style="vertical-align: middle;" />
      </li>
      <li><i>use alt + drag to tilt the map...</i></li>
    </ul>
  </div>

  <script type="text/javascript">
  var layer = new ol.layer.Tile({ name:"OSM", source: new ol.source.OSM() });

  // The map
  var map = new ol.PerspectiveMap({
    target: 'map',
    view: new ol.View ({
      zoom: 19,
      center: [-245406, 5986536]// [-245575, 5986863], //[-244777, 5989809]
    }),
    interactions: ol.interaction.defaults(),
    layers: [ layer ]
  });

  map.on('change:perspective', function(e) {
    if (!e.animating) $('#angle').val(e.angle);
  })

  // An overlay
  var place = new ol.Overlay.Placemark ({
    contentColor: '#000',
    stopEvent: false
  });
  map.addOverlay(place);
  place.show([-245406, 5986536]);
  // map.on('click', function(e) {
  //   place.show(e.coordinate);
  // });

  // Drag interaction
  var drag = new ol.interaction.DragOverlay({
    overlays: [place]
  });
  map.addInteraction(drag);
  drag.on('dragend', function(e){
    if (e.overlay===place) {
      // Animate placemark
      place.show(true);
    }
  });

  </script>

</body>
</html>
Viglino commented 3 years ago

Some class was a missing in the css... NB: perspective map is experimental and using overlay may be a little tricky on such a map...

berkayoruc commented 3 years ago

So, what is your advice?

Viglino commented 3 years ago

Test and try... its not working on all browsers and I don't know if the Overlay will move correctly on all devices...

liqinglong123 commented 1 year ago

如何在点击时获取真实的位置