Created
February 2, 2017 05:48
-
-
Save stevage/b863ddd9364c7bf076413119215022fd to your computer and use it in GitHub Desktop.
Loop freeze bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset='utf-8' /> | |
<title></title> | |
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' /> | |
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.32.1/mapbox-gl.js'></script> | |
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.32.1/mapbox-gl.css' rel='stylesheet' /> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.4.0/d3.min.js"></script> | |
<style> | |
body { margin:0; padding:0; } | |
#map { position:absolute; top:0; bottom:0; width:100%; } | |
</style> | |
</head> | |
<body> | |
<div id='map'></div> | |
<script> | |
/* jshint esnext:true */ | |
var flightPath = { | |
"type": "FeatureCollection", | |
"features": [ | |
/*{ | |
"type": "Feature", | |
"properties": { | |
"marker-color": "#7e7e7e", | |
"marker-size": "medium", | |
"marker-symbol": "", | |
"bearing": 350 | |
}, | |
"geometry": { | |
"type": "Point", | |
"coordinates": [ | |
144.96288299560547, | |
-37.82171764783965 | |
] | |
} | |
},*/ | |
{ | |
"type": "Feature", | |
"properties": { | |
"bearing": 270 | |
}, | |
"geometry": { | |
"type": "Point", | |
"coordinates": [ | |
144.9785041809082, | |
-37.808359917423594 | |
] | |
} | |
}, | |
{ | |
"type": "Feature", | |
"properties": { | |
"marker-color": "#7e7e7e", | |
"marker-size": "medium", | |
"marker-symbol": "", | |
"bearing": 180 | |
}, | |
"geometry": { | |
"type": "Point", | |
"coordinates": [ | |
144.95558738708496, | |
-37.8057830213145 | |
] | |
} | |
}, | |
{ | |
"type": "Feature", | |
"properties": { | |
"marker-color": "#7e7e7e", | |
"marker-size": "medium", | |
"marker-symbol": "", | |
"bearing": 90 | |
}, | |
"geometry": { | |
"type": "Point", | |
"coordinates": [ | |
144.94434356689453, | |
-37.81649689372308 | |
] | |
} | |
} | |
] | |
} | |
d3.json('https://api.mapbox.com/styles/v1/gisfeedback/ciwmwq2gb00fa2ppabho4z39c?fresh=true&access_token=pk.eyJ1IjoiZ2lzZmVlZGJhY2siLCJhIjoiY2l2eDJndmtjMDFkeTJvcHM4YTNheXZtNyJ9.-HNJNch_WwLIAifPgzW2Ig&_=1481601754051', function(style) { | |
var allbuildings = { | |
"layout": { | |
"visibility": "visible" | |
}, | |
"type": "fill-extrusion", | |
"source": "composite", | |
"id": "mapbase-buildingfootprints-bwuw1f", | |
"paint": { | |
'fill-extrusion-opacity': 0.8, | |
'fill-extrusion-color': 'grey', | |
'fill-extrusion-height': { | |
type: 'identity', | |
property: 'HEIGHT' | |
} | |
}, | |
"source-layer": "MAPBASE_BuildingFootprints-bwuw1f" | |
}; | |
style.layers[style.layers.length-2] = allbuildings; | |
/*var dambuildings = { | |
"layout": { | |
"visibility": "visible" | |
}, | |
"type": "fill-extrusion", | |
"source": "composite", | |
"id": "dam-footprints", | |
"paint": { | |
'fill-extrusion-opacity': 0.9, | |
"fill-extrusion-color": { | |
"property": "shape_type", | |
"type": "categorical", | |
"stops": [ | |
["podium", "hsl(220,80%, 40%)"], | |
["tower", "hsl(220,80%, 60%)"], | |
["tower_pod", "hsl(220,80%, 60%)"] | |
] | |
}, | |
'fill-extrusion-height': { | |
type: 'identity', | |
property: 'ovlhgt_ahd' | |
} | |
}, | |
"source-layer": "developmentfootprints-aehdyj" | |
}; | |
style.layers[style.layers.length-1] = dambuildings;*/ | |
style.layers[style.layers.length-1] = undefined; | |
style.layers.length = style.layers.length - 1; | |
mapboxgl.accessToken = 'pk.eyJ1IjoiZ2lzZmVlZGJhY2siLCJhIjoiY2l2eDJndmtjMDFkeTJvcHM4YTNheXZtNyJ9.-HNJNch_WwLIAifPgzW2Ig'; | |
var map = new mapboxgl.Map({ | |
container: 'map', // container id | |
style: style,//'mapbox://styles/gisfeedback/ciwmwq2gb00fa2ppabho4z39c/', //stylesheet location | |
center: [144.97, -37.82], // starting position | |
zoom: 15, | |
minZoom: 14, | |
pitch: 45 | |
}); | |
var posNo = 0; | |
var positions = flightPath.features.map(feature => ({ | |
center: feature.geometry.coordinates, | |
zoom: 15, | |
bearing: feature.properties.bearing | |
})); | |
/*var positions = [ | |
{ center: [144.96, -37.8], zoom: 15, bearing: 10}, | |
{ center: [144.98, -37.84], zoom: 15, bearing: 160, pitch: 10}, | |
{ center: [144.995, -37.825], zoom: 15, bearing: -90}, | |
{ center: [144.97, -37.82], zoom: 15, bearing: 140} | |
];*/ | |
function moveCamera() { | |
var pos = positions[posNo]; | |
posNo = (posNo + 1) % positions.length; | |
pos.speed = 0.1; | |
pos.curve = 1.1; | |
if (pos.pitch === undefined) pos.pitch = 45; | |
map.flyTo(pos); | |
} | |
map.on('moveend', _ => setTimeout(moveCamera, 500)); | |
map.on('load', _ => setTimeout(moveCamera, 500)); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment