Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhamley committed Nov 2, 2018
1 parent 5e8a69b commit b5acbb5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 255 deletions.
254 changes: 7 additions & 247 deletions debug/image.html
Original file line number Diff line number Diff line change
@@ -1,181 +1,5 @@

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Raster TMS + Symbols Test</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<link href='https://www.mapbox.com/base/latest/base.css' rel='stylesheet' />
<script src='/dist/mapbox-gl-dev.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.45.0/mapbox-gl.css' rel='stylesheet' />

<style>
body { margin:0; padding:0; overflow:hidden;}
#map { position:absolute; top:0; bottom:0; left:0px; right:0px;}
#menu {
position: relative;
padding: 10px;
background: #fff;
width: 300px;
font-family: 'Open Sans', sans-serif;
}
input {
vertical-align: inherit
}
</style>
</head>
<body>
<div id='map'></div>
<div id='menu'>
<input id='symbol-osm' type='radio' name='rtoggle' checked value='symbol-osm'>
<label for='symbol-osm'>symbol-osm</label>
<input id='symbol-streets' type='radio' name='rtoggle' value='symbol-streets'>
<label for='symbol-streets'>symbol-streets</label>
</div>

<script>
mapboxgl.accessToken = 'pk.eyJ1IjoibWlrZWxtYXJvbiIsImEiOiJjaWZlY25lZGQ2cTJjc2trbmdiZDdjYjllIn0.Wx1n0X7aeCQyDTnK6_mrGw';
var json = [
{
"geometry": {
"coordinates": [
37.6290353,
-1.7803167
],
"type": "Point"
},
"properties": {
"is_in": "Makueni,Kenya",
"name": "Wote",
"place": "town",
"wikidata": "Q7193508"
},
"type": "Feature"
},
{
"geometry": {
"coordinates": [
37.5364803,
-1.8178943
],
"type": "Point"
},
"properties": {
"is_in": "Makueni,Kenya",
"name": "Nziu",
"place": "village"
},
"type": "Feature"
},
{
"geometry": {
"coordinates": [
37.7,
-1.8333
],
"type": "Point"
},
"properties": {
"is_in": "Makueni,Kenya",
"name": "Ngosini West",
"place": "village",
"wikidata": "Q7022586"
},
"type": "Feature"
}
];
var osm_style = {
"version": 8,
"sources": {
"openstreetmap-tiles": {
"type": "raster",
"tiles": [
"https://a.tile.openstreetmap.org/{z}/{x}/{y}.png",
],
"tileSize": 256
},
"poi": {
'type': 'geojson',
'data': {
'type': 'FeatureCollection',
'features': json
}
}
},
"layers": [{
"id": "openstreetmap-layer",
"type": "raster",
"source": "openstreetmap-tiles",
"minzoom": 0,
"maxzoom": 18
},
{
'id': 'poi-layer',
'type': 'symbol',
'source': 'poi',
'layout': {
"icon-allow-overlap": true,
'icon-image': 'bus-15',
'visibility': 'visible'
}
}]
};
var map = new mapboxgl.Map({
container: 'map', // container id
style: osm_style,
center: [37.6004, -1.7805], // starting position
zoom: 12, // starting zoom
hash: true
});
map.addControl(new mapboxgl.NavigationControl());



map.on('style.load', function() {
// map.addSource('poi', {
// 'type': 'geojson',
// 'data': {
// 'type': 'FeatureCollection',
// 'features': json
// }
// });
//
// map.addLayer({
// 'id': 'poi-layer',
// 'type': 'symbol',
// 'source': 'poi',
// 'layout': {
// "icon-allow-overlap": true,
// 'icon-image': 'bus-15',
// 'visibility': 'visible'
// }
// });
console.log('images', map.listImages());
});

function switchType(type) {
var typeId = type.target.id;
if (typeId == 'symbol-streets') {
map.setStyle('mapbox://styles/mapbox/streets-v9');
} else {
map.setStyle(osm_style);
}
}

