efd009e89cfd429b85740bc8c7acf4b94b61ab17.svn-base 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <div id="SimpleMarker" ref="SimpleMarker" class="SimpleMarker">
  3. <div id="locateMarker" ref="locateMarker" class="locateMarker" v-show="iconShow"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import 'ol/ol.css';
  8. import Overlay from "ol/Overlay";
  9. export default {
  10. name: "SimpleMarker",
  11. props: {
  12. },
  13. data: function() {
  14. return {
  15. iconShow: false,
  16. locate: {},
  17. map:{},
  18. }
  19. },
  20. inject: ['baseMap'],
  21. methods: {
  22. init(coords) {
  23. this.map = this.baseMap.map;
  24. if (!this.map) {
  25. return
  26. }
  27. if (!this.map.getOverlayById('locate')) {
  28. this.locate = new Overlay({
  29. id: 'locate',
  30. stopEvent: false,
  31. });
  32. this.map.addOverlay(this.locate);
  33. }
  34. this.locate.setElement(this.$refs.locateMarker);
  35. this.setMarkerPosition(coords);
  36. this.showMarker();
  37. },
  38. setMarkerPosition(coords) {
  39. this.locate.setPosition(coords);
  40. },
  41. showMarker() {
  42. this.iconShow = true;
  43. },
  44. hideMarker() {
  45. this.iconShow = false;
  46. }
  47. }
  48. }
  49. </script>
  50. <style scoped>
  51. .locateMarker {
  52. width: 48px;
  53. height: 48px;
  54. background-image: url("../../../assets/locate-red.png");
  55. background-size: 48px;
  56. z-index: 100;
  57. position: relative;
  58. left: -24px;
  59. top: -45px;
  60. pointer-events: none;
  61. }
  62. </style>