1

I try to build a globe with markers (like the markers on google maps) with HERE and harp.gl. These markers are SVG-Images and need to be loaded from their file. They also need to be clickable with some metadata attached like an ID.

So my questions are:

  • what is the best way to display these markers?
  • how can I make them clickable? (raycasting?)
  • is there a way to attach some metadata?

thanks in advance!

Edit: To clarify, the Markers are SVG-Images stored in SVG-Files which need to be loaded and displayed as Markers.

The Data is provided by an API and therefore I tried adding it as Point of it's own like the Cube-Example and also tried to translate it to GeoJSON and FeatureSets:

    const geojsonPoints: {type:  "FeatureCollection", features: Feature[]} = {  type: "FeatureCollection",
        features: [
        ]
    };
    for(let i = 0; i < locationdata.length; i++) {
        geojsonPoints.features.push({
            type: "Feature",
            id: i.toString(),
            geometry: {
                type: "Point",
                coordinates: [locationdata[i]["lonlat"][1], locationdata[i]["lonlat"][0]]
            },
            properties: locationdata[i]
        })
    }
    const features: MapViewFeature[] = [];
    for(let i = 0; i < locationdata.length; i++) {
        features.push(new MapViewPointFeature([locationdata[i]["lonlat"][1], locationdata[i]["lonlat"][0]], locationdata[i]))
    }

When I try adding a GeoJSON-Layer I get an error that the decoder.min.js couldn't be loaded but I configured it like that:

const mapView = new MapView({
        canvas: this.canvas,
        projection: sphereProjection,
        theme: {
            extends: pluginpath + "/js/harp.gl-example/dist/resources/berlin_tilezen_base_globe.json",
            styles: {
                geojson: this.getStyleSet()
            }
        },
        decoderUrl: pluginpath + "/js/harp.gl-example/dist/decoder.bundle.js"
    });

pluginpath is a variable containing prefix since the js-folder isn't directly in the root-directory like in all the examples.

To sum it all up: I need to display the data provided by the API as markers. The markers should be the SVG-Images mentioned earlier and these markers should be clickable.

Edit 2: I tried modifying this example to display the SVG-Markers. The first step worked where I just displayed the cubes from the example at the needed locations, but I couldn't replace the cube with markers. I used these two documentations from three.js website but they didn't work for me:

I didn't get any error the SVGs just didn't show up.

Zbigniew Zagórski
  • 1,921
  • 1
  • 13
  • 23
pheuberger
  • 11
  • 2

2 Answers2

1

Just a quick note that in general, it's better to ask one question at a time. I'm going to focus on your first one about adding markers. Our tutorial has a section on adding markers, https://developer.here.com/tutorials/harpgl/#add-data. In the example, it assumes GeoJSON data. You didn't mention what kind of file you had so I don't know if it's GeoJSON or not.

I'd say - begin by describing what kind of file you have, how the data looks. Then look at the example I linked to in terms of adding markers. Then - share with us what you tried.

