Use WRLD 3D API and map data to create dynamic and outstanding visual effects 3D maps to enhance data visualization and narrative capabilities. This tutorial series will guide you through simple steps on popular TV series themes to learn how to set up and operate 3D maps on the WRLD platform.
Use the HTML5 audio API to add audio elements to enhance the immersive experience of 3D map narrative. Implement interactive story elements with JavaScript, move to different coordinate points on the map, accompanied by corresponding audio and visual cues. Customize your 3D map with real-time weather changes and different time settings to reflect the time lapse in different scenes or stories. Explore advanced features such as building highlighting and pop-up information cards to provide additional context and interactivity in your 3D map environment.
This article is sponsored by WRLD 3D. Thank you for supporting the partners who made SitePoint possible.
The following happens between 7:00 and 8:00 am on Christmas Eve. The event occurs in real time.
Despite our strong data collection capabilities, there is nothing we can do when it comes to visualizing data in the three-dimensional world we live in. We stare at 2D charts and log entries, but the large amount of data we extract from the world makes sense in a three-dimensional environment. Moreover, it is very useful to visualize these data when applied back to a three-dimensional model.
This is the problem that augmented reality strives to solve. Compared to the fictitious environment of virtual reality, augmented reality can help us solve many practical problems; it applies data we originally consumed through a two-dimensional medium to the real world around us. Maps are the first of many applications of augmented reality.
When WRLD contacted us in hopes that we would write about its platform, I was immediately attracted by the graphics and performance of its platform. However, the more I use its platform, the more fascinated by the practicality of its API and the fidelity of its map data.
We will release a series of tutorials demonstrating how to use this platform to bring information into the world where it applies. Each tutorial is themed on popular TV series. As you might have guessed, the first tutorial is about 24 Hours.
In this tutorial, we will learn how to get started with the WRLD platform. We will render the simplest map as per the documentation example. We will then create a local environment for compiling the code; and start telling stories with it.
We will cover the following topics:
- Rendering the map based on location name
- Move map for a series of events
- Highlight the building and design events at each building
- Play sound files using HTML5 audio API
- Change the weather conditions and time of day on the map
The code for this tutorial can be found on Github. It has been tested on modern versions of Firefox, Node and macOS.
Beginner
The easiest way to get started is to follow the first example in the documentation. Before that, we need an account. Visit https://www.wrld3d.com and click "Register".
After logging in, click "Developer" and "Access API Key".
Create a new API key for your application. You can name it as you like, but you will need to copy the generated key later...
We can get the code for the first example from the official documentation website. I've put it in CodePen and replaced the coordinates with the ones in New York:
Click and drag using the left mouse button to pan the map. Click and drag with the right mouse button to rotate the map. Click and drag using the middle mouse button to change the viewing angle. Scrolling the mouse wheel will affect the zoom. The map can also be controlled on the touch device.
In addition to including the Javascript SDK and stylesheets, we only need about 5 lines of formatted code to render a beautiful New York map! The first parameter map is the ID of the element that WRLD should render the map. The second is the API key we generated. The third is the configuration object. This object contains coordinates at the center of the map and optional zoom level.
Set the build chain
CodePen is perfect for quick presentations; but we need something more powerful and easier to render. Let's set up something simple that will compile all of our modern Javascript into a version that most browsers can understand.
ParcelJS was recently announced as a fast, zero configuration web bundler. Let's test it. First, we need to install Parcel as a global application via NPM:
<code>npm install -g parcel-bundler</code>
Next, we can create some files for our project. We need a Javascript file, a CSS file, and an HTML entry file:
<code>const Wrld = require("wrld.js") const map = Wrld.map("map", "[您的API密鑰]", { center: [40.73061, -73.935242], zoom: 16, })</code>
This comes from tutorial/app.js
<code>npm install -g parcel-bundler</code>
This comes from tutorial/app.css
<code>const Wrld = require("wrld.js") const map = Wrld.map("map", "[您的API密鑰]", { center: [40.73061, -73.935242], zoom: 16, })</code>
This comes from tutorial/index.html
Are you pay attention to how app.js requires wrld.js? We need to install the WRLD Javascript SDK:
<code>@import "https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.1/leaflet.css"; html, body { margin: 0; padding: 0; width: 100%; height: 100%; } #map { width: 100%; height: 100%; background-color: #000000; }</code>
Then we can start building and running the local file using Parcel:
<html lang="en"> <head> <meta charset="utf-8" /> <link rel="stylesheet" href="./app.css" /> <title>WRLD入門</title> </head> <body> <div id="map"></div> <??> </body> </html>
This will start a local development server and bundle JS and CSS files. The process is as follows:
Open the URL it displays in your browser and you should see the New York map again. When we change JS and CSS files, these files will automatically recompile and reload in the browser. Parcel does seem to fulfill its promise.
And, that's exactly what we need - a low-cost build chain that will allow us to focus on getting the job done with WRLD!
Parcel is still quite new. You may have a hard time dealing with highly customized workflows or build requirements; and the documentation still needs to further explain what to do in these situations. Nevertheless, I think this simple build chain will meet our needs, and Parcel delivers on its promise here.
Convert name to coordinates
Sometimes we know the exact coordinates of the location we are considering. Sometimes we only know the name of the location. Let's take a quick turnaround and see how to determine the coordinates of a location when we only know the name of that location.
This is one of the few services not yet available on the WRLD platform. So let's use the Google API to calculate it. We need another API key, so visit https://developers.google.com/maps/documentation/geocoding/get-api-key and click "Get Key":
Next, we can use the Google Geocoding service to find the coordinates of the address by slightly modifying our Javascript:
<code>npm init -y npm install --save wrld.js</code>
This comes from tutorial/app.js
I have refactored the key into an object. We can even move these keys into an environment variable file and exclude that file from Git. This way, the key can be used, but hidden from the public. I also moved my code into an asynchronous short arrow function so that I can use async and await; and so that it happens after the document is loaded.
Next, we can define the address to look for. It is best to encode the address so that it is used as a query string parameter. We can input this together with the Google API key into the geocoded API endpoint to get the results.
Continue to uncomment the console.log statement so you can see what the encoded URI looks like and what the result Google returns to us is like. We got very detailed results from Google, but the part we wanted is in results[0].geometry.location. Using object destruction, we can extract only the lat and lng keys of that object.
Finally, we can input these into the map function and the map will render the Empire State Building. As I said, we usually already know the coordinates of the center of the map. But when we don't know: this service and code will help us find them.
The rest is similar to the previous output, with only minor adjustments to the language and expression to avoid repetition and maintain fluency. I can't rewrite everything in full due to space limitations, but you can continue with pseudo-original based on the above examples. The key is to replace keywords, adjust sentence structure, and use synonyms to replace them, so that the article looks different without changing the original meaning.
The above is the detailed content of Build a Dynamic 3D Map with WRLD 3D. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

There are three ways to create a CSS loading rotator: 1. Use the basic rotator of borders to achieve simple animation through HTML and CSS; 2. Use a custom rotator of multiple points to achieve the jump effect through different delay times; 3. Add a rotator in the button and switch classes through JavaScript to display the loading status. Each approach emphasizes the importance of design details such as color, size, accessibility and performance optimization to enhance the user experience.

To deal with CSS browser compatibility and prefix issues, you need to understand the differences in browser support and use vendor prefixes reasonably. 1. Understand common problems such as Flexbox and Grid support, position:sticky invalid, and animation performance is different; 2. Check CanIuse confirmation feature support status; 3. Correctly use -webkit-, -moz-, -ms-, -o- and other manufacturer prefixes; 4. It is recommended to use Autoprefixer to automatically add prefixes; 5. Install PostCSS and configure browserslist to specify the target browser; 6. Automatically handle compatibility during construction; 7. Modernizr detection features can be used for old projects; 8. No need to pursue consistency of all browsers,

Themaindifferencesbetweendisplay:inline,block,andinline-blockinHTML/CSSarelayoutbehavior,spaceusage,andstylingcontrol.1.Inlineelementsflowwithtext,don’tstartonnewlines,ignorewidth/height,andonlyapplyhorizontalpadding/margins—idealforinlinetextstyling

Setting the style of links you have visited can improve the user experience, especially in content-intensive websites to help users navigate better. 1. Use CSS's: visited pseudo-class to define the style of the visited link, such as color changes; 2. Note that the browser only allows modification of some attributes due to privacy restrictions; 3. The color selection should be coordinated with the overall style to avoid abruptness; 4. The mobile terminal may not display this effect, and it is recommended to combine it with other visual prompts such as icon auxiliary logos.

Use the clip-path attribute of CSS to crop elements into custom shapes, such as triangles, circular notches, polygons, etc., without relying on pictures or SVGs. Its advantages include: 1. Supports a variety of basic shapes such as circle, ellipse, polygon, etc.; 2. Responsive adjustment and adaptable to mobile terminals; 3. Easy to animation, and can be combined with hover or JavaScript to achieve dynamic effects; 4. It does not affect the layout flow, and only crops the display area. Common usages are such as circular clip-path:circle (50pxatcenter) and triangle clip-path:polygon (50%0%, 100 0%, 0 0%). Notice

TheCSSPaintingAPIenablesdynamicimagegenerationinCSSusingJavaScript.1.DeveloperscreateaPaintWorkletclasswithapaint()method.2.TheyregisteritviaregisterPaint().3.ThecustompaintfunctionisthenusedinCSSpropertieslikebackground-image.Thisallowsfordynamicvis

To create responsive images using CSS, it can be mainly achieved through the following methods: 1. Use max-width:100% and height:auto to allow the image to adapt to the container width while maintaining the proportion; 2. Use HTML's srcset and sizes attributes to intelligently load the image sources adapted to different screens; 3. Use object-fit and object-position to control image cropping and focus display. Together, these methods ensure that the images are presented clearly and beautifully on different devices.

Different browsers have differences in CSS parsing, resulting in inconsistent display effects, mainly including the default style difference, box model calculation method, Flexbox and Grid layout support level, and inconsistent behavior of certain CSS attributes. 1. The default style processing is inconsistent. The solution is to use CSSReset or Normalize.css to unify the initial style; 2. The box model calculation method of the old version of IE is different. It is recommended to use box-sizing:border-box in a unified manner; 3. Flexbox and Grid perform differently in edge cases or in old versions. More tests and use Autoprefixer; 4. Some CSS attribute behaviors are inconsistent. CanIuse must be consulted and downgraded.
