Experiencing a problem with the 'circle-color' data-driven styling feature in Mapboxgl.js & GeoJSON, yet everything is functioning correctly with the default color

I have been attempting to generate a map, plot data points using GeoJSON and Mapbox. Everything goes smoothly when I use a default color code for all points, but as soon as I try to implement data driven styling to assign different colors based on different property values, errors start cropping up. I am working with mapboxgl.js.

Upon inspecting in Chrome, the following errors pop up:

net::ERR_INTERNET_DISCONNECTED
exports.getJSON @ ajax.js:33
evented.js:111 Error
at XMLHttpRequest.r.onerror (ajax.js:18)

If anyone could offer some assistance, it would be greatly appreciated! Below are my GeoJSON and HTML files.

mapboxgl.accessToken = 'pk.eyJ1Ijoicml0YW1iaGFyYSImEiOiJjajZuNGZjNHUwNHgxMzNwc29hZ2ZkbmRvIn0.4kTuXEpbJBeoN3jCp3pfwQ';
var map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mapbox/dark-v9',
    center: [-121.403732, 40.492392],
    zoom: 10
});
map.on("load", function() {
    map.addSource('pH', {
        'type': 'geojson',
         'data': 'test.json'
    });
    map.addLayer({
        id: 'heat-map',
        type: 'circle',
        source: 'pH',
        paint: {
            // 'circle-color': '#f1f075',
            'circle-color': {
                property: 'value',
                 stops: [
                    [6, '#f1f075'],
                    [10, '#e55e5e']
                ]          
            },
            "circle-radius": 6,
            'circle-opacity': 0.8
        },
    });
});

GeoJSON file:

{
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "properties": { "value": "7" }, 
        "geometry": {
            "type": "Point",
            "coordinates": [-121.415061, 40.506229]
        }
    }, {
        "type": "Feature",
        "properties": { "value": "8" }, 
        "geometry": {
            "type": "Point",
            "coordinates": [-121.505184, 40.488084]
        }
    }, {
        "type": "Feature",
        "properties": { "value": "9" }, 
        "geometry": {
            "type": "Point",
            "coordinates": [-121.354465, 40.488737]
        }
    }]
}

Answer №1

The issue at hand seems to stem from the fact that the values in your geojson are stored as strings rather than numbers. By converting them to numbers, as shown below, I was able to make your example code function correctly:

{
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "properties": { "value": 7 }, 
        "geometry": {
            "type": "Point",
            "coordinates": [-121.415061, 40.506229]
        }
    }, {
        "type": "Feature",
        "properties": { "value": 8 }, 
        "geometry": {
            "type": "Point",
            "coordinates": [-121.505184, 40.488084]
        }
    }, {
        "type": "Feature",
        "properties": { "value": 9 }, 
        "geometry": {
            "type": "Point",
            "coordinates": [-121.354465, 40.488737]
        }
    }]
}

If you continue to encounter the AJAX error, it may be necessary to launch a local server (you can achieve this by using python -m SimpleHTTPServer within your project directory and then accessing

localhost:8000/path/to/index.html
in your browser)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The HTML changes are not reflected in the document.querySelectorAll function

Trying to select all the div elements within another div using document.querySelectorAll. Interestingly, when setting the height to 1000 in the JS, the browser's scrollbar adjusts accordingly (the balloons do not change size). What could I be doing in ...

JavaScript - Dynamic rotation algorithm

I recently developed a piece of code to manage object rotation in a THREE.js environment. Although the issue is not specific to 3D. My goal is to have my object (referred to as 'this') rotate by 0.25 radians each time a function is called, until ...

Resetting dynamic form changes in Vue.js explained

Currently, I am using a template like this: <div> <div v-for="(item, key) in items" :key="key"> <div> <input type="text" :value="item.title"> </div> ...

What is the reason behind a PHP page refresh causing a session variable to be released

In an attempt to unset a session variable after 2 minutes using unsetsession.php, I have the following code: <?php session_start(); if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 120 ...

Unable to expand or collapse rows in ng-table

