3D टाइल रेंडरर के साथ काम करना

फ़ोटोरियलिस्टिक 3D टाइल OGC स्टैंडर्ड glTF फ़ॉर्मैट में हैं. इसका मतलब है कि 3D विज़ुअलाइज़ेशन बनाने के लिए, किसी भी ऐसे रेंडरर का इस्तेमाल किया जा सकता है जो OGC 3D टाइल की खास बातों के साथ काम करता हो. उदाहरण के लिए, Cesium 3D विज़ुअलाइज़ेशन को रेंडर करने के लिए एक बुनियादी ओपन सोर्स लाइब्रेरी है.

CesiumJS के साथ काम करें

CesiumJS, वेब पर 3D विज़ुअलाइज़ेशन के लिए एक ओपन सोर्स JavaScript लाइब्रेरी है. CesiumJS इस्तेमाल करने के बारे में ज़्यादा जानकारी के लिए, CesiumJS के बारे में जानें लेख पढ़ें.

उपयोगकर्ता नियंत्रण

CesiumJS टाइल रेंडरर में उपयोगकर्ता कंट्रोल का एक स्टैंडर्ड सेट मौजूद होता है.

ऐक्शन जानकारी
पैन व्यू लेफ़्ट क्लिक करके खींचें और छोड़ें
ज़ूम दृश्य राइट क्लिक करके खींचें और छोड़ें या माउस व्हील को स्क्रोल करें
व्यू घुमाएं Ctrl + लेफ़्ट/राइट क्लिक करके खींचें और छोड़ें या बीच में क्लिक करके खींचें और छोड़ें

सबसे सही तरीके

CesiumJS 3D लोड होने में लगने वाला समय कम करने के लिए, कई तरीके अपनाए जा सकते हैं. उदाहरण के लिए:

  • अपने रेंडरिंग एचटीएमएल में यह स्टेटमेंट जोड़कर एक साथ कई अनुरोध करने की सुविधा चालू करें:

    Cesium.RequestScheduler.requestsByServer["tile.googleapis.com:443"] = <REQUEST_COUNT>
    

    REQUEST_COUNT जितना ज़्यादा होगा टाइल उतनी तेज़ी से लोड होंगी. हालांकि, जब ऐसे Chrome ब्राउज़र में लोड किया जाता है जिसमें REQUEST_COUNT 10 से ज़्यादा और कैश मेमोरी की सुविधा बंद हो, तो आपको Chrome से जुड़ी किसी समस्या का सामना करना पड़ सकता है. ज़्यादातर मामलों में, बेहतर परफ़ॉर्मेंस के लिए हम 18 के REQUEST_COUNT का सुझाव देते हैं.

  • जानकारी वाले लेवल को स्किप करने की सुविधा चालू करें. ज़्यादा जानकारी के लिए, सीज़ियम से जुड़ी समस्या देखें.

showCreditsOnScreen: true को चालू करके पक्का करें कि आपने डेटा एट्रिब्यूशन को सही तरीके से दिखाया है. ज़्यादा जानकारी के लिए, नीतियां देखें.

मेट्रिक रेंडर करना

फ़्रेमरेट पता करने के लिए, देखें कि हर सेकंड में requestAnimationFrame मेथड को कितनी बार कॉल किया जाता है.

फ़्रेम के इंतज़ार के समय का हिसाब कैसे लगाया जाता है, यह जानने के लिए PerformanceDisplay क्लास देखें.

CesiumJS रेंडरर के उदाहरण

आप बस रूट टाइलसेट यूआरएल को देकर, Map Tiles API की 3D टाइल के साथ CesiumJS रेंडरर का इस्तेमाल कर सकते हैं.

आसान उदाहरण

नीचे दिए गए उदाहरण में CesiumJS रेंडरर शुरू करता है और फिर रूट टाइलसेट लोड करता है.

<!DOCTYPE html>
<head>
  <meta charset="utf-8">
  <title>CesiumJS 3D Tiles Simple Demo</title>
  <script src="https://ajax.googleapis.com/ajax/libs/cesiumjs/1.105/Build/Cesium/Cesium.js"></script>
  <link href="https://ajax.googleapis.com/ajax/libs/cesiumjs/1.105/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
