Skip to content

Commit

Permalink
Docs for dynamic balloon
Browse files Browse the repository at this point in the history
  • Loading branch information
PNKBizz committed Oct 16, 2021
1 parent 8a629c5 commit 3cbec0e
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/en/guide/Map.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ The attributes `coords`, `bounds` and `zoom` are observable. The map is react if
| show-all-markers | Boolean | Set to `true` to initialize map with all markers inside map bounds. Default: `false` |
| use-html-in-layout | Boolean | Set to `true` to define balloon properties as html. Default: `false` |
| [options](https://tech.yandex.ru/maps/doc/jsapi/2.1/ref/reference/Map-docpage/#Map__param-options) | Object | Map options. |

| balloon-component | Vue Component | Allow to use Vue Component as balloon. Need to activate runtimeCompiler(https://cli.vuejs.org/config/#runtimecompiler). **Vue 2 only**|
1 change: 1 addition & 0 deletions docs/en/guide/Marker.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Since version `0.10` attribute `callbacks` not supported. You can listen compone
| properties | Object | [Marker settings](https://tech.yandex.ru/maps/doc/jsapi/2.1/ref/reference/GeoObject-docpage/#param-feature.properties) | All |
| options | Object | [Marker options](https://tech.yandex.ru/maps/doc/jsapi/2.1/ref/reference/GeoObject-docpage/#param-options) | All |
| [balloonTemplate](/en/examples/#custom-cluster-balloon) | String | HTML Template for balloon | All |
| balloon-component-props | Object | Props object for balloon. _Use only for balloonComponent_ | All |

## Slots

Expand Down
1 change: 1 addition & 0 deletions docs/guide/Map.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,4 @@
| show-all-markers | Boolean | Установите значение в `true`, чтобы границы карты при инициализации вмещали все маркеры. Default: `false` |
| use-html-in-layout | Boolean | Установите значение в `true`, чтобы передавать в поля в балун в виде html-разметки. Default: `false` |
| [options](https://tech.yandex.ru/maps/doc/jsapi/2.1/ref/reference/Map-docpage/#Map__param-options) | Object | Опции карты |
| balloon-component | Vue Component | Позволяет использовать компонент Vue в качестве балуна. Для работы необходима активация runtimeCompiler(https://cli.vuejs.org/config/#runtimecompiler). **Только для Vue 2**|
3 changes: 2 additions & 1 deletion docs/guide/Marker.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
| cluster-name | String | Имя кластера для группировки маркеров | All |
| properties | Object | [Свойства маркера](https://tech.yandex.ru/maps/doc/jsapi/2.1/ref/reference/GeoObject-docpage/#param-feature.properties) | All |
| options | Object | [Опции маркера](https://tech.yandex.ru/maps/doc/jsapi/2.1/ref/reference/GeoObject-docpage/#param-options) | All |
| [balloonTemplate](/examples/#кастомный-темпnейт-баnуна) | String | HTML Template for balloon | All |
| [balloon-template](/examples/#кастомный-темпnейт-баnуна) | String | HTML Template for balloon | All |
| balloon-component-props | Object | Объект пропсов для балуна. _Только при инициализации балуна через balloonComponent_ | All |

## Slots

Expand Down
2 changes: 1 addition & 1 deletion examples/vue3/src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createApp } from 'vue'
import App from './App.vue'
import ymapPlugin from '../../../src';
import ymapPlugin from '../../../dist/vue-yandex-maps.esm.js';

const app = createApp(App)

Expand Down
3 changes: 3 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default [
file: pkg.module,
format: 'es',
exports: 'named',
globals: { vue: 'vue' },
},
plugins: [
babel({
Expand All @@ -26,6 +27,7 @@ export default [
file: pkg.main,
format: 'umd',
exports: 'named',
globals: { vue: 'vue' },
},
plugins: [
babel({
Expand All @@ -42,6 +44,7 @@ export default [
format: 'iife',
exports: 'named',
extend: true,
globals: { vue: 'vue' },
},
plugins: [
babel({
Expand Down
4 changes: 3 additions & 1 deletion src/Marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default {
balloonComponentProps: {
type: Object,
default: () => ({}),
},
markerEvents: {
type: Array,
default: () => [],
Expand All @@ -70,6 +71,7 @@ export default {
},
mounted() {
Object.keys(this.$props).forEach((prop) => {
if (prop === 'balloonComponentProps') return;
this.unwatchArr.push(this.$watch(
prop,
(newVal, oldVal) => this.compareValues({
Expand Down Expand Up @@ -108,7 +110,7 @@ export default {

if (this.$slots.balloon) {
balloonContentLayout = ymaps.templateLayoutFactory
.createClass(typeof this.$slots.balloon === 'function' ? this.$slots.balloon()[0].elm.outerHTML : this.$slots.balloon[0].elm.outerHTML);
.createClass(typeof this.$slots.balloon === 'function' ? this.$slots.balloon()[0].elm.outerHTML : this.$slots.balloon[0].elm.outerHTML);
}

if (this.makeComponentBalloonTemplate) {
Expand Down
12 changes: 9 additions & 3 deletions src/YMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ export default {
this.$emit('markers-was-change', ids);
} else utils.addToMap(markers, config);
this.$options.static.markers = [];
if (this.showAllMarkers) this.$options.static.myMap.setBounds(this.$options.static.myMap.geoObjects.getBounds());
if (this.showAllMarkers) {
this.$options.static.myMap.setBounds(this.$options.static.myMap.geoObjects.getBounds());
}
},
deleteMarkers(deletedMarkersIds) {
this.$options.static.myMap.geoObjects.each((collection) => {
Expand Down Expand Up @@ -268,7 +270,9 @@ export default {
coordinates(val) {
if (this.disablePan) {
if (this.$options.static.myMap.setCenter) this.$options.static.myMap.setCenter(val);
} else if (this.$options.static.myMap.panTo && this.$options.static.myMap.getZoom()) this.$options.static.myMap.panTo(val, { checkZoomRange: true });
} else if (this.$options.static.myMap.panTo && this.$options.static.myMap.getZoom()) {
this.$options.static.myMap.panTo(val, { checkZoomRange: true });
}
},
zoom() {
this.$options.static.myMap.setZoom(this.zoom);
Expand Down Expand Up @@ -316,7 +320,9 @@ export default {
if (this.placemarks && this.placemarks.length) throw new Error('Vue-yandex-maps: Attribute placemarks is not supported. Use marker component.');

this.mapObserver = new MutationObserver((() => {
if (this.$options.static.myMap.container) this.$options.static.myMap.container.fitToViewport();
if (this.$options.static.myMap.container) {
this.$options.static.myMap.container.fitToViewport();
}
}));

// Setup the observer
Expand Down
1 change: 1 addition & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ let idCounter = 1;
let VueBalloonClass;

export function setupBalloonClass(Vue) {
if (typeof Vue.extend !== 'function') return;
VueBalloonClass = Vue.extend({
props: ['marker', 'component'],
template: '<component :is="component" v-bind="{ marker, ...props.balloonComponentProps }" v-on="listeners" />',
Expand Down

0 comments on commit 3cbec0e

Please sign in to comment.