создал компонент ymap.vue

This commit is contained in:
Norbaev 2024-07-05 18:03:24 +05:00
parent e07d34d61e
commit c3ab0cf6b8
2 changed files with 69 additions and 14 deletions

View File

@ -0,0 +1,62 @@
<template>
<div ref="map" :style="{ width: mapWidth, height: mapHeight }"></div>
</template>
<script>
export default {
name: 'YandexMap',
props: {
apiKey: {
type: String,
default: '',
},
mapWidth: {
type: String,
default: '100%',
},
mapHeight: {
type: String,
default: '100%',
},
center: {
type: Array,
default: () => [61.402554, 55.159902],
},
zoom: {
type: Number,
default: 10,
},
},
mounted() {
this.loadYandexMap();
},
methods: {
loadYandexMap() {
if (document.querySelector('script[src*="api-maps.yandex.ru"]')) {
this.initMap();
} else {
const script = document.createElement('script');
script.src = `https://api-maps.yandex.ru/v3/?apikey=${this.apiKey}&lang=ru_RU`;
script.onload = this.initMap;
document.head.appendChild(script);
}
},
async initMap() {
// eslint-disable-next-line no-undef
await ymaps3.ready;
// eslint-disable-next-line no-undef
const { YMap, YMapDefaultSchemeLayer, YMapDefaultMarker } = ymaps3;
const map = new YMap(this.$refs.map, {
location: {
center: this.center,
zoom: this.zoom,
},
});
map.addChild(new YMapDefaultSchemeLayer());
},
},
};
</script>

View File

@ -29,8 +29,8 @@
</div> </div>
</div> </div>
</div> </div>
<!-- <div class="contacts__map"> <div class="contacts__map">
<div <!-- <div
class="contacts__map-frame" class="contacts__map-frame"
style="position: relative; overflow: hidden" style="position: relative; overflow: hidden"
> >
@ -38,10 +38,6 @@
href="https://yandex.ru/maps/56/chelyabinsk/?utm_medium=mapframe&utm_source=maps" href="https://yandex.ru/maps/56/chelyabinsk/?utm_medium=mapframe&utm_source=maps"
style="color: #eee; font-size: 12px; position: absolute; top: 0px" style="color: #eee; font-size: 12px; position: absolute; top: 0px"
>Челябинск</a >Челябинск</a
><a
href="https://yandex.ru/maps/geo/chelyabinsk/53159527/?ll=61.421984%2C55.159071&utm_medium=mapframe&utm_source=maps&z=14.04"
style="color: #eee; font-size: 12px; position: absolute; top: 14px"
>Челябинск Яндекс Карты</a
><iframe ><iframe
src="https://yandex.ru/map-widget/v1/?ll=61.421984%2C55.159071&mode=poi&poi%5Bpoint%5D=61.399655%2C55.160475&poi%5Buri%5D=ymapsbm1%3A%2F%2Fgeo%3Fdata%3DCgg1MzE1OTUyNxIg0KDQvtGB0YHQuNGPLCDQp9C10LvRj9Cx0LjQvdGB0LoiCg04nHVCFb2jXEI%2C&z=14.04" src="https://yandex.ru/map-widget/v1/?ll=61.421984%2C55.159071&mode=poi&poi%5Bpoint%5D=61.399655%2C55.160475&poi%5Buri%5D=ymapsbm1%3A%2F%2Fgeo%3Fdata%3DCgg1MzE1OTUyNxIg0KDQvtGB0YHQuNGPLCDQp9C10LvRj9Cx0LjQvdGB0LoiCg04nHVCFb2jXEI%2C&z=14.04"
width="100%" width="100%"
@ -50,8 +46,9 @@
allowfullscreen="true" allowfullscreen="true"
style="position: relative" style="position: relative"
></iframe> ></iframe>
</div>
</div> --> </div> -->
<YandexMap apiKey="e73ed16e-35ea-483b-afb4-9daac388591a" />
</div>
<FormKit <FormKit
v-model="formData" v-model="formData"
type="form" type="form"
@ -79,11 +76,12 @@
<script> <script>
import AppBreadcrumbs from '@/components/app-breadcrumbs.vue'; import AppBreadcrumbs from '@/components/app-breadcrumbs.vue';
import SupportBlock from '@/components/support-block.vue'; import SupportBlock from '@/components/support-block.vue';
import YandexMap from '@/components/ymap.vue';
import { app } from '@/services'; import { app } from '@/services';
export default { export default {
name: 'contacts', name: 'contacts',
components: { SupportBlock, AppBreadcrumbs }, components: { SupportBlock, AppBreadcrumbs, YandexMap },
data() { data() {
return { return {
formData: {}, formData: {},
@ -162,7 +160,6 @@ export default {
submitHandler() {}, submitHandler() {},
removeNullFields(obj) { removeNullFields(obj) {
const result = {}; const result = {};
for (const key in obj) { for (const key in obj) {
if (obj[key] !== null) { if (obj[key] !== null) {
if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) { if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
@ -172,19 +169,15 @@ export default {
} }
} }
} }
return result; return result;
}, },
createArrayContacts(dictionary, fields) { createArrayContacts(dictionary, fields) {
const result = []; const result = [];
for (const key in fields) { for (const key in fields) {
if (dictionary[key]) { if (dictionary[key]) {
result.push({ title: dictionary[key], data: fields[key] }); result.push({ title: dictionary[key], data: fields[key] });
} }
} }
return result; return result;
}, },
formatAddress(contacts) { formatAddress(contacts) {