var layerList = document.getElementById('menu');
var inputs = layerList.getElementsByTagName('input');

inputs[0].onclick = switchType;
inputs[1].onclick = switchType;

</script>

</body>
</html>


<!-- <!DOCTYPE html>
<html>
<head>
<title>Mapbox GL JS debug page</title>
<meta charset='utf-8'>
Expand Down Expand Up @@ -226,78 +50,14 @@

var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9'
minZoom: 14,
zoom: 17,
center: [-122.514426, 37.562984],
bearing: -96,
style: imageStyle,
hash: false
});

map.on('load', function() {
map.loadImage('https://upload.wikimedia.org/wikipedia/commons/thumb/6/60/Cat_silhouette.svg/400px-Cat_silhouette.svg.png', function(error, image) {
if (error) throw error;
map.addImage('cat', image);
map.addLayer({
"id": "points",
"type": "symbol",
"source": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [0, 0]
}
}]
}
},
"layout": {
"icon-image": "cat",
"icon-size": 0.25
}
});
console.log('images', map.listImages());
});
});
// var imageStyle = {
// "version": 8,
// "sources": {
// "image": {
// "type": "image",
// "url": "/test/integration/image/0.png",
// "coordinates": [
// [-122.51596391201019, 37.56238816766053],
// [-122.51467645168304, 37.56410183312965],
// [-122.51309394836426, 37.563391708549425],
// [-122.51423120498657, 37.56161849366671]
// ]
// }
// },
// "layers": [{
// "id": "background",
// "type": "background",
// "paint": {
// "background-color": "rgb(4,7,14)"
// }
// }, {
// "id": "image",
// "type": "raster",
// "source": "image"
// }]
// };
//
// var map = new mapboxgl.Map({
// container: 'map',
// minZoom: 14,
// zoom: 17,
// center: [-122.514426, 37.562984],
// bearing: -96,
// style: imageStyle,
// hash: false
// });
//
// map.on('load', function () {
// console.log('images', map.listImages());
// });
</script>
</body>
</html> -->
</html>
6 changes: 3 additions & 3 deletions src/render/image_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class ImageManager {
}
}
}
console.log('getImages', ids);

if (this.isLoaded() || hasAllDependencies) {
this._notify(ids, callback);
} else {
Expand All @@ -115,9 +115,9 @@ class ImageManager {

_notify(ids: Array<string>, callback: Callback<{[string]: StyleImage}>) {
const response = {};

for (const id of ids) {
const image = this.images[id];
console.log('image', image, id);
if (image) {
// Clone the image so that our own copy of its ArrayBuffer doesn't get transferred.
response[id] = {
Expand All @@ -126,7 +126,7 @@ class ImageManager {
sdf: image.sdf
};
} else {
warnOnce(`Image "${id}" could not be loaded. Please make sure you have added the image (with map.addImage(), an image source or a "sprite" property in your style) before using it in a layer.`);
warnOnce(`Image "${id}" could not be loaded. Please make sure you have added the image with map.addImage(), an image source or a "sprite" property in your style before using it in a layer.`);
}
}

Expand Down
5 changes: 0 additions & 5 deletions src/style-spec/validate/validate_property.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,8 @@ export default function validateProperty(options, propertyType) {
}
}


if (options.layerType === 'background' || options.layerType === 'fill' || options.layerType === 'fill-extrusion' || options.layerType === 'line' || options.layerType === 'symbol') {
if (propsThatRequireSprite.indexOf(propertyKey) > -1) {
console.log('using a potential sprite property!', propertyKey, options, style);
}
if (propsThatRequireSprite.indexOf(propertyKey) > -1 && style && !style.sprite) {
// errors.push(new ValidationError(key, value, `use of "${propertyKey}" requires a style "sprite" property`));
warnOnce(`Use of "${propertyKey}" in may require a style "sprite" property. If you're experiencing a problem, please ensure that your image has loaded correctly.`);
}
}
Expand Down

0 comments on commit b5acbb5

Please sign in to comment.