Is there a way to incorporate a unique HTML map marker onto a Nokia HERE map?

After reviewing the Nokia maps documentation, it appears that custom markers can be added using a vector-based drawing API. More information can be found at:

Although you can create custom graphic markers based on a sprite as demonstrated here:

Alternatively, their own markers can be utilized by following this guide:

However, is there a way to input an HTML snippet to position on the map similar to a map marker? This functionality would allow for complete control over the map marker using HTML/CSS, eliminating the need to replicate styling in custom JS. I have existing map markers styled in HTML/CSS and would prefer not to duplicate that effort.

Answer №1

If your goal is to incorporate styled, injected HTML into your project, one approach could be to develop a set of custom components (one for each marker) and link them to the map. Each component would then inject a block-level element that can be customized using CSS.

This method shares similarities with the straightforward GroundOverlay component I previously utilized before discovering the ImgTileProvider class within the API. The GroundOverlay component adds an <IMG> element which resizes based on the zoomLevel, although you may choose to omit this feature. Despite this, it effectively anchors a piece of HTML to a specific location on the map.

For most basic applications, I tend to prefer utilizing Markers (with or without custom icons) or Infobubbles. These options provide a more responsive and standard user interface without cluttering the map.

function extend(B, A) {
  function I() {}
  I.prototype = A.prototype;
  B.prototype = new I();
  B.prototype.constructor = B;
}

function GroundOverlay(url, boundingBox) {
  nokia.maps.map.component.Component.call(this);
  this.init(url, boundingBox);
}

extend(GroundOverlay,
    nokia.maps.map.component.Component);


GroundOverlay.prototype.init = function (url, boundingBox) {
  var that = this;
  that.overlayDiv  = document.createElement('div');
  that.overlayDiv.style.position = 'absolute';
  that.overlayDiv.style.cursor = 'default';
  that.overlayImage = document.createElement('img');
  that.overlayImage.id = 'groundoverlay';
  that.overlayDiv.appendChild(that.overlayImage);

  that.set('url', url);
  that.set('boundingBox', boundingBox);
  that.set('visible', true);
  that.set('opacity', 1);

  that.addOverlay = function () {
    var isVisible = that.get('visible'),
      bbox,
      topLeft,
      bottomRight;

    if (isVisible === false) {
      that.overlayDiv.style.display = 'none';
    } else {
      bbox = that.get('boundingBox');
      topLeft = that.map.geoToPixel(bbox.topLeft);
      bottomRight = that.map.geoToPixel(bbox.bottomRight);
      that.overlayDiv.style.display = 'block';
      that.overlayDiv.style.left = topLeft.x + 'px';
      that.overlayDiv.style.top = topLeft.y + 'px';
      that.overlayDiv.style.width = (bottomRight.x - topLeft.x) + 'px';
      that.overlayDiv.style.height = (bottomRight.y - topLeft.y) + 'px';
      that.overlayImage.src = that.get('url');
      that.overlayImage.style.width = (bottomRight.x - topLeft.x) + 'px';
      that.overlayImage.style.height = (bottomRight.y - topLeft.y) + 'px';
      that.overlayImage.style.opacity = that.get('opacity');
    }
  };

  that.addObserver('opacity', that.addOverlay);
  that.addObserver('visible', that.addOverlay);
  that.addObserver('url', that.addOverlay);
  that.addObserver('boundingBox', that.addOverlay);

  that.eventHandlers = {
    dragListener : function (evt) {
      var newGeo = that.map.pixelToGeo(
        that.map.width / 2 - evt.deltaX,
        that.map.height / 2 - evt.deltaY
      );
      that.map.set('center', newGeo);
      evt.stopPropagation();
    },
    dblClickListener :  function (evt) {
      evt.target = this.parentNode.parentNode;
      that.map.dispatch(evt);
    },
    mouseWheelListener :  function (evt) {
      evt.target = this.parentNode.parentNode;
      that.map.dispatch(evt);
    }
  };
};


GroundOverlay.prototype.attach = function (map) {
  this.map = map;
  var controls = map.getUIContainer().firstChild,
    child = controls.firstChild;
  controls.insertBefore(this.overlayDiv, child);

  map.addObserver('center', this.addOverlay);
  map.addObserver('zoomLevel', this.addOverlay);

  if (!this.evtTarget) {
    this.evtTarget =  nokia.maps.dom.EventTarget(
      document.getElementById('groundoverlay')
    ).enableDrag();
    this.evtTarget.addListener('drag', this.eventHandlers.dragListener);
    this.evtTarget.addListener('dblclick', this.eventHandlers.dblClickListener);
    this.evtTarget.addListener('mousewheel', this.eventHandlers.mouseWheelListener);
    this.addOverlay();
  }
};

GroundOverlay.prototype.detach = function (map) {
  this.map = null;
  map.removeObserver('center', this.addOverlay);
  map.removeObserver('zoomLevel', this.addOverlay);
  this.overlayDiv.parentNode.removeChild(this.overlayDiv);
};

GroundOverlay.prototype.getId = function () {
  return 'GroundOverlay';
};

