Giter VIP home page Giter VIP logo

Comments (7)

felixpalmer avatar felixpalmer commented on May 18, 2024

Could you share a jsfiddle or some other sort of live example?

from procedural-gl-react.

cyango avatar cyango commented on May 18, 2024

This is the current ProceduralMap object I get from react component
image

As you can see there are lots of functions missing like onOverlayAdded...etc.

I can add a Basic Line, but can't add marker and text marker or image markers, following the same logic on the documentation.

from procedural-gl-react.

felixpalmer avatar felixpalmer commented on May 18, 2024

I've updated the example repo to show adding an overlay and responding to clicks on features. It works fine for me with an image marker.

The relevant part is here:

export default class Example extends React.Component {
  constructor( props ) {
    super( props );
    this.map = React.createRef();
  }

  componentDidMount() {
    // Once map is initialized add an overlay
    const map = this.map.current;
    map.addOverlay( overlay );
  }

  render() {
    return React.createElement( ProceduralMap, {
      ref: this.map,
      datasource,

      // Configure UI elements to show
      compassVisible: true,

      // Configure initial map location
      displayLocation: {
        latitude: 47.25,
        longitude: 13.56
      },

      // Define callbacks
      onFeatureClicked: id => {
        // The id passed here is defined in the overlay
        const map = this.map.current;

        // Simply focus on the feature when clicked
        map.focusOnFeature( id );
      }
    } );
  }
} 

As to your other point, the onOverlayAdded etc functions are missing because you haven't defined them. They are callbacks that you define on the map component. If they are not defined then it is expected that they will not be present and thus they won't get called. Again, see the above example to see how to define these.

from procedural-gl-react.

cyango avatar cyango commented on May 18, 2024

Hum...strange, I'm using React with hooks. I'm unable to get the same results:

import overlay from "overlay.js"
.
.

const component =()=>{
.
.
.
const NASADEM_APIKEY = "xxxxxxxxxxxxxxx";
  const MAPTILER_APIKEY = "xxxxxxxxxxx";

  const datasource = {
    elevation: {
      apiKey: NASADEM_APIKEY,
    },
    imagery: {
      apiKey: MAPTILER_APIKEY,
      urlFormat: "https://api.maptiler.com/tiles/satellite/{z}/{x}/{y}.jpg?key={apiKey}",
      attribution:
        "<a href="https://www.maptiler.com/copyright/">Maptiler</a> <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors",
    },
  };

  const aref = createRef();

  useEffect(() => {
    if (aref.current) {
      aref.current.addOverlay(overlay);

      aref.current.onOverlayAdded = function (name) {
        console.log("Overlay added:", name);
      };
    }
  }, []);

  return (
    <div>
      <ProceduralMap
        ref={aref}
        datasource={datasource}
        compassVisible={false}
        displayLocation={{
          latitude: 47.25,
          longitude: 13.56,
        }}
      />
    </div>
  );
};

I can see the maps, but no added custom overlay. This same approach works with the basic line however.

from procedural-gl-react.

felixpalmer avatar felixpalmer commented on May 18, 2024

Without seeing what you have in overlay.js I can't help debug this. That why it would be useful to be able to take a look at a live example. My guess is that there is something wrong with the overlay you've defined

from procedural-gl-react.

cyango avatar cyango commented on May 18, 2024

Sorry, I'm using the exact same overlay.js file you have here: https://github.com/felixpalmer/procedural-gl-react-example/blob/main/overlay.js

from procedural-gl-react.

cyango avatar cyango commented on May 18, 2024

Ok, so I found a solution, but I think this should be included on documentation or the component itself.

The font awesome css was missing on my index.html

   <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">

from procedural-gl-react.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.