Coder Social home page Coder Social logo

Comments (5)

eregnier avatar eregnier commented on July 19, 2024

from vue2-gmap-custom-marker.

eregnier avatar eregnier commented on July 19, 2024

I reproduced locally and I do not have the issue on the sample demo that are on gh-pages.
do you have some additional clues to troubleshot this issue ?
Any code avaimable ? or stack trace ?
Your code may destroy the map before the component is destroyed by the page change from the vue router.

from vue2-gmap-custom-marker.

eregnier avatar eregnier commented on July 19, 2024

Closing due to inactivity and not reproducable on my side.

from vue2-gmap-custom-marker.

anchetaWern avatar anchetaWern commented on July 19, 2024

@eregnier I got the same error. Here's the code I'm using:

<GmapMap :options="options" :center="center" :zoom="zoom" class="ais-GeoSearch-map" @zoom_changed="zoomChanged">

    <gmap-custom-marker :marker="{ lat: item._geoloc.lat, lng: item._geoloc.lng }" :key="item.objectID" v-for="(item, index) in state.items" @click.native="selectMarker(item)">
        <img src="http://lorempixel.com/50/50/nature" />
    </gmap-custom-marker>

    <GmapInfoWindow :position="selected_coordinate" :opened="isInfoWindowOpen" @closeclick="closeInfoWindow">
    {{ selectedLocation }}
    </GmapInfoWindow>

</GmapMap>

I'm using it with vue2-google-maps and instantsearch:

import Vue from "vue";
import * as VueGoogleMaps from "vue2-google-maps";
import GmapCustomMarker from "vue2-gmap-custom-marker";
import { createWidgetMixin } from "vue-instantsearch";
import { connectGeoSearch } from "instantsearch.js/es/connectors";

Vue.use(VueGoogleMaps, {
    load: {
        key: process.env.GOOGLE_API_KEY,
    },
});

export default {
    mixins: [createWidgetMixin({ connector: connectGeoSearch })],
    components: {
        'gmap-custom-marker': GmapCustomMarker
    },
    // ...
}

Here's the exact warning I'm getting:

[Vue warn]: Error in destroyed hook: "TypeError: Cannot read property 'setMap' of undefined"

found in

---> <GmapCustomMarker> at node_modules/vue2-gmap-custom-marker/gmap-custom-marker.vue
       <GmapMap> at node_modules/vue2-google-maps/dist/components/map.vue
         <AppMap> at resources/js/search/components/Map.vue
           <AisInstantSearch>
             <App> at resources/js/search/App.vue
               <Root>

I was able to solve it by doing something like this:

<gmap-custom-marker v-if="isMapInitialized" :marker="{ lat: item._geoloc.lat, lng: item._geoloc.lng }" :key="item.objectID" v-for="(item, index) in state.items">
     ...
</gmap-custom-marker>
mounted() {
        setTimeout(() => {
            this.isMapInitialized = true;
        }, 1000);
    }

Would be good to have a better way of doing it.

from vue2-gmap-custom-marker.

eregnier avatar eregnier commented on July 19, 2024

Hey . I think you should try to empty your state.items list in the wrapping component destroy hook. This would prevent map component repaint after yoyr route changed.

Is it clear enough ?

from vue2-gmap-custom-marker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.