GroundOverlay.prototype.getVersion = function () {
  return '1.0.0';
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Alignment of labels in Bootstrap for various form groups with error messages and required fields

How can I align a horizontal text box in the same row even though the label is on a different line? <div class="row"> <div class="col-sm-12 col-lg-4"> <div class="form-group"> ...

Employing v-btn for navigating to a different route depending on whether a specific condition is satisfied

Is there a way to prevent this button from redirecting to the specified URL? I want to implement a validation check in my method, and if it fails, I need to stop this button from performing any action. Any suggestions or assistance would be highly apprec ...

Eliminating unnecessary white space while utilizing the first-letter CSS property

Is there a way to remove the extra whitespace added under the first line when making the first letter of a paragraph bigger than the rest of the text? I already tried adjusting padding and margins on p::first-line without success. p{ line-height: 1.4; } p ...

Say goodbye to colors and different design elements as you make the switch to Angular Material 1.1.1

Last week, I made the switch in my project from Angular Material 1.0.8 to Angular Material 1.1.1. However, after completing this update, I encountered some styling issues, such as: The hues feature is not functioning properly. For instance, the use of m ...

Javascript variable scope

let preGameRequest = new XMLHttpRequest(); let preGameData; preGameRequest.open("GET", "/matches/live.json"); preGameRequest.onload = function() { preGameData = JSON.parse(preGameRequest.responseText); } preGameRequest.send(); console.log(preGameData) ...

The parent class failed to implement the border radius as intended

Recently, I created an HTML table using Bootstrap V5 on my website. .reasonCode-table th, .reasonCode-table td { padding: 8px; border: 2px solid #7a7878; border-radius: 6px; } .reasonCode-table__title { text-align: center; } .rea ...

How can you use Firestore to filter documents based on their presence in another collection?

For instance, I am looking to retrieve all users who are members of a certain "space". Here is a simplified Firestore rule example: match /users/{userId} { allow read: if exists(/databases/$(database)/documents/spaces/SPACEID/members/$(userId)); } Java ...

Adjust the component's onClick property in Next.js

Looking for guidance on how to update a property value of a component in Next.js. I have been using the Material-UI library for styling. Encountering an issue when attempting to modify the 'open' property of a drawer component, as it constantly ...

Prevent an element from being animated by CSS

Currently tackling a frustrating bug while working on a component. The issue arises when clicking on a div that opens a menu, contained within a React component which is nested inside another. Below is the CSS styling: const FilterBox = styled("div")` ...

Library for converting HTML to PowerPoint presentations using the .Net framework

I have developed a web-based reporting engine that generates reports in HTML/CSS format. For exporting to PDF, I am using Essential Objects' HTMLtoPDF library and for exporting to Excel, EPPlus. Despite this, I am facing difficulty finding a .NET libr ...

Why is the function not being invoked in Ext JS?

Ext.define('iTell.view.MarketView', { extend: 'Ext.Container', xtype: 'marketview', config: { scrollable: false, layout: 'fit', items: [ { xtype: &apos ...

The query datetime picker is unable to retrieve the date when called in a different function

Could you please clarify why I am receiving an "undefined" value in the second alert of the loadchart function call? What is causing the error here? I am encountering an issue with fetching dates from a date timepicker while using Bootstrap. Below is my ...

Displaying an HTML string on a webpage

I am developing a user dashboard using Django for a Python-based web application. This web application generates emails, and the HTML content of these emails is stored in a file (and potentially in a database table as well). As part of the dashboard's ...

Customize CSS on a specific webpage to overwrite the default values set by the

We recently had a website redesigned by a company that also manages and hosts it, along with providing our CRM system. The issue at hand is that they include a backlink in the footer that I am unable to modify since it's not part of the page until the ...

What are some techniques for utilizing CSS with form.ImageField in Django?

When attempting to apply CSS to form.ImageField in Django similar to CharField, I encountered an error. File "/Users/hogehoge/Desktop/hoge/hoge/forms.py", line 42, in PostForm photo = forms.ImageField(label='Image', validators=[fi ...

What are the potential causes of an asynchronous error in a WebGLRenderingContext?

While running an animation loop, I encountered a peculiar error message that reads... GL ERROR :GL_INVALID_OPERATION : glDrawElements: Source and destination textures of the draw are the same. This error seems to occur randomly after 2 or 3 animation fr ...

Python allows for the sending of HTML content in the body of an email

Is there a way to show the content of an HTML file in an email body using Python, without having to manually copy and paste the HTML code into the script? ...

What is the information stored inside the div element?

How can I extract the contents of a div using bs4? >>> Doc <div class="document"> <p>Text.</p> <p>More text</p> </div> >>> type(Doc) bs4.element.Tag I am looking to retrieve: <p>Text.</p> ...

Tips for inserting information into HTML components in JSP

Hey everyone, I'm diving into JSP for the first time and I'm trying to wrap my head around how to display data from an ArrayList in my HTML. Can someone help me out? I'm thinking of doing something like this: <article> <p>< ...

Determining the maximum value while omitting a specific value within a property of a nested object

I'm struggling with the specific iteration logic required here. The object structure is somewhat complex: var answers = { cat1: { q1: { "question": "Why?", "answer": "No", "points": 6 }, q2: { "questi ...