NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I am displaying two Marker dynamically on OSM 5. The data saved to the array is (longiutde, latitude, car name) The Marker are being correctly displayed with a Popup window for each one. The Popup windows should contain the name of each car, but the problem here is that i am ALWAYS getting the second name of the car displayed on both Popups which is wrong. I am really stucked i have tried everything i knew.

/ open street map newest version / var map = new ol.Map({ target: 'map', // the div id layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }) ], view: new ol.View({ center: ol.proj.fromLonLat([4.35247, 52.520008]), zoom: 6, minZoom: 3 }) }); for(var i=0; i < arrayPos.length; i++) { var long = arrayPos[i][0] var lat = arrayPos[i][1]; var vehName = arrayPos[i][2]; // add a marker to the map var layer = new ol.layer.Vector({ source: new ol.source.Vector({ features: [ new ol.Feature({ geometry: new ol.geom.Point(ol.proj.fromLonLat([long, lat])) })] }) }); layer.setStyle(new{ image: new{ src: '', // scale: 0.4 // set the size of the vehicle on the map }) })); map.addLayer(layer); //initialize the popup var container = document.getElementById('popup'); var content = document.getElementById('popup-content'); var overlay = new ol.Overlay({ element: container, autoPan: true, autoPanAnimation: { duration: 250 } }); map.addOverlay(overlay); console.log(vehName); // two different car names are shown in the console //display the pop with on mouse over event map.on('pointermove', function (event) {
if (map.hasFeatureAtPixel(event.pixel) === true) {
var coordinate = event.coordinate; //simple text written in the popup, values are just of the second index content.innerHTML = 'Im a vehicle:
'+vehName; //just the second one is getting displayed overlay.setPosition(coordinate); } else { overlay.setPosition(undefined); } }); }
Any help is really appreciated!!

asked 19 Oct '20, 10:59

unkown53's gravatar image

accept rate: 0%

edited 20 Oct '20, 09:20


Our wiki doesn't have anything for "OSM 5". What are you actually using?

(19 Oct '20, 23:00) InsertUser

I am using the latest version of OSM

(19 Oct '20, 23:05) unkown53

OSM is just a database of raw data. What you're probably using is some other software that uses OSM data to reach some goal.

Based on the code you posted, my guess is that you're using the OpenLayers library to display a map on a website somewhere. The latest version of OpenLayers is 6.4.3, though, so maybe you're using some other software?

(20 Oct '20, 00:33) alester

@unkown53 can you link to what you mean by "OSM"? Perhaps show where you downloaded it from?

(20 Oct '20, 00:40) SomeoneElse ♦

Yes, I am using Openlayers. I just used OSM for the abbreviation of OpenStreetMap. But could anyone of you knew what i am messing up?. I am really stucked there :(

(20 Oct '20, 09:08) unkown53

OpenLayers is a JavaScript library that can be used to display all sorts of map data on a website. OpenStreetMap maps - among others - can be used as background but other than that OpenLayers has nothing to do with OSM. Possibly someone here might be able to give you an answer but if not you might be better off to direct your question to a more OpenLayers oriented forum.

(20 Oct '20, 09:26) TZorn
showing 5 of 6 show 1 more comments

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 19 Oct '20, 10:59

question was seen: 1,922 times

last updated: 20 Oct '20, 09:26

NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum