Comments (4)
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.
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.
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.
- Repro done here – https://github.com/vinayakkulkarni/cluster
from v-mapbox.
Related Issues (20)
- Wrong docs link HOT 5
- Clustering markers on the map via vuejs component HOT 1
- @load not firing HOT 6
- [Compatibility] vue 2.7.8 HOT 1
- Error: Could not resolve Map in Nuxt 3
- How to add and load images to map
- Injection key not exported HOT 2
- The setup binding property "templateRefs" is already declared (vuejs2 legacy version) HOT 2
- Named export 'GeolocateControl' not found - The requested module 'maplibre-gl' is a CommonJS module HOT 6
- Using v-mapbox with private (Offline) Mapbox Atlas instance
- map is not loading on latest version of 'mapbox-gl' and 'v-mapbox' HOT 4
- Dependency Dashboard
- URL scheme "mapbox" is not supported
- docs: update documentation on usage for Vue 3
- Map Marker - aria-label or additional attributes?
- [3.1.0] Click on v-map fires MapMouseEvent and MouseEvent HOT 6
- Working with Vuex Map HOT 3
- .easeTo dynamic durations
- Issue with using Marker in Vue 3 HOT 8
- question: How to make v-layer-deck-geojson reactive HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from v-mapbox.