mapbox / mapbox.js

Mapbox JavaScript API, a Leaflet Plugin
mapbox.com/mapbox.js/
Other
1.92k stars 386 forks source link

The 'icon' field can't be undefined in L.markerOptions. #1302

Closed jim-king-2000 closed 3 years ago

jim-king-2000 commented 4 years ago

See the code below:

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>A simple map</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.mapbox.com/mapbox.js/v3.2.0/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v3.2.0/mapbox.css' rel='stylesheet' />
<style>
  body { margin:0; padding:0; }
  #map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
L.mapbox.accessToken = 'pk.eyJ1IjoiamltLWtpbmctMjAwMCIsImEiOiJjazFqaG41azcyMHczM2NwNnZlcWhtcG54In0.VJFYenX5OVz3R-z_JjB16w';
var map = L.mapbox.map('map')
  .setView([40, -74.50], 9)
  .addLayer(L.mapbox.styleLayer('mapbox://styles/mapbox/streets-v11'));
var marker = L.marker([40, -74.50], {
  icon: undefined
}).addTo(map);
</script>
</body>
</html>

This code generates an error: 'leaflet-src.js:7549 Uncaught TypeError: Cannot read property 'createIcon' of undefined'. The relevant code is:

var marker = L.marker([40, -74.50], {
  icon: undefined
}).addTo(map);

While the following code is OK.

var marker = L.marker([40, -74.50]).addTo(map);
var marker = L.marker([40, -74.50], {}).addTo(map);

Summary: Undefined field should behave exactly the same as omitted one, i.e., { icon: undefined } should be equal to {}.