Raymond Camden
  • 10,661
  • 3
  • 34
  • 68
  • I edited my question, hope this clarifies my question – pheuberger Jul 28 '20 at 08:24
  • You mentioned you tried to translate your data into GeoJSON, had an issue with the decoder file but fixed it, but didn't say what happened with the GeoJSON - did it load right? I'd try to get basic markers working first, then we can get your custom SVG markers working. (Hopefully.) – Raymond Camden Jul 28 '20 at 13:56
  • I fixed it for the OmvDataSource loading tiles using the here-API, but the OmvDataSource which should load GeoJSON using the GeoJSON-provider always fails with the following error: `MapView: Failed to connect to datasource my_data: Error during worker initialization: Uncaught SyntaxError: Unexpected token '<' in http://globetest.local/decoder.bundle.js/:1` The issue is that it seems to ignore the `decoderUrl: pluginpath + "/js/harp.gl-example/dist/decoder.bundle.js"` configured for the MapView and uses the wrong URL. Everything else is exactly like in the example you mentioned. – pheuberger Jul 29 '20 at 17:09
  • Yo mentioned you weren't using the JS files directly in root like the examples, does moving it there work? If so that may be a temporary solution, and I can file a bug report on it ignoring the path. – Raymond Camden Jul 29 '20 at 21:22
  • I can confirm the geojson-layer works if the harp-lib is placed in root, but this isn't a solution or me since I can't do that in that project. Nevertheless, I'm going to update the question again so please let us discuss the issue of placing markers again. – pheuberger Aug 06 '20 at 06:06
  • Thank you - I was just trying to confirm because it sounds like you've found a bug. – Raymond Camden Aug 06 '20 at 14:31
  • So I think what you would need to do is - create a reproduceable case. Ie don't use an API, just some static data. ANd then file this on the harp.gl repo: https://github.com/heremaps/harp.gl. As I said, I think you've got a real bug w/ plugin path identified. Sharing this could get it fixed. – Raymond Camden Aug 06 '20 at 14:36
  • Let's make a deal, I will create a reproducible case and then file a bug **IF** you can provide me a working example of Vector-images used as markers, which was my original question. – pheuberger Aug 12 '20 at 06:17
  • I can try - sure - but I wasn't sure if it was still an issue because of the other thing you mentioned. That's why I suggested on top that it's better to stick one issue at a time. So it sounds like we have two potential issues here. I'm happy to go ahead and file it for you in case I don't have a chance to get a working demo of the *second* issue. – Raymond Camden Aug 12 '20 at 13:43
  • I would be glad to share the information about the bug, but please provide me some way of displaying SVG-Images as markers first. – pheuberger Aug 18 '20 at 06:34
  • Hi @pheuberger, loading SVG directly is not supported due to security constraints. What you could do instead is load a base64 encoded SVG. I will post some code snippets in a separate answer. – Nino Aug 18 '20 at 17:09
  • Regarding the decoder url issue: There are actually two components that need the decoder bundle: 1. The OmvDataSource for decoding and styling data in the web-worker 2. The GeoJsonDataProvider for tiling the GeoJSON on the fly in the web-worker See: https://www.harp.gl/docs/master/doc/interfaces/harp_vectortile_datasource.geojsondataprovideroptions-1.html#workertilerurl – Nino Aug 18 '20 at 17:21
  • 1
    I created a pull request in the harp.gl repo that adds a marker example with custom icons: https://github.com/heremaps/harp.gl/pull/1780 – Nino Aug 18 '20 at 18:46
1

Loading SVGs directly is not supported but you could use base64 encoded svg images, e.g.:

const imageString =
"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDIyLjEuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHdpZHRoPSI0OHB4IiBoZWlnaHQ9IjQ4cHgiIHZlcnNpb249IjEuMSIgaWQ9Imx1aS1pY29uLWRlc3RpbmF0aW9ucGluLW9uZGFyay1zb2xpZC1sYXJnZSIKCSB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCIgdmlld0JveD0iMCAwIDQ4IDQ4IgoJIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDQ4IDQ4IiB4bWw6c3BhY2U9InByZXNlcnZlIj4KPGc+Cgk8ZyBpZD0ibHVpLWljb24tZGVzdGluYXRpb25waW4tb25kYXJrLXNvbGlkLWxhcmdlLWJvdW5kaW5nLWJveCIgb3BhY2l0eT0iMCI+CgkJPHBhdGggZmlsbD0iI2ZmZmZmZiIgZD0iTTQ3LDF2NDZIMVYxSDQ3IE00OCwwSDB2NDhoNDhWMEw0OCwweiIvPgoJPC9nPgoJPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGZpbGw9IiNmZmZmZmYiIGQ9Ik0yNCwyQzEzLjg3MDgsMiw1LjY2NjcsMTAuMTU4NCw1LjY2NjcsMjAuMjIzMwoJCWMwLDUuMDMyNSwyLjA1MzMsOS41ODg0LDUuMzcxNywxMi44ODgzTDI0LDQ2bDEyLjk2MTctMTIuODg4M2MzLjMxODMtMy4zLDUuMzcxNy03Ljg1NTgsNS4zNzE3LTEyLjg4ODMKCQlDNDIuMzMzMywxMC4xNTg0LDM0LjEyOTIsMiwyNCwyeiBNMjQsMjVjLTIuNzY1LDAtNS0yLjIzNS01LTVzMi4yMzUtNSw1LTVzNSwyLjIzNSw1LDVTMjYuNzY1LDI1LDI0LDI1eiIvPgo8L2c+Cjwvc3ZnPgo=";

This image can then be used in the style definition like this:

            styles: {
                geojson: [
                    {
                        when: ["==", ["geometry-type"], "Point"],
                        technique: "labeled-icon",
                        attr: {
                            text: ["get", "text"],
                            textMayOverlap: true,
                            size: 14,
                            imageTexture: "custom-icon",
                            screenHeight: 32,
                            iconScale: 0.5,
                            distanceScale: 1,
                            iconYOffset: 20
                        }
                    }
                ]
            },
            images: {
                "custom-icon": {
                    url: imageString,
                    preload: true
                }
            },
            imageTextures: [
                {
                    name: "custom-icon",
                    image: "custom-icon"
                }
            ]
Nino
  • 429
  • 2
  • 8