0

I am trying to get clicked geojson marker's custom options.I can do it if i create marker in map.But when i get from geojson not working.My code is :

function onClick(e) {
get_marker(this.options.marker_id);
//geojson.features[64].options.marker_id)  
}

get_marker() takes marker's custom id which i defined as a custom marker like this.

customMarker = L.Marker.extend({
       options: { 
          marker_id: 'Custom data!',
          name: '',
          category: '',
          information: '',
          owner: ''
       }
    });

and i create marker in map like this.

map.on('click', function(e) {   
        newMarker[i] = new customMarker (e.latlng, {
            draggable : true,
            marker_id : 'new'
        }).addTo(map);
        newMarker[i].on('click', onClick);

    newMarker[i].bindPopup("<b>Hello world!</b><br />I am a popup.");
            //.openPopup();
    save_marker(newMarker[i]);
    //$(".bilgi").val(newMarker.getPopup().getContent());
    i++;
}); 

i can't get marker_id option in geojson point.When i set geojson.features[64].options.marker_id as a get_marker parameter it works.But i cant control which marker is clicked.Maybe i have to define geojson as a custom marker but i don't know.How can i solve this problem ?

1 Answer 1

0

i solved my problem.when i try to get geojson data i create custom marker and give marker_id and it works now.And now i think using different marker type is difficult. when you create marker in map as a user and getting geojson marker from server has to be same marker type.So using same marker type is better.

L.geoJson(data, {
        onEachFeature : function(feature, layer) {
            var popupContent = "marker_id = " + feature.options.marker_id;
            if (feature.properties && feature.properties.popupContent) {
                popupContent += feature.properties.popupContent;
            }
            layer.bindPopup(popupContent);
            layer.on('click', onClick);
        },
        pointToLayer : function(feature, latlng) {
            return new customMarker(new L.LatLng(feature.geometry.

            coordinates[1], feature.geometry.coordinates[0]), {
                marker_id : feature.options.marker_id
            });
        }
    }).addTo(map);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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