Skip to content

Commit

Permalink
bump mapbox-gl to 3.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
huanglii committed Jul 5, 2024
1 parent 30b765d commit dc8dde5
Show file tree
Hide file tree
Showing 17 changed files with 1,881 additions and 284 deletions.
5 changes: 3 additions & 2 deletions docs/.vuepress/components/control/HomeControl.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { AnimationOptions, CameraOptions } from 'mapbox-gl'
import { createDom, removeDom } from '../../utils'

const className = 'mapboxgl-ctrl'
class HomeControl implements mapboxgl.IControl {
private _container: HTMLElement
private _map?: mapboxgl.Map
private _options: mapboxgl.EaseToOptions
private _options: CameraOptions & AnimationOptions

constructor(options: mapboxgl.EaseToOptions) {
constructor(options: CameraOptions & AnimationOptions) {
this._options = Object.assign(
{},
{
Expand Down
13 changes: 6 additions & 7 deletions docs/.vuepress/components/map/base-map.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import HomeControl from '../control/HomeControl';
interface Props {
height?: number
mapOptions?: Omit<mapboxgl.MapboxOptions, 'container'>
mapOptions?: Omit<mapboxgl.MapOptions, 'container'>
mapClickable?: boolean
}
const props = withDefaults(defineProps<Props>(), {
Expand All @@ -32,9 +32,8 @@ let map: mapboxgl.Map
let mapLoaded = ref(false)
onMounted(() => {
const mapDefaultOptions: mapboxgl.MapboxOptions = {
const mapDefaultOptions: mapboxgl.MapOptions = {
container: mapContainer,
// style: STYLE.DEFAULT,
style: withBase('/mapbox/standard.json'),
center: [104.294538, 35.860092],
zoom: 2.4,
Expand Down Expand Up @@ -67,7 +66,7 @@ onMounted(() => {
initMap(options)
})
const initMap = (options: mapboxgl.MapboxOptions) => {
const initMap = (options: mapboxgl.MapOptions) => {
mapboxgl.accessToken = TK
map = new mapboxgl.Map(options)
map.addControl(new mapboxgl.AttributionControl({
Expand All @@ -86,12 +85,12 @@ const initMap = (options: mapboxgl.MapboxOptions) => {
}),
'bottom-left'
)
map.on('load', (e: mapboxgl.MapboxEvent<undefined> & mapboxgl.EventData) => {
map.on('load', (e) => {
mapLoaded.value = true
emit('load', e.target)
})
if (props.mapClickable) {
map.on('click', (e: mapboxgl.MapMouseEvent & mapboxgl.EventData) => {
map.on('click', (e) => {
const features = map.queryRenderedFeatures(e.point)
if (features.length > 0) {
Expand All @@ -101,7 +100,7 @@ const initMap = (options: mapboxgl.MapboxOptions) => {
if (geometry.type === 'Point') {
lngLat = geometry.coordinates as [number, number]
}
if (properties) {
if (layer && properties) {
new mapboxgl.Popup().setLngLat(lngLat).setHTML(createPropHtml(layer.id, properties)).addTo(map)
}
}
Expand Down
13 changes: 5 additions & 8 deletions docs/.vuepress/components/map/starter/standard-style/imports.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<template>
<base-map :map-options="mapOptions" @load="handleMapLoaded" />
<base-map :map-options="mapOptions" />
</template>

<script setup lang="ts">
import { withBase } from '@vuepress/client'
import BaseMap from '../../base-map.vue'
import { withBase } from '@vuepress/client';
import type { MapOptions } from 'mapbox-gl';
import BaseMap from '../../base-map.vue';
const mapOptions: Omit<mapboxgl.MapboxOptions, 'container'> = {
const mapOptions: Omit<MapOptions, 'container'> = {
center: [107.744809, 30.180706],
zoom: 6,
style: {
Expand Down Expand Up @@ -37,8 +38,4 @@ const mapOptions: Omit<mapboxgl.MapboxOptions, 'container'> = {
]
}
}
function handleMapLoaded(map: mapboxgl.Map) {
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
</template>

<script setup lang="ts">
import BaseMap from '../../base-map.vue'
import type { MapOptions } from 'mapbox-gl';
import BaseMap from '../../base-map.vue';
const mapOptions: Omit<mapboxgl.MapboxOptions, 'container'> = {
const mapOptions: Omit<MapOptions, 'container'> = {
center: [2.2945, 48.8606],
zoom: 15.4,
pitch: 60,
}
function handleMapLoaded(map: mapboxgl.Map) {
function handleMapLoaded(map) {
let lightPreset = 'day'
const h = new Date().getHours()
Expand Down
54 changes: 54 additions & 0 deletions docs/.vuepress/components/map/starter/standard-style/model.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<template>
<base-map :map-options="mapOptions" @load="handleMapLoaded" />
</template>

<script setup lang="ts">
import BaseMap from '../../base-map.vue'
const mapOptions: Omit<mapboxgl.MapboxOptions, 'container'> = {
center: [2.2945, 48.8606],
zoom: 18,
pitch: 60,
}
function handleMapLoaded(map: mapboxgl.Map) {
map.on('click', e => console.log(e.lngLat))
map.setConfigProperty('basemap', 'showPointOfInterestLabels', false)
map.setConfigProperty('basemap', 'showPlaceLabels', false)
map.setConfigProperty('basemap', 'showRoadLabels', false)
map.setConfigProperty('basemap', 'showTransitLabels', false)
map.addSource('point', {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: [{
type: 'Feature',
properties: { id: 2 },
geometry: {
type: 'Point',
coordinates: [2.2944, 48.8615],
}
}]
}
})
map.addLayer({
id: 'point-with-model',
type: 'model',
source: 'point',
layout: {
'model-id': 'pine1-lod1'
},
"paint": {
"model-scale": [70.0, 50.0, 50.0],
"model-rotation": ["match", ["%", ["get", "id"], 4],
0, ["literal", [0.0, 0.0, 0.0]],
1, ["literal", [0.0, 0.0, 60.0]],
2, ["literal", [10.0, 0.0, 180.0]],
["literal", [0.0, -3.0, -90]]],
"model-color": "red",
"model-color-mix-intensity": 1.0
}
})
}
</script>
171 changes: 171 additions & 0 deletions docs/.vuepress/components/map/starter/standard-style/model1.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<template>
<base-map :map-options="mapOptions" @load="handleMapLoaded" />
</template>

<script setup lang="ts">
import BaseMap from '../../base-map.vue'
const mapOptions: Omit<mapboxgl.MapboxOptions, 'container'> = {
"pitch": 60,
"bearing": 0,
"zoom": 15,
"center": [
-122.40784,
37.78432
],
style: {
"version": 8,
"metadata": {
"test": {
"height": 512,
"allowed": 0.0015,
"operations": [
["setPaintProperty", "tree-layer", "model-color-mix-intensity", 0.0],
["wait"]
]
}
},
"sources": {
"mapbox": {
"type": "vector",
"url": "mapbox://mapbox.mapbox-streets-v8"
},
"trees": {
"type": "geojson",
"data": "http://localhost:8080/mapbox-gl-js-cookbook/data/trees.geojson"
}
},
"transition": {
"duration": 0
},
"models": {
"pine1-lod1": "mapbox://models/mapbox/pine1-lod1.glb",
// "tree": "http://localhost:8080/mapbox-gl-js-cookbook/data/tree-metallic.glb",
// "tree-diffuse": "http://localhost:8080/mapbox-gl-js-cookbook/data/tree-no-material.glb"
},
// "light": {
// "intensity": 1,
// "position": [1, 110, 90],
// "anchor": "map"
// },
// "fog": {
// "range": [-1.5, 3.0]
// },
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": "#aaaaaa"
}
},
{
"id": "3d-buildings",
"source": "mapbox",
"paint": {
"fill-extrusion-opacity": 0.7,
"fill-extrusion-color": "white",
"fill-extrusion-height": [
"number",
[
"get",
"height"
]
],
"fill-extrusion-base": [
"number",
[
"get",
"min_height"
]
]
},
"filter": [
"==",
[
"get",
"extrude"
],
"true"
],
"source-layer": "building",
"type": "fill-extrusion"
}
]
}
}
function handleMapLoaded(map: mapboxgl.Map) {
map.on('click', e => console.log(e.lngLat))
map.addSource('point', {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: [{
type: 'Feature',
properties: { id: 2 },
geometry: {
type: 'Point',
coordinates: [-122.409721, 37.782875],
}
}]
}
})
map.addLayer({
id: 'point-with-model',
type: 'model',
source: 'point',
layout: {
'model-id': 'pine1-lod1'
},
"paint": {
"model-scale": [20.0, 20.0, 70.0],
// "model-rotation": ["match", ["%", ["get", "id"], 4],
// 0, ["literal", [0.0, 0.0, 0.0]],
// 1, ["literal", [0.0, 0.0, 60.0]],
// 2, ["literal", [10.0, 0.0, 180.0]],
// ["literal", [0.0, -3.0, -90]]],
// "model-color": "red",
// "model-color-mix-intensity": 1.0
}
})
// map.setConfigProperty('basemap', 'showPointOfInterestLabels', false)
// map.setConfigProperty('basemap', 'showPlaceLabels', false)
// map.setConfigProperty('basemap', 'showRoadLabels', false)
// map.setConfigProperty('basemap', 'showTransitLabels', false)
// map.addSource('point', {
// type: 'geojson',
// data: {
// type: 'FeatureCollection',
// features: [{
// type: 'Feature',
// properties: { id: 1 },
// geometry: {
// type: 'Point',
// coordinates: [2.2944, 48.8615],
// }
// }]
// }
// })
// map.addLayer({
// id: 'point-with-model',
// type: 'model',
// source: 'point',
// layout: {
// 'model-id': 'maple1-lod1'
// },
// "paint": {
// "model-scale": [70.0, 50.0, 50.0],
// "model-rotation": ["match", ["%", ["get", "id"], 4],
// 0, ["literal", [0.0, 0.0, 0.0]],
// 1, ["literal", [0.0, 0.0, 60.0]],
// 2, ["literal", [10.0, 0.0, 180.0]],
// ["literal", [0.0, -3.0, -90]]],
// "model-color": "red",
// "model-color-mix-intensity": 1.0
// }
// })
}
</script>
Binary file added docs/.vuepress/public/data/tree-metallic.glb
Binary file not shown.
Binary file added docs/.vuepress/public/data/tree-no-material.glb
Binary file not shown.
Binary file added docs/.vuepress/public/data/tree.glb
Binary file not shown.
Loading

0 comments on commit dc8dde5

Please sign in to comment.