HelloWorld.vue

118 阅读1分钟

HelloWorld.vue

<script setup>
import { ref, onMounted } from 'vue'
import Transform from "ol-ext/interaction/Transform"
import VectorSource from 'ol/source/Vector';
import VectorLayer from 'ol/layer/Vector';
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import XYZ from 'ol/source/XYZ';
import { Feature } from 'ol';
import { Polygon } from 'ol/geom';


onMounted(() => {
  const map = new Map({
    target: 'map',
    layers: [
      new TileLayer({
        source: new XYZ({
          url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'
        })
      })
    ],
    view: new View({
      center: [34243, 6305749],
      zoom: 5.5
    })
  });
  var vector = new VectorLayer({
    name: 'Vecteur',
    source: new VectorSource({ wrapX: false }),
  })
  map.addLayer(vector);
  vector.getSource().addFeature(new Feature(new Polygon([[[34243, 6305749], [210354, 6305749], [210354, 5576845], [34243, 5576845], [34243, 6305749]]])));
  var interaction = new Transform({
    keepRectangle: true,
  });
  map.addInteraction(interaction);
  let rotate = 0;
  let sum = 0;
  // ['scale', 'scale1', 'scale2', 'scale3', 'scalev', 'scaleh1', 'scalev2', 'scaleh3'].map((v, i) => {
  //   interaction.Cursors[v] = `url(\'data:image/svg+xml, <svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg"	xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"	viewBox="0 0 120 120" style="enable-background:new 0 0 60 60;" xml:space="preserve"><g  transform="rotate(${i % 4 * 90 + (i > 3 ? 45 : 0) - sum}, 60,60) translate(30,30)">	<path d="M59.923,0.618c-0.101-0.245-0.296-0.44-0.541-0.541C59.26,0.027,59.13,0,59,0H39c-0.553,0-1,0.448-1,1s0.447,1,1,1h17.586		L34.293,24.293c-0.391,0.391-0.391,1.023,0,1.414C34.488,25.902,34.744,26,35,26s0.512-0.098,0.707-0.293L58,3.414V21		c0,0.552,0.447,1,1,1s1-0.448,1-1V1C60,0.87,59.974,0.74,59.923,0.618z"/>	<path d="M24.293,34.293L2,56.586V39c0-0.552-0.447-1-1-1s-1,0.448-1,1v20c0,0.13,0.027,0.26,0.077,0.382		c0.101,0.245,0.296,0.44,0.541,0.541C0.74,59.973,0.87,60,1,60h20c0.553,0,1-0.448,1-1s-0.447-1-1-1H3.414l22.293-22.293		c0.391-0.391,0.391-1.023,0-1.414S24.684,33.902,24.293,34.293z"/></g></svg> \') 15 15, auto`
  // })
  ['scale', 'scale1', 'scale2', 'scale3', 'scalev', 'scaleh1', 'scalev2', 'scaleh3'].map((v, i) => {
    interaction.Cursors[v] = `url(\'data:image/svg+xml, <svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"	 viewBox="0 0 182.931 182.931" style="enable-background:new 0 0 182.931 182.931;" xml:space="preserve">  <g transform="scale(0.5) translate(91.4655,91.4655) rotate(${i % 4 * 90 + (i > 3 ? 45 : 0) - sum - 90},91.4655,91.4655)"><path d="M173.93,92.798c-4.971,0-9,4.029-9,9v50.404L30.728,18h50.404c4.971,0,9-4.029,9-9s-4.029-9-9-9H9C4.03,0,0,4.029,0,9	v72.132c0,4.971,4.029,9,9,9s9-4.029,9-9V30.729l134.202,134.202h-50.404c-4.971,0-9,4.029-9,9s4.029,9,9,9h72.132	c4.971,0,9-4.029,9-9v-72.132C182.93,96.828,178.901,92.798,173.93,92.798z"/></g></svg> \') 15 15, auto`
  })
  let rotateArr = [];
  interaction.on("rotating", (e) => {
    rotate = (e.angle * 180 / Math.PI - 180) % 360 + 180;
    // console.log("aaa", e,(e.angle * 180 / Math.PI - 180) % 360 + 180,interaction.Cursors)
  })
  interaction.on("rotateend", () => {
    rotateArr.push(rotate);
    console.log(rotateArr, "arr")
    let sum = 0;
    rotateArr.map(v => sum = sum + v);
    // ['scale', 'scale1', 'scale2', 'scale3', 'scalev', 'scaleh1', 'scalev2', 'scaleh3'].map((v, i) => {
    //   interaction.Cursors[v] = `url(\'data:image/svg+xml, <svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg"	xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"	viewBox="0 0 120 120" style="enable-background:new 0 0 60 60;" xml:space="preserve"><g  transform="rotate(${i % 4 * 90 + (i > 3 ? 45 : 0) - sum}, 60,60) translate(30,30)">	<path d="M59.923,0.618c-0.101-0.245-0.296-0.44-0.541-0.541C59.26,0.027,59.13,0,59,0H39c-0.553,0-1,0.448-1,1s0.447,1,1,1h17.586		L34.293,24.293c-0.391,0.391-0.391,1.023,0,1.414C34.488,25.902,34.744,26,35,26s0.512-0.098,0.707-0.293L58,3.414V21		c0,0.552,0.447,1,1,1s1-0.448,1-1V1C60,0.87,59.974,0.74,59.923,0.618z"/>	<path d="M24.293,34.293L2,56.586V39c0-0.552-0.447-1-1-1s-1,0.448-1,1v20c0,0.13,0.027,0.26,0.077,0.382		c0.101,0.245,0.296,0.44,0.541,0.541C0.74,59.973,0.87,60,1,60h20c0.553,0,1-0.448,1-1s-0.447-1-1-1H3.414l22.293-22.293		c0.391-0.391,0.391-1.023,0-1.414S24.684,33.902,24.293,34.293z"/></g></svg> \') 15 15, auto`
    // })
    ['scale', 'scale1', 'scale2', 'scale3', 'scalev', 'scaleh1', 'scalev2', 'scaleh3'].map((v, i) => {
      interaction.Cursors[v] = `url(\'data:image/svg+xml, <svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"	 viewBox="0 0 182.931 182.931" style="enable-background:new 0 0 182.931 182.931;" xml:space="preserve">  <g transform="scale(0.5) translate(91.4655,91.4655) rotate(${i % 4 * 90 + (i > 3 ? 45 : 0) - sum - 90},91.4655,91.4655)"><path d="M173.93,92.798c-4.971,0-9,4.029-9,9v50.404L30.728,18h50.404c4.971,0,9-4.029,9-9s-4.029-9-9-9H9C4.03,0,0,4.029,0,9	v72.132c0,4.971,4.029,9,9,9s9-4.029,9-9V30.729l134.202,134.202h-50.404c-4.971,0-9,4.029-9,9s4.029,9,9,9h72.132	c4.971,0,9-4.029,9-9v-72.132C182.93,96.828,178.901,92.798,173.93,92.798z"/></g></svg> \') 15 15, auto`
    })
    console.log(interaction.Cursors, "aaa");
  })
})
defineProps({
  msg: String,
})

const count = ref(0)
</script>

<template>
  <div id="map" style="width: 600px;height: 600px;"></div>
  <h1>{{ msg }}</h1>

  <div class="card">
    <button type="button" @click="count++">count is {{ count }}</button>
    <p>
      Edit
      <code>components/HelloWorld.vue</code> to test HMR
    </p>
  </div>

  <p>
    Check out
    <a href="https://vuejs.org/guide/quick-start.html#local" target="_blank">create-vue</a>, the official Vue + Vite
    starter
  </p>
  <p>
    Install
    <a href="https://github.com/vuejs/language-tools" target="_blank">Volar</a>
    in your IDE for a better DX
  </p>
  <p class="read-the-docs">Click on the Vite and Vue logos to learn more</p>
</template>

<style scoped>
.read-the-docs {
  color: #888;
}
</style>