Looking to implement an expand and collapse feature for ng-table, where clicking on a row should expand it to show more detail. However, currently all rows expand on click. Any ideas on how to achieve this? Any assistance would be greatly appreciated, tha ...

Validate AngularJS forms by displaying error messages based on the server's response

Within my form, I am checking for the existence of an email address. If the email already exists, I display an error message from the JSON response when the user clicks the submit button. When the email already exists, I receive a 409 error. I am looking ...

Tips for handling multiple ajax requests simultaneously on a single webpage

In my quest to create an 'ajaxified' user interface with multiple ajax calls for handling tasks such as creating, renaming, and deleting elements on the page, I initially struggled with organizing the "code behind" ajax pages. I started off by cr ...

I'm looking for guidance on utilizing the NodeRT (Windows.Gaming.Input) module within an electron environment. Can anyone provide some

I'm having trouble importing the Gamepad class from a specific module, as I keep encountering the error message "Invalid arguments, no suitable constructor found." Here is the code snippet in question: const { Gamepad } = require('@nodert-win10-2 ...

What is the process for incorporating personalized field attributes using an inlineformset_factory in Django?

I am currently working with an 'inlineformset_factory' and I am trying to determine the best way to set attributes for the individual fields. So far, I have not been able to find a method to add them without resorting to using javascript, which i ...

Utilizing base classes in callbacks with ES6 in NodeJS

Consider this scenario where I have a class as shown below: class X extends Y { constructor() { super(); } method() { asyncMethod( function( err ) { super.method( err ); } ); } } The issue here is that super actually ...

How can one determine if a new document was created by Mongoose's upsert feature?

My code in node.js/express.js looks like this: var User = mongoose.model('User'); var usersRouter = express.Router(); usersRouter.put('/:id', function(req, res) { req.body._id = req.params.id; var usr = new User(req.body); ...

Discovering the precise Offset value for a Div element

Looking for a way to identify the unique value of each div on my HTML page, even as offset values change with each refresh. Any suggestions or methods that can help achieve this? ...

When using the JavaScript .sort() method, any undefined value must always be considered as coming before any other value

I am working on sorting an array of objects based on multiple fields, typically around 3-4 fields. Some values within the objects may be undefined, and I need to ensure that these undefined values are considered as "earlier" in the sorting process, wheth ...

Verification of the password is not being conducted

I am facing an issue while trying to log in where only the username is being checked and not the password. Regardless of the password I provide, it gets accepted. If I set echo in connect.php to 1, the login process works fine except for the redirect funct ...

Tips on making a fresh form appear during the registration process

After clicking on a submit button labeled as "continue" within a form, a new form will appear for you to complete in order to continue the registration process. ...

Error: The value of 'id' cannot be assigned to an undefined property

Recently, I've been delving into learning JS Express and decided to create a basic solution to handle GET / DELETE / POST / PUT requests. Everything was running smoothly until I encountered an issue with the POST router. Below is the code snippet for ...

Is it possible to set up the material-ui datepicker to allow for the selection of dates spanning across multiple months without losing visibility of the current month?

Is it possible to choose dates within the same calendar week, regardless of whether they fall in different calendar months? For instance, selecting Friday from the previous month when the new month begins on a Saturday. To illustrate my point, let's ...

Collaborating with SockJS connectivity

Currently, my Node.js backend is interacting with desktop clients using websockets. The communication from the server side is initiated from a web front-end and everything is functioning properly because I am storing the SockJS Connection instances in an ...

Incorporating information collected from a modal form into a table using vue.js

insert code hereThis single page application allows users to input data into a modal, which is then automatically added to a table on the main page. var modal = document.getElementById('modalAdd'); var modalBtn = document.getElementById(' ...

iisnode ran into a problem while handling the request. Error code: 0x6d HTTP status code: 500 HTTP subStatus code: 1013

Currently, I am working on a web application using ReactJS for the frontend and Express for the backend. My deployment platform is Azure. In order to verify that my requests are being processed correctly, I decided to conduct two API tests. The first tes ...