Incorporate a data pop-up feature onto a d3js visualization map

Utilizing Data-Driven Documents to combine JSON data with Google Maps. The JavaScript code places a circle and label at a specified station location. Check out this example.

Here is the relevant JavaScript file.

And here is the corresponding JSON file.

Included in the JSON data are pH levels and soil chemistry information for each station, like station 24:


  "24": {
    "latitude": 31.967240000000004,
    "longitude": -111.09028,
    "pH Buffer": 0.0,
    "pH": 7.53,
    "Aluminum": 25.28,
    "Antimonies": 0.32,
    "Arsenic ": 0.08,
    "Barium": 46.27,
    "Beryllium": 0.2,
    "Boron": 0.66,
    "Cadmium": 0.03,
<more>
    "Zinc": 0.15
  },

The JSON file will be updated to present chemistry data in quotes along with measurement symbols (mg/kg).

How can we modify the JavaScript to display chemical details on mouseover.

We aim to create an effect similar to what's done for US Congressional Districts and the New York Times.

Both examples have pop-up information displayed upon mouseover (NYT) or mouseclick (US Congressional Districts).

In the case of US Congressional Districts, the map and pop-up info are generated using GitHub services. Only a subset of the information from the GeoJSON file appears in the pop-up.

For instance:

"properties": {"startcong": "103", "district": "0", "statename": "Wyoming", "endcong": "112", "id": "056103112000"}

This is transformed into a pop-up table:

| startcong | 103             |
| district  | 0               |
| statename | Wyoming         |
| member    | [object Object] |
| endcong   | 112             |
| id        | 056103112000    |

We are interested in integrating a service comparable to GitHub's, but suitable for a standalone HTML + JS document.

Answer №1

When it comes to customizing maps, Google Maps falls short in providing high flexibility. For example, both NYT and US Congressional Districts do not use Google Maps; instead, NYT utilizes a direct SVG file of the USA Albers map.

However, you can override Google Maps event handlers by disabling them. Simply add disableDoubleClickZoom: true to your map options.

var map = new google.maps.Map(d3.select("#map").node(), {
zoom: 8,
center: new google.maps.LatLng(32.96, -111.090),
mapTypeId: google.maps.MapTypeId.TERRAIN,
disableDoubleClickZoom: true,
scrollwheel: false
});

Don't forget to change overlayLayer to overlayMouseTarget:

var layer = d3.select(this.getPanes().overlayMouseTarget).append("div")

To enhance the user experience, consider adding a tooltip to circles represented on the map using d3.tips:

var tip = d3.tip()
.attr('class', 'd3-tip')
.offset([+20, -20])
.html(function(d) {
console.log(d);
return "<span style='color:blue'>" + JSON.stringify(d.value) + "</span>";
})


// Add a circle.
marker.append("svg:circle")
.attr("r", 4.5)
.attr("cx", padding)
.attr("cy", padding)
.on("mouseover",tip.show)
.on("mouseout", tip.hide)
.call(tip);

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 Event of XMLHttpRequest State Transition Error

