0
import "./style.css";
import * as THREE from "three";
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
import Globe from "globe.gl";

fetch("/geo.json", { mode: "cors" })
  .then((res) => res.json())
  .then((geoJson) => {
    fetch("/geoq.json", { mode: "cors" })
      .then((res) => res.json())
      .then((geoPJson) => {
        const geoJsonData = geoJson.features.filter((d) => d.geometry != null);
        const countriesArr = geoJsonData.filter(
          (d) => d.properties.ISO_A2 !== "AQ",
        );

        const globe = new Globe(document.querySelector("#showGlobe"))
          .globeImageUrl("dayEarth.jpg")
          .showAtmosphere(true)
          .atmosphereColor("lightskyblue")
          .polygonsData(countriesArr)
          .polygonAltitude(0.04)
          .polygonStrokeColor("red")
          .polygonSideColor(() => "rgba(0, 100, 0, 0.15)")
          .polygonStrokeColor(() => "#111")
          .onPolygonHover((hoverD, lastHoverD) => {
            if (hoverD !== lastHoverD) {
              globe
                // .polygonAltitude((d) => (d === hoverD ? 0.08 : 0.04))
                .polygonCapColor((d) =>
                  d === hoverD ? "steelblue" : "#ffaa00",
                );
            }
          })
          .polygonsTransitionDuration(250)
          .onPolygonClick((polygon) => {
            console.log(polygon);
          });

        function drawProvincesBorders() {
          const newArr = [];
          console.log(geoPJson.features)
          for (let feature of geoPJson.features) {
            if (feature.properties.iso_a2 == "TR") {
              newArr.push(feature);
              console.log(feature)
            }
          }
          const result = [...countriesArr, ...newArr];
          globe.polygonsData([]);
          globe.polygonsData(result);


        }
        drawProvincesBorders();




      });
  });

I store country info in geo.json, and store provinces info in geoq.json. Countries work perfectly: (https://i.sstatic.net/FR7mbzVo.png)

However, when I add provinces borders for a country, whole world becomes interactive: (https://i.sstatic.net/gZmp74Iz.png)

I think it is about coordinates in my geoq.json file. since I am not competent about coordinates, I can't say what causes this bug. If you have an idea please don't hesitate to share with me, because I'm totally stuck.

1
  • Hi, please, what behavior are you expecting and what behavior are you currently getting? Commented Feb 25 at 17:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.