mapbox / mapbox/mapbox-directions.js

mapboxgl.GeoJSONSource is not a constructor

Open
#119 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
58
Forks
21
PR merge metrics
No merged PRs in 30d

Description

I want to move a marker in particular direction and got this error. Source Below mentioned.







body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }


mapboxgl.accessToken = 'ApiKey';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/satellite-hybrid-v8',
center: [-86.155231, 39.768458],
zoom: 6
});

var direction = 0, manual = false, speed = 0.1;

// create a GeoJSON point to serve as a starting point
var point = {
"type": "Point",
"coordinates": [-86.155231, 39.768458]
};

// add the GeoJSON above to a new vector tile source
var source = new mapboxgl.GeoJSONSource({
data: point
});

function setPosition() {
point.coordinates[0] += speed * Math.sin(direction) / 100;
point.coordinates[1] += speed * Math.cos(direction) / 100;
source.setData(point);

map.setLayoutProperty('drone', 'icon', direction * (180 / Math.PI));

if (!manual && Math.random() > 0.95) {
direction += (Math.random() - 0.5) / 2;
}

map.setCenter(point.coordinates);
}

map.on('style.load', function () {
map.addSource('drone', source);

map.addLayer({
"id": "drone-glow-strong",
"type": "circle",
"source": "drone",
"paint": {
"circle-radius": 18,
"circle-color": "#00e673",
"circle-opacity": .8
}
});

map.addLayer({
"id": "drone-glow",
"type": "circle",
"source": "drone",
"paint": {
"circle-radius": 40,
"circle-color": "#99ffcc",
"circle-opacity": 0.4
}
});

// Full icon list: https://www.mapbox.com/maki
map.addLayer({
"id": "drone",
"type": "symbol",
"source": "drone",
"layout": {
"icon-image": "car-24", // try: 'car-24', 'airport-24', 'zoo-24'
}
});

window.setInterval(setPosition, 10);
});

// Add manual control of the airplane with left and right arrow keys, just because
document.body.addEventListener('keydown', function (e) {
if (e.which == 37) { // left
direction -= 0.1;
manual = true;
}
if (e.which == 39) { // right
direction += 0.1;
manual = true;
}
if (e.which == 38) { // faster
speed = Math.min(speed + 0.1, 10);
manual = true;
e.preventDefault();
}
if (e.which == 40) { // slower
speed = Math.max(speed - 0.1, 0);
manual = true;
e.preventDefault();
}
}, true);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the inline HTML example and the mapbox-gl-js v0.12.0 script reference, then inspect the `new mapboxgl.GeoJSONSource` call and the later `map.addSource('drone', source)` entry point. Determine the supported way to provide the GeoJSON source and verify that the marker example no longer raises the constructor error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.