0
votes

I am trying for hours now to find out how to implement GeoJson data into a draggable marker in leaflet.

What should be the outcome?

I have a lot of GeoJson data and when the user moves the marker around it should always be updated with the data in a popup from the GeoJson data. However, I do not get any popup and this popup should be shown automatically when the user moves the marker around as well as when the user opens the map.

For now I was able to do this thing: Marker, LineString but there opens no popup when I move the marker around, there will be only a popup when the mouse clicks on a point of the Linstring.

Maybe someone can help me, please!

Thank you very much in advance!

Here is my code:

var lat = "48.213596251439945";
var lon = "16.370388632910814";

var userLocation = new L.LatLng(lat, lon);
var map = L.map('map').setView(userLocation, 15);

var marker = new L.Marker(userLocation, {draggable:true}).addTo(map);

function onEachFeature(feature, layer) {
    if (feature.properties && feature.properties.ADRESSE) {
        layer.bindPopup(feature.properties.ADRESSE);
    }
}

var park ={"type":"FeatureCollection","totalFeatures":318,"features":[{"type":"Feature","id":"PARKENANRAINEROGD.46915","geometry":{"type":"LineString","coordinates":[[16.343426519543712,48.19899297608236],[16.343819453861414,48.199054476000356]]},"geometry_name":"SHAPE","properties":{"OBJECTID":46915,"ADRESSE":"7, Lindengasse 65","AUSNAHME_TXT":"ausg. Fahrzeuge mit Parkkleber für den 7. Bezirk","STELLPL_ANZ":6,"WEITERE_INF":"http://www.wien.gv.at/verkehr/parken/kurzparkzonen/anrainerparken/index.html","SE_ANNO_CAD_DATA":null}},{"type":"Feature","id":"PARKENANRAINEROGD.46916","geometry":{"type":"LineString","coordinates":[[16.344127698086258,48.19693994597798],[16.34405731788839,48.197075926878945]]},"geometry_name":"SHAPE","properties":{"OBJECTID":46916,"ADRESSE":"7, Schottenfeldgasse 1","AUSNAHME_TXT":"ausg. Fahrzeuge mit Parkkleber für den 7. Bezirk","STELLPL_ANZ":5,"WEITERE_INF":"http://www.wien.gv.at/verkehr/parken/kurzparkzonen/anrainerparken/index.html","SE_ANNO_CAD_DATA":null}},{"type":"Feature","id":"PARKENANRAINEROGD.46917","geometry":{"type":"LineString","coordinates":[[16.343436482402232,48.19823247289745],[16.343044047309462,48.19816957993468]]},"geometry_name":"SHAPE","properties":{"OBJECTID":46917,"ADRESSE":"7, Apollogasse 5","AUSNAHME_TXT":"ausg. Fahrzeuge mit Parkkleber für den 7. Bezirk","STELLPL_ANZ":6,"WEITERE_INF":"http://www.wien.gv.at/verkehr/parken/kurzparkzonen/anrainerparken/index.html","SE_ANNO_CAD_DATA":null}},{"type":"Feature","id":"PARKENANRAINEROGD.46918","geometry":{"type":"LineString","coordinates":[[16.341316763422924,48.197389549581146],[16.341216883353184,48.19783422369746]]},"geometry_name":"SHAPE","properties":{"OBJECTID":46918,"ADRESSE":"7, Kaiserstraße 7 bis 9","AUSNAHME_TXT":"ausg. Fahrzeuge mit Parkkleber für den 7. Bezirk","STELLPL_ANZ":10,"WEITERE_INF":"http://www.wien.gv.at/verkehr/parken/kurzparkzonen/anrainerparken/index.html","SE_ANNO_CAD_DATA":null}},{"type":"Feature","id":"PARKENANRAINEROGD.46919","geometry":{"type":"LineString","coordinates":[[16.340597502665545,48.19814779191206],[16.340710677525596,48.197984617136626]]},"geometry_name":"SHAPE","properties":{"OBJECTID":46919,"ADRESSE":"7, Apollogasse 28","AUSNAHME_TXT":"ausg. Fahrzeuge mit Parkkleber für den 7. Bezirk","STELLPL_ANZ":4,"WEITERE_INF":"http://www.wien.gv.at/verkehr/parken/kurzparkzonen/anrainerparken/index.html","SE_ANNO_CAD_DATA":null}},{"type":"Feature","id":"PARKENANRAINEROGD.46920","geometry":{"type":"LineString","coordinates":[[16.36369899496353,48.21041785473858],[16.364024360352,48.20999372090455]]},"geometry_name":"SHAPE","properties":{"OBJECTID":46920,"ADRESSE":"1, Petrarcagasse 2","AUSNAHME_TXT":"ausg. Fahrzeuge mit Parkkleber für den 1. Bezirk","STELLPL_ANZ":11,"WEITERE_INF":"http://www.wien.gv.at/verkehr/parken/kurzparkzonen/anrainerparken/index.html","SE_ANNO_CAD_DATA":null}},{"type":"Feature","id":"PARKENANRAINEROGD.46921","geometry":{"type":"LineString","coordinates":[[16.370388632910814,48.213596251439945],[16.371272095721892,48.213365313905804]]},"geometry_name":"SHAPE","properties":{"OBJECTID":46921,"ADRESSE":"1, Salzgries 14 bis 18","AUSNAHME_TXT":"ausg. Fahrzeuge mit Parkkleber für den 1. Bezirk","STELLPL_ANZ":22,"WEITERE_INF":"http://www.wien.gv.at/verkehr/parken/kurzparkzonen/anrainerparken/index.html","SE_ANNO_CAD_DATA":null}},{"type":"Feature","id":"PARKENANRAINEROGD.46922","geometry":{"type":"LineString","coordinates":[[16.34089103293889,48.19102192022651],[16.340805285726734,48.19119392107657]]},"geometry_name":"SHAPE","properties":{"OBJECTID":46922,"ADRESSE":"6, Gfrornergasse 11","AUSNAHME_TXT":"ausg. Fahrzeuge mit Parkkleber für den 6. Bezirk","STELLPL_ANZ":4,"WEITERE_INF":"http://www.wien.gv.at/verkehr/parken/kurzparkzonen/anrainerparken/index.html","SE_ANNO_CAD_DATA":null}},{"type":"Feature","id":"PARKENANRAINEROGD.46923","geometry":{"type":"LineString","coordinates":[[16.37738967522273,48.2028433999537],[16.37697583375718,48.20243859721643]]},"geometry_name":"SHAPE","properties":{"OBJECTID":46923,"ADRESSE":"1, Kantgasse 2 bis 4","AUSNAHME_TXT":"ausg. Fahrzeuge mit Parkkleber für den 1. Bezirk","STELLPL_ANZ":11,"WEITERE_INF":"http://www.wien.gv.at/verkehr/parken/kurzparkzonen/anrainerparken/index.html","SE_ANNO_CAD_DATA":null}},{"type":"Feature","id":"PARKENANRAINEROGD.46924","geometry":{"type":"LineString","coordinates":[[16.375161348679857,48.203392872925484],[16.375490802610553,48.20370480701764]]},"geometry_name":"SHAPE","properties":{"OBJECTID":46924,"ADRESSE":"1, Hegelgasse 10 bis 12","AUSNAHME_TXT":"ausg. Fahrzeuge mit Parkkleber für den 1. Bezirk","STELLPL_ANZ":12,"WEITERE_INF":"http://www.wien.gv.at/verkehr/parken/kurzparkzonen/anrainerparken/index.html","SE_ANNO_CAD_DATA":null}},{"type":"Feature","id":"PARKENANRAINEROGD.46925","geometry":{"type":"LineString","coordinates":[[16.37563338574046,48.20383069631851],[16.37609805265778,48.204271916358685]]},"geometry_name":"SHAPE","properties":{"OBJECTID":46925,"ADRESSE":"1, Hegelgasse 6 bis 8","AUSNAHME_TXT":"ausg. Fahrzeuge mit Parkkleber für den 1. Bezirk","STELLPL_ANZ":10,"WEITERE_INF":"http://www.wien.gv.at/verkehr/parken/kurzparkzonen/anrainerparken/index.html","SE_ANNO_CAD_DATA":null}},{"type":"Feature","id":"PARKENANRAINEROGD.46926","geometry":{"type":"LineString","coordinates":[[16.375482015391142,48.20375222547123],[16.37494494209173,48.20399285355658]]},"geometry_name":"SHAPE","properties":{"OBJECTID":46926,"ADRESSE":"1, Johannesgasse 14","AUSNAHME_TXT":"ausg. Fahrzeuge mit Parkkleber für den 1. Bezirk","STELLPL_ANZ":10,"WEITERE_INF":"http://www.wien.gv.at/verkehr/parken/kurzparkzonen/anrainerparken/index.html","SE_ANNO_CAD_DATA":null}}]};

L.geoJson(park, {
    onEachFeature: onEachFeature
}).addTo(map);

L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    maxZoom: 20}).addTo(map);
1

1 Answers

0
votes
var lat = "48.213596251439945";
var lon = "16.370388632910814";

Latitude & longitude are numbers: these should not have quotes around them. Quotes mean strings.

Besides that, it's not clear what you're really trying to do... you drag around a marker and whatever the marker is on top of, that's what the popup of the marker shows? Since the marker can be on top of multiple features at the same time, should it show all? None? And can it be dragged on top of a point, which has zero area?