Can anyone provide assistance in troubleshooting why the code below is not functioning as expected, displaying "something negative happened" instead of the desired PHP echo alert? The JavaScript code I am using is: window.onload = function(){ var re ...

Employing jQuery tabs to reveal or conceal extra information

We have implemented a feature on our page where five tabs are used in the center column to show/hide content. Within the right-hand column, there is specific content that should only be visible when tab one (named '#overview') is selected, which ...

Guide on initiating a GET request to a Rails server using JavaScript

I have spent hours searching online with no luck in finding a solution. I am trying to create a JavaScript function that sends a GET request to my Rails controller, and in return receives a JSON object. Does anyone know how to accomplish this? Thank you. ...

Is it possible to utilize the function(e) multiple times within a single file?

Can the same function be used multiple times in a single file? document.getElementById('one').onlick = function test(e) { var key = e.which; if(key === 13) { document.getElementById('two').c ...

Is there a way to create a component that will vanish when hovered over using only CSS and HTML?

Despite my attempts, it seems that the desired functionality is not working as demonstrated here. Here is the CSS code I used: div { background-color: yellow; padding: 20px; display: block; } div:hover { display: none; } Is it necessary ...

Scraping data from the web using R and creating interactive plots with hover text in Plotly without

I'm attempting to extract hover text content from plotly traces that have been shared online. This is a new type of scraping for me, and I'm exploring ways to accomplish this task in R without relying on selenium or phantomjs, possibly with the u ...

Secure your browsing experience with AngularJS authentication prompt

Currently, I am working on building an application using AngularJS for the front-end and JavaEE for the back-end. In my AngularJS application, I am trying to access a REST resource provided by the back-end which is protected with JAAS authentication, allow ...

JQuery: Detecting the Arrival of New Messages

Is there a way to incorporate playing a sound in the JavaScript code for the messages page only when a new message is received, without triggering it for each request? function homeAjax() { $.ajax({ url : 'subHome', success : function( ...

Selecting an option from a Javascript CSS drop-down menu functions successfully in the WebDriver IDE, but encounters issues when

Having difficulty selecting an item from a Javascript dropdown, where the items are not visible in the DOM tree until a link is clicked. Attempted to use the Actions class with code like this: Actions cursor = new Actions(driver); cursor.moveToEle ...

The input value in the HTML form was altered momentarily before reverting back to its original state

Researching this topic was quite challenging, but keep reading to find out why. My objective is to detect any changes in a form field so that I can enable the "Save" button. While this seems easy enough, there's a catch. If the user reverts the input ...

Error: HTMLButtonElement on notes-taking website unable to read property 'push' of null

I'm encountering an issue with this code that is resulting in an error message: Uncaught TypeError: Cannot read property 'push' of null at HTMLButtonElement. (app.js:15) console.log("Welcome to Notes Taking Website"); // To sto ...

When implementing ReplaySubject in Angular for a PUT request, the issue of data loss arises

I seem to be encountering a problem with the ReplaySubject. I can't quite pinpoint what I've done wrong, but the issue is that whenever I make a change and save it in the backend, the ReplaySubject fetches new data but fails to display it on the ...

Steer clear of changing props directly in VueJS to prevent unintended

I am working with a component that has props, and I need to change the value from false to true. However, I encountered a message in the Chrome console advising against mutating a prop directly because it will be overwritten whenever the parent component r ...

Hover shows no response

I'm having trouble with my hover effect. I want an element to only be visible when hovered over, but it's not working as expected. I've considered replacing the i tag with an a, and have also tried using both display: none and display: bloc ...

What is the best way to retrieve a value from a JSON object when there are duplicate

As a novice iOS developer diving into the world of JSON, I found myself searching endlessly for answers without much luck. It seems my struggle lies in formulating the right questions due to my lack of experience with JSON. The JSON snippet below is a segm ...

Adding row numbers to a table generated by a JQuery DataTable with server-side data source can be achieved by implementing a custom function

Utilizing JQuery and DataTable to display data, I am unable to add row numbers to the grid generated on the client-side. Below is a snippet of my code: HTML <table id="applications_list" class="table table-bordered datagrid"> <thead> ...

Gain entry to this specific data structure [{"id":"1","name":"2"},{...}]

Struggling to retrieve specific values from a query result: $sentenceSQL=$pdo->prepare("SELECT * FROM users_data"); $sentenceSQL->execute(); $result= $sentenceSQL->fetchAll(PDO::FETCH_ASSOC); $va = json_encode($result); echo $va; [{"id":"001","n ...

What could be causing the values I push into the array to show up as undefined?

My current project involves a personality quiz where I store answer values in an array to later analyze and determine the user's dominant personality trait. However, I am encountering an issue where the answer value of an option being pushed into the ...

What is the method for determining the length of an array in nlohmann's JSON library?

I am currently utilizing the nlohmann/json library and I'm looking to determine the length of a JSON array. Let's consider the following array: [ "test", "test2" ] My objective is to retrieve the length of this array, which in this case would b ...

Caching JSON Results in ASP .Net MVC 5

Can someone help me understand how to implement caching for JsonResult actions in an MVC 5 application? I am looking to cache certain actions that are called via AJAX using the [OutputCache()] attribute. Some of these actions return an ActionResult with HT ...