D
D
danilr2019-06-30 11:07:30
Vue.js
danilr, 2019-06-30 11:07:30

How to use one 2GIS map twice in SPA Vue page?

Moved the map and adjacent content into a separate component and use it on different routes. The map is drawn on two pages as it should, but an error is written in the console.
5d186d0c32830449843673.png

<div class="map-wrapper">
        <div ref="cap" style="width:100%; height:100%"></div>
    </div>
</div>
</template>

<script>
import DG from '2gis-maps'
// var DG = require('2gis-maps')
export default {
    data(){
        return{
            map: null
        }
    },
    mounted(){
            this.map = new DG.map(this.$refs.cap, {
                center: [54.966613, 73.439596],
                zoom: 13,
                // zoomControl: false,
                minZoom: 10,
                fullscreenControl: false,
                scrollWheelZoom: false
            });
            var myDivIcon = DG.divIcon({
                iconSize: [57, 77],
                className: "marker-custom",
                iconAnchor: [28.5, 70],
                html: '<img class="marker-img" src="/img/marker.svg">'

            });
            DG.marker([54.966613, 73.439596], {
                icon: myDivIcon
            }).addTo(this.map);
            // DG.control.zoom({position: 'bottomleft'}).addTo(map);
    },
  beforeDestroy () {
    if (this.map) this.map.remove()
  }
}

If id is written instead of ref, then the error is different -
5d186d9ddd72a689528939.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question