Question

I'm using open street maps and open street layers and I am trying to create a map of tickets (markers) where a technician will go to the marker and do work and move to the next. I am able to create the marker and have an onclick function that fires. What I can't figure out is how to pull out information from the marker itself. I am creating the markers like..

addPinViaLongLat: function(icon, long, lat, popupString) { 
   var icon_marker = new OpenLayers.Icon(icon, null, null);
   var marker = new OpenLayers.Marker(new OpenLayers.LonLat(long, lat).transform(rapidSchedulingMap.coor_from, rapidSchedulingMap.coor_to), icon_marker);
   var popup;

   marker.events.register('mouseover', marker, function(evt) {
     popup = new OpenLayers.Popup.FramedCloud("Popup",
            new OpenLayers.LonLat(long, lat).transform(rapidSchedulingMap.coor_from, rapidSchedulingMap.coor_to),
            null,
            popupString,
            null,
            false);
       rapidSchedulingMap.map.addPopup(popup);
   });
   marker.events.register('mouseout', marker, function(evt) {
       popup.hide();
   });
   rapidSchedulingMap.bindClick(marker);
   rapidSchedulingMap.layer.addMarker(marker);
},

I am wondering if there is a way to add data so on the click I can reference it like marker.ticketNumber. I haven't seen anything like this from googling for it so I turned here. Hope someone has some ideas.

EDIT: I found how to remove a specific marker in openlayer which shows the ability to do marker.XXXX and then push the markers into an array to keep track of them all.

Was it helpful?

Solution

I found the solution...

var marker = new OpenLayers.Marker(new OpenLayers.LonLat(long, lat).transform(rapidSchedulingMap.coor_from, rapidSchedulingMap.coor_to), icon_marker);
marker.data = data;

Then when I click on the marker I am able to do marker.data and pull the object that i stored for each marker. No need to do an extra array to keep track of any values.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top