Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to get the default marker NOT to show, but it's coming up WITH the icon that I want, so I have a marker and icon like this:

enter image description here

I'm getting my data from a OSM nomination search result.

if (response) {
        var mArray = [];
        for (var i = 0; i < response.length; i++) {
            var result = response[i];
            var s = result.display_name;
            var ex = result.extratags;
            var lk = ex.website;
            var ph = ex.phone;
            var hr = ex.opening_hours;
            var poly = result.geojson;
            if (hr) {
                var hours = hr.replace(/\;/g, '<br/>');
            }
            var arr = s.split(', ');
            var dd = s.substring(0, s.lastIndexOf(", "));
            var cc = dd.substring(dd.indexOf(",") + 1);
            var rIcon = result.icon;
            var myIcon;
            if (rIcon) {
                myIcon = new L.Icon({
                    iconSize: [35, 35],
                    iconAnchor: [13, 27],
                    popupAnchor: [1, -24],
                    iconUrl: rIcon
                });
            } else if (!(rIcon)) {
                myIcon = new L.Icon({
                    iconSize: [35, 35],
                    iconAnchor: [13, 27],
                    popupAnchor: [1, -24],
                    iconUrl: 'lib/images/question.png'
                });
            }
            var srchPops = "<div class=\"mypopupinfo\">";
            srchPops += "<div class='popHeader'><h6><strong>" + arr[0] + "</strong></div>";
            srchPops += "<div class='popBody'><h6>" + cc +
                    "</h6></div>";
            srchPops += "<button class='btn btn-default btn-xs add-field' value='" + result.lat + ", " + result.lon + "'>Add Point</button>";
            srchMarkers = new L.marker([result.lat, result.lon], {icon: myIcon}).bindPopup(srchPops);
            srchPoly = L.geoJson(poly);
            mArray.push(srchMarkers, srchPoly);
        }
    }
    srchresultMarkers = L.layerGroup(mArray);

So what am I doing wrong?

share|improve this question
up vote 7 down vote accepted

It looks strange that you add both a GeoJSON layer from result.geojson and a marker created from [result.lat, result.lon].

If result.geojson contains the same point information as [result.lat, result.lon], you are adding both markers to your map.

share|improve this answer
1  
That's correct. I figured that out myself about 45 mins ago. :) – Dean Mar 16 at 15:55
    
Good job in finding it out by yourself! :-) – ghybs Mar 16 at 16:36

an event listener and change the icon through setIcon() method:

createdMarker.on("dblclick", function(evt) {

        var myIcon = L.icon({
            iconUrl: 'res/marker-icon-red.png',
            shadowUrl: 'res/marker-shadow.png'
        });
        this.setIcon(myIcon);
});

Or you can get some help from this Tutorial

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.