ajax maps infobox - editing possible ?

This forum deals with any kind of web based client technology, whether it is the well known java script based Ajax servlet or the upcoming approaches such as Leaflet, OpenLayers and so on.
Post Reply
nemec
Posts: 17
Joined: Tue May 02, 2017 10:05 am

ajax maps infobox - editing possible ?

Post by nemec »

Hello !

i use a infobox for defined points

var infobox = new com.ptvag.webcomponent.map.vector.InfoBox();
infobox.set({x:4303250,y:5486500,text:"Mc Donalds"});
vectorLayer.addElement(infobox);

is it possible to edit this Text on the map ?

Regards
Andreas
AndreasJunghans
Posts: 13
Joined: Tue May 13, 2014 3:28 pm

Re: ajax maps infobox - editing possible ?

Post by AndreasJunghans »

Hi Andreas,

the text in an InfoBox is HTML, so you can put anything there. Here's a small example that makes the text editable (not pretty and only tested in Chrome, but you should get the idea):

Code: Select all

var infobox = new com.ptvag.webcomponent.map.vector.InfoBox();
var myText = "Test";
function setContents() {
  var textSpan = document.createElement("span");
  textSpan.id = "textSpan";
  textSpan.appendChild(document.createTextNode(myText));
  infobox.setText(textSpan.outerHTML);
  setTimeout(function() {
    textSpan = document.getElementById("textSpan");
    textSpan.onclick = textClicked;
  }, 0);
}
function textClicked() {
  var input = document.createElement("input");
  input.id = "textInput";
  infobox.setText(input.outerHTML);
  setTimeout(function() {
    input = document.getElementById("textInput");
    input.value = myText;
    input.onkeydown = textKeyDown;
    input.focus();
  }, 0);
};
function textKeyDown(e) {
  if (!e) e = window.event;
  if (e.keyCode == 13) {
    if (this.value.trim() != "") {
      myText = this.value;
    }
    setContents();
  }
};
infobox.set({x:4303250,y:5486500});
setContents();
vectorLayer.addElement(infobox);
Regards,

Andreas (yes, me too :-))
nemec
Posts: 17
Joined: Tue May 02, 2017 10:05 am

Re: ajax maps infobox - editing possible ?

Post by nemec »

Thank you very much / Danke 1000 fach !

it runs!!!

Regards /Grüße aus Wien
Andreas Nemec
Post Reply