</head>
<body>
  <div id="cesiumContainer"></div>
  <script>

    // Enable simultaneous requests.
    Cesium.RequestScheduler.requestsByServer["tile.googleapis.com:443"] = 18;

    // Create the viewer.
    const viewer = new Cesium.Viewer('cesiumContainer', {
      imageryProvider: false,
      baseLayerPicker: false,
      geocoder: false,
      globe: false,
      // https://cesium.com/blog/2018/01/24/cesium-scene-rendering-performance/#enabling-request-render-mode
      requestRenderMode: true,
    });

    // Add 3D Tiles tileset.
    const tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
      url: "https://tile.googleapis.com/v1/3dtiles/root.json?key=YOUR_API_KEY",
      // This property is needed to appropriately display attributions
      // as required.
      showCreditsOnScreen: true,
    }));
  </script>
</body>

requestRenderMode के बारे में जानकारी पाने के लिए, रेंडर मोड के लिए अनुरोध चालू करना देखें.

एचटीएमएल पेज, उसी तरह रेंडर होता है जैसा यहां दिखाया गया है.

Places API इंटिग्रेशन

ज़्यादा जानकारी पाने के लिए, जगह एपीआई के साथ CesiumJS का इस्तेमाल करें. स्थानों के व्यूपोर्ट पर जाने के लिए आप ऑटोकंप्लीट विजेट का इस्तेमाल कर सकते हैं. इस उदाहरण में, Places के अपने-आप पूरे होने वाले एपीआई का इस्तेमाल किया गया है. इसे इन निर्देशों का पालन करके, और Maps JavaScript API को चालू किया गया है. इसे इन निर्देशों का पालन करके चालू किया गया है.

<!DOCTYPE html>
<head>
 <meta charset="utf-8" />
 <title>CesiumJS 3D Tiles Places API Integration Demo</title>
 <script src="https://ajax.googleapis.com/ajax/libs/cesiumjs/1.105/Build/Cesium/Cesium.js"></script>
 <link href="https://ajax.googleapis.com/ajax/libs/cesiumjs/1.105/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
</head>
<body>
 <label for="pacViewPlace">Go to a place: </label>
 <input
   type="text"
   id="pacViewPlace"
   name="pacViewPlace"
   placeholder="Enter a location..."
   style="width: 300px"
 />
 <div id="cesiumContainer"></div>
 <script>
   // Enable simultaneous requests.
   Cesium.RequestScheduler.requestsByServer["tile.googleapis.com:443"] = 18;

   // Create the viewer.
   const viewer = new Cesium.Viewer("cesiumContainer", {
     imageryProvider: false,
     baseLayerPicker: false,
     requestRenderMode: true,
     geocoder: false,
     globe: false,
   });

   // Add 3D Tiles tileset.
   const tileset = viewer.scene.primitives.add(
     new Cesium.Cesium3DTileset({
       url: "https://tile.googleapis.com/v1/3dtiles/root.json?key=YOUR_API_KEY",
       // This property is required to display attributions as required.
       showCreditsOnScreen: true,
     })
   );

   const zoomToViewport = (viewport) => {
     viewer.entities.add({
       polyline: {
         positions: Cesium.Cartesian3.fromDegreesArray([
           viewport.getNorthEast().lng(), viewport.getNorthEast().lat(),
           viewport.getSouthWest().lng(), viewport.getNorthEast().lat(),
           viewport.getSouthWest().lng(), viewport.getSouthWest().lat(),
           viewport.getNorthEast().lng(), viewport.getSouthWest().lat(),
           viewport.getNorthEast().lng(), viewport.getNorthEast().lat(),
         ]),
         width: 10,
         clampToGround: true,
         material: Cesium.Color.RED,
       },
     });
     viewer.flyTo(viewer.entities);
   };

   function initAutocomplete() {
     const autocomplete = new google.maps.places.Autocomplete(
       document.getElementById("pacViewPlace"),
       {
         fields: [
           "geometry",
           "name",
         ],
       }
     );
     autocomplete.addListener("place_changed", () => {
       viewer.entities.removeAll();
       const place = autocomplete.getPlace();
       if (!place.geometry || !place.geometry.viewport) {
         window.alert("No viewport for input: " + place.name);
         return;
       }
       zoomToViewport(place.geometry.viewport);
     });
   }
 </script>
 <script
   async=""
   src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places&callback=initAutocomplete"
 ></script>
</body>

रोटेटिंग ड्रोन व्यू

टाइलसेट की मदद से ऐनिमेट करने के लिए, कैमरा कंट्रोल किया जा सकता है. Places API और एलिवेशन एपीआई के साथ इस्तेमाल करने पर, यह ऐनिमेशन किसी भी लोकप्रिय जगह के इंटरैक्टिव ड्रोन फ़्लाइओवर की नकल करता है.

यह कोड सैंपल आपको उस जगह पर ले जाता है जिसे आपने ऑटोकंप्लीट विजेट में चुना था.

<!DOCTYPE html>
<head>
  <meta charset="utf-8" />
  <title>CesiumJS 3D Tiles Rotating Drone View Demo</title>
  <script src="https://ajax.googleapis.com/ajax/libs/cesiumjs/1.105/Build/Cesium/Cesium.js"></script>
  <link href="https://ajax.googleapis.com/ajax/libs/cesiumjs/1.105/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
</head>
<body>
  <label for="pacViewPlace">Go to a place: </label>
  <input type="text" id="pacViewPlace" name="pacViewPlace" placeholder="Enter a location..." style="width: 300px" />
  <div id="cesiumContainer"></div>
  <script>
    // Enable simultaneous requests.
    Cesium.RequestScheduler.requestsByServer["tile.googleapis.com:443"] = 18;

    // Create the viewer and remove unneeded options.
    const viewer = new Cesium.Viewer("cesiumContainer", {
      imageryProvider: false,
      baseLayerPicker: false,
      homeButton: false,
      fullscreenButton: false,
      navigationHelpButton: false,
      vrButton: false,
      sceneModePicker: false,
      geocoder: false,
      globe: false,
      infobox: false,
      selectionIndicator: false,
      timeline: false,
      projectionPicker: false,
      clockViewModel: null,
      animation: false,
      requestRenderMode: true,
    });

    // Add 3D Tile set.
    const tileset = viewer.scene.primitives.add(
      new Cesium.Cesium3DTileset({
        url: "https://tile.googleapis.com/v1/3dtiles/root.json?key=YOUR_API_KEY",
        // This property is required to display attributions.
        showCreditsOnScreen: true,
      })
    );

    // Point the camera at a location and elevation, at a viewport-appropriate distance.
    function pointCameraAt(location, viewport, elevation) {
      const distance = Cesium.Cartesian3.distance(
        Cesium.Cartesian3.fromDegrees(
          viewport.getSouthWest().lng(), viewport.getSouthWest().lat(), elevation),
        Cesium.Cartesian3.fromDegrees(
          viewport.getNorthEast().lng(), viewport.getNorthEast().lat(), elevation)
      ) / 2;
      const target = new Cesium.Cartesian3.fromDegrees(location.lng(), location.lat(), elevation);
      const pitch = -Math.PI / 4;
      const heading = 0;
      viewer.camera.lookAt(target, new Cesium.HeadingPitchRange(heading, pitch, distance));
    }

    // Rotate the camera around a location and elevation, at a viewport-appropriate distance.
    let unsubscribe = null;
    function rotateCameraAround(location, viewport, elevation) {
      if(unsubscribe) unsubscribe();
      pointCameraAt(location, viewport, elevation);
      unsubscribe = viewer.clock.onTick.addEventListener(() => {
        viewer.camera.rotate(Cesium.Cartesian3.UNIT_Z);
      });
    }

    function initAutocomplete() {
      const autocomplete = new google.maps.places.Autocomplete(
        document.getElementById("pacViewPlace"), {
          fields: [
            "geometry",
            "name",
          ],
        }
      );
      
      autocomplete.addListener("place_changed", async () => {
        const place = autocomplete.getPlace();
        
        if (!(place.geometry && place.geometry.viewport && place.geometry.location)) {
          window.alert(`Insufficient geometry data for place: ${place.name}`);
          return;
        }
        // Get place elevation using the ElevationService.
        const elevatorService = new google.maps.ElevationService();
        const elevationResponse =  await elevatorService.getElevationForLocations({
          locations: [place.geometry.location],
        });

        if(!(elevationResponse.results && elevationResponse.results.length)){
          window.alert(`Insufficient elevation data for place: ${place.name}`);
          return;
        }
        const elevation = elevationResponse.results[0].elevation || 10;

        rotateCameraAround(
          place.geometry.location,
          place.geometry.viewport,
          elevation
        );
      });
    }
  </script>
  <script async src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places&callback=initAutocomplete"></script>
</body>

पॉलीलाइन और लेबल बनाना

यह कोड सैंपल, मैप में पॉलीलाइन और लेबल जोड़ने का तरीका बताता है. ड्राइविंग और पैदल चलने के निर्देश दिखाने या प्रॉपर्टी की सीमाएं दिखाने या ड्राइविंग और पैदल चलने में लगने वाले समय का हिसाब लगाने के लिए, मैप में पॉलीलाइन जोड़ें. सीन को रेंडर किए बिना भी एट्रिब्यूट हासिल किए जा सकते हैं.

आप उपयोगकर्ताओं को आस-पड़ोस के चुनिंदा टूर पर ले जा सकते हैं या वे आस-पास की ऐसी प्रॉपर्टी दिखा सकते हैं जो फ़िलहाल बिक्री के लिए उपलब्ध हैं. इसके बाद, आप सीन में बिलबोर्ड जैसे 3D ऑब्जेक्ट जोड़ सकते हैं.

आपने जो प्रॉपर्टी देखी हैं उनकी सूची बनाकर, यात्रा की खास जानकारी दी जा सकती है. ऐसा करके, इस जानकारी को वर्चुअल ऑब्जेक्ट में दिखाया जा सकता है.

<!DOCTYPE html>
<head>
  <meta charset="utf-8" />
  <title>CesiumJS 3D Tiles Polyline and Label Demo</title>
  <script src="https://ajax.googleapis.com/ajax/libs/cesiumjs/1.105/Build/Cesium/Cesium.js"></script>
  <link 
    href="https://ajax.googleapis.com/ajax/libs/cesiumjs/1.105/Build/Cesium/Widgets/widgets.css"
    rel="stylesheet"
  />
</head>
<body>
  <div id="cesiumContainer"></div>
  <script>
    // Enable simultaneous requests.
    Cesium.RequestScheduler.requestsByServer["tile.googleapis.com:443"] = 18;

    // Create the viewer.
    const viewer = new Cesium.Viewer("cesiumContainer", {
      imageryProvider: false,
      baseLayerPicker: false,
      requestRenderMode: true,
      geocoder: false,
      globe: false,
    });

    // Add 3D Tiles tileset.
    const tileset = viewer.scene.primitives.add(
      new Cesium.Cesium3DTileset({
        url: "https://tile.googleapis.com/v1/3dtiles/root.json?key=YOUR_API_KEY",

        // This property is required to display attributions as required.
        showCreditsOnScreen: true,
      })
    );

    // Draws a circle at the position, and a line from the previous position.
    const drawPointAndLine = (position, prevPosition) => {
      viewer.entities.removeAll();
      if (prevPosition) {
        viewer.entities.add({
          polyline: {
            positions: [prevPosition, position],
            width: 3,
            material: Cesium.Color.WHITE,
            clampToGround: true,
            classificationType: Cesium.ClassificationType.CESIUM_3D_TILE,
          },
        });
      }
      viewer.entities.add({
        position: position,
        ellipsoid: {
          radii: new Cesium.Cartesian3(1, 1, 1),
          material: Cesium.Color.RED,
        },
      });
    };

    // Compute, draw, and display the position's height relative to the previous position.
    var prevPosition;
    const processHeights = (newPosition) => {
      drawPointAndLine(newPosition, prevPosition);

      const newHeight = Cesium.Cartographic.fromCartesian(newPosition).height;
      let labelText = "Current altitude (meters above sea level):\n\t" + newHeight;
      if (prevPosition) {
        const prevHeight =
          Cesium.Cartographic.fromCartesian(prevPosition).height;
        labelText += "\nHeight from previous point (meters):\n\t" + Math.abs(newHeight - prevHeight);
      }
      viewer.entities.add({
        position: newPosition,
        label: {
          text: labelText,
          disableDepthTestDistance: Number.POSITIVE_INFINITY,
          pixelOffset: new Cesium.Cartesian2(0, -10),
          showBackground: true,
          verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
        }
      });

      prevPosition = newPosition;
    };

    const handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
    handler.setInputAction(function (event) {
      const earthPosition = viewer.scene.pickPosition(event.position);
      if (Cesium.defined(earthPosition)) {
        processHeights(earthPosition);
      }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  </script>
</body>

कैमरा ऑर्बिट

सीज़ियम में, कैमरे को लोकप्रिय जगह के चारों ओर घुमाया जा सकता है. इससे, इमारतों के साथ होने वाली टकरावों से बचा जा सकता है. इसके अलावा, इमारतों के मूव होने पर उन्हें पारदर्शी बनाया जा सकता है.

सबसे पहले, कैमरे को किसी पॉइंट पर लॉक करें. इसके बाद, अपनी ऐसेट दिखाने के लिए कैमरा ऑर्बिट बनाएं. कैमरे के lookAtTransform फ़ंक्शन का इस्तेमाल, इवेंट लिसनर के साथ करके ऐसा किया जा सकता है. जैसा कि इस कोड सैंपल में बताया गया है.

// Lock the camera onto a point.
const center = Cesium.Cartesian3.fromRadians(
  2.4213211833389243,
  0.6171926869414084,
  3626.0426275055174
);

const transform = Cesium.Transforms.eastNorthUpToFixedFrame(center);

viewer.scene.camera.lookAtTransform(
  transform,
  new Cesium.HeadingPitchRange(0, -Math.PI / 8, 2900)
);

// Orbit around this point.
viewer.clock.onTick.addEventListener(function (clock) {
  viewer.scene.camera.rotateRight(0.005);
});

कैमरे को कंट्रोल करने के बारे में ज़्यादा जानकारी के लिए, कैमरा कंट्रोल करना लेख पढ़ें

सीज़ियम फ़ॉर अनरियल के साथ काम करें

3D Tiles API के साथ Cesium for Unreal प्लगिन का इस्तेमाल करने के लिए, नीचे दिया गया तरीका अपनाएं.

  1. Cesium for Unreal प्लगिन इंस्टॉल करें.

  2. एक नया Unreal प्रोजेक्ट बनाएं.

  3. Google Photoरियलिस्टिक 3D Tiles API से कनेक्ट करें.

    1. मेन्यू से सीज़ियम > सीज़ियम चुनकर, सीज़ियम विंडो खोलें.

    2. खाली 3D टाइल टाइलसेट चुनें.

    3. World Outliner में, इस Cesium3DTileset को चुनकर ब्यौरा पैनल खोलें.

    4. सोर्स को सेल्सियम आयन से से यूआरएल से में बदलें.

    5. यूआरएल को Google 3D टाइल के यूआरएल के तौर पर सेट करें.

    https://tile.googleapis.com/v1/3dtiles/root.json?key=YOUR_API_KEY
    
    1. एट्रिब्यूशन को ठीक से दिखाने के लिए, स्क्रीन पर क्रेडिट दिखाएं को चालू करें.
  4. यह दुनिया को लोड करता है. किसी भी LatLng में जाने के लिए, Outliner पैनल में CesiumGeoreference आइटम चुनें और फिर ब्यौरा पैनल में मूल अक्षांश/देशांतर/ऊंचाई में बदलाव करें.

Cesium for Unity के साथ काम करें

Unity के लिए Cesium के साथ फ़ोटोरियलिस्टिक टाइल का इस्तेमाल करने के लिए, यहां दिया गया तरीका अपनाएं.

  1. एक नया Unity प्रोजेक्ट बनाएं.

  2. पैकेज मैनेजर सेक्शन में एडिटर > प्रोजेक्ट सेटिंग की मदद से, एक नई स्कोप वाली रजिस्ट्री जोड़ें.

    • नाम: सीज़ियम

    • यूआरएल: https://unity.pkg.cesium.com

    • दायरा: com.cesium.unity

  3. Cesium for Unity पैकेज इंस्टॉल करें.

  4. Google Photoरियलिस्टिक 3D Tiles API से कनेक्ट करें.

    1. मेन्यू से सीज़ियम > सीज़ियम चुनकर, सीज़ियम विंडो खोलें.

    2. खाली 3D टाइल टाइलसेट पर क्लिक करें.

    3. बाईं ओर वाले पैनल में, सोर्स के तहत टाइलसेट सोर्स विकल्प में, यूआरएल से चुनें (सेज़ियम आयन से).

    4. यूआरएल को Google 3D टाइल के यूआरएल पर सेट करें.

    https://tile.googleapis.com/v1/3dtiles/root.json?key=YOUR_API_KEY
    
    1. एट्रिब्यूशन को ठीक से दिखाने के लिए, स्क्रीन पर क्रेडिट दिखाएं को चालू करें.
  5. यह दुनिया को लोड करता है. किसी भी LatLng में जाने के लिए, सीन हैरारकी में CesiumGeoreference आइटम चुनें और फिर इंस्पेक्टर में ऑरिजिन अक्षांश/देशांतर/ऊंचाई में बदलाव करें.

Deck.gl की मदद से काम करें

deck.gl, WebGL के साथ काम करता है. यह बेहतर परफ़ॉर्मेंस और बड़े पैमाने पर डेटा विज़ुअलाइज़ेशन के लिए, एक ओपन सोर्स JavaScript फ़्रेमवर्क है.

एट्रिब्यूशन

पक्का करें कि gltf asset की टाइल से copyright फ़ील्ड को एक्सट्रैक्ट करके, डेटा एट्रिब्यूशन को सही तरीके से दिखाया जा रहा है. इसके बाद, इसे रेंडर किए गए व्यू पर दिखाएं. ज़्यादा जानकारी के लिए, डिसप्ले डेटा एट्रिब्यूशन लेख पढ़ें.

Deck.gl रेंडरर के उदाहरण

आसान उदाहरण

नीचे दिए गए उदाहरण में, Deck.gl रेंडरर को शुरू किया गया है और फिर किसी जगह को 3D में लोड किया गया है. अपने कोड में, YOUR_API_KEY को अपनी असल एपीआई कुंजी से बदलना न भूलें.

<!DOCTYPE html>
<html>
 <head>
   <title>deck.gl Photorealistic 3D Tiles example</title>
   <script src="https://unpkg.com/deck.gl@latest/dist.min.js"></script>
   <style>
     body { margin: 0; padding: 0;}
     #map { position: absolute; top: 0;bottom: 0;width: 100%;}
     #credits { position: absolute; bottom: 0; right: 0; padding: 2px; font-size: 15px; color: white;
        text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;}
   </style>
 </head>

 <body>
   <div id="map"></div>
   <div id="credits"></div>
   <script>
     const GOOGLE_API_KEY = YOUR_API_KEY;
     const TILESET_URL = `https://tile.googleapis.com/v1/3dtiles/root.json`;
     const creditsElement = document.getElementById('credits');
     new deck.DeckGL({
       container: 'map',
       initialViewState: {
         latitude: 50.0890,
         longitude: 14.4196,
         zoom: 16,
         bearing: 90,
         pitch: 60,
         height: 200
       },
       controller: {minZoom: 8},
       layers: [
         new deck.Tile3DLayer({
           id: 'google-3d-tiles',
           data: TILESET_URL,
           loadOptions: {
            fetch: {
              headers: {
                'X-GOOG-API-KEY': GOOGLE_API_KEY
              }
            }
          },
           onTilesetLoad: tileset3d => {
             tileset3d.options.onTraversalComplete = selectedTiles => {
               const credits = new Set();
               selectedTiles.forEach(tile => {
                 const {copyright} = tile.content.gltf.asset;
                 copyright.split(';').forEach(credits.add, credits);
                 creditsElement.innerHTML = [...credits].join('; ');
               });
               return selectedTiles;
             }
           }
         })
       ]
     });
   </script>
 </body>
</html>

Google Photoरियलिस्टिक 3D टाइल के ऊपर 2D लेयर विज़ुअलाइज़ करें

डेक.gl TerrainExtension इसके बजाय, 3D प्लैटफ़ॉर्म पर 2D डेटा रेंडर करता है. उदाहरण के लिए, आप फ़ोटोरियलिस्टिक 3D टाइल ज्यामिति के ऊपर किसी इमारत के फ़ुटप्रिंट का GeoJSON को लपेट सकते हैं.

नीचे दिए गए उदाहरण में, इमारतों की एक लेयर को फ़ोटोरियलिस्टिक 3D टाइल्स सरफ़ेस के हिसाब से बनाए गए पॉलीगॉन से विज़ुअलाइज़ किया गया है.

<!DOCTYPE html>
<html>
 <head>
   <title>Google 3D tiles example</title>
   <script src="https://unpkg.com/deck.gl@latest/dist.min.js"></script>
   <style>
     body { margin: 0; padding: 0;}
     #map { position: absolute; top: 0;bottom: 0;width: 100%;}
     #credits { position: absolute; bottom: 0; right: 0; padding: 2px; font-size: 15px; color: white;
        text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;}
   </style>
 </head>

 <body>
   <div id="map"></div>
   <div id="credits"></div>
   <script>
     const GOOGLE_API_KEY = YOUR_API_KEY;
     const TILESET_URL = `https://tile.googleapis.com/v1/3dtiles/root.json`;
     const BUILDINGS_URL = 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/examples/google-3d-tiles/buildings.geojson'
     const creditsElement = document.getElementById('credits');
     const deckgl = new deck.DeckGL({
       container: 'map',
       initialViewState: {
         latitude: 50.0890,
         longitude: 14.4196,
         zoom: 16,
         bearing: 90,
         pitch: 60,
         height: 200
       },
       controller: true,
       layers: [
         new deck.Tile3DLayer({
           id: 'google-3d-tiles',
           data: TILESET_URL,
           loadOptions: {
            fetch: {
              headers: {
                'X-GOOG-API-KEY': GOOGLE_API_KEY
              }
            }
          },
          onTilesetLoad: tileset3d => {
             tileset3d.options.onTraversalComplete = selectedTiles => {
               const credits = new Set();
               selectedTiles.forEach(tile => {
                 const {copyright} = tile.content.gltf.asset;
                 copyright.split(';').forEach(credits.add, credits);
                 creditsElement.innerHTML = [...credits].join('; ');
               });
               return selectedTiles;
             }
           },
           operation: 'terrain+draw'
         }),
         new deck.GeoJsonLayer({
           id: 'buildings',
           // This dataset is created by CARTO, using other Open Datasets available. More info at: https://3dtiles.carto.com/#about.
           data: 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/examples/google-3d-tiles/buildings.geojson',
           stroked: false,
           filled: true,
           getFillColor: ({properties}) => {
             const {tpp} = properties;
             // quantiles break
             if (tpp < 0.6249)
               return [254, 246, 181]
             else if (tpp < 0.6780)
               return [255, 194, 133]
             else if (tpp < 0.8594)
               return [250, 138, 118]
             return [225, 83, 131]
           },
           opacity: 0.2,
           extensions: [new deck._TerrainExtension()]
         })
       ]
     });
   </script>
 </body>
</html>