Code Monkey home page Code Monkey logo

Comments (4)

vinayakkulkarni avatar vinayakkulkarni commented on May 24, 2024

You can do this via the geojson-layer w.r.t. this example – https://docs.mapbox.com/mapbox-gl-js/example/cluster/

from v-mapbox.

ConnorOnTheWeb avatar ConnorOnTheWeb commented on May 24, 2024

Thank you, we're a step closer. I see the MglGeojsonLayer component in v-mapbox.

How do I translate the vanilla js example from the Mapbox docs to the format that works with vue and v-mapbox? Where do I input the array that I have working with the Markers and how to handle popups?

from v-mapbox.

ConnorOnTheWeb avatar ConnorOnTheWeb commented on May 24, 2024

I've got clustering working, from this vanilla js example https://codepen.io/pen/?editors=0010

Looks perfect! Only thing I'm hung up on now is adding the events

This is the vanilla js code for the events:

// inspect a cluster on click
map.on('click', 'clusters', (e) => {
    const features = map.queryRenderedFeatures(e.point, {
        layers: ['clusters']
    });
    const clusterId = features[0].properties.cluster_id;
    map.getSource('earthquakes').getClusterExpansionZoom(
        clusterId,
        (err, zoom) => {
            if (err) return;

            map.easeTo({
                center: features[0].geometry.coordinates,
                zoom: zoom
            });
        }
    );
});

// popup over point on click
map.on('click', 'unclustered-point', (e) => {
    const coordinates = e.features[0].geometry.coordinates.slice();
    const mag = e.features[0].properties.mag;
    const tsunami =
        e.features[0].properties.tsunami === 1 ? 'yes' : 'no';

    while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
        coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
    }

    new mapboxgl.Popup()
        .setLngLat(coordinates)
        .setHTML(
            `magnitude: ${mag}<br>Was there a tsunami?: ${tsunami}`
        )
        .addTo(map);
});

map.on('mouseenter', 'clusters', () => {
    map.getCanvas().style.cursor = 'pointer';
});
map.on('mouseleave', 'clusters', () => {
    map.getCanvas().style.cursor = '';
});

I don't see how to add these events to the map in the v-mapbox documentation.

This is my MglGeojsonLayer component:

<MglGeojsonLayer
  v-for="(layer, idx) in layers"
  :key="idx"
  :source-id="layer.source"
  :source="geoJsonSource"
  :layer-id="layer.id"
  :layer="layer"
  :clear-source="true"
  :replace="true"
/>

I'm thinking I need to add these:

@click="onClick"
@mouseenter="mouseEnter"
@mouseleave="mouseLeave"

In nuxt methods, how can I effect the same changes to the map? (zoom in on cluster, display popup, etc)

Also how can I insert a component into the popup?

from v-mapbox.

vinayakkulkarni avatar vinayakkulkarni commented on May 24, 2024

from v-mapbox.

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.