Closed GoogleCodeExporter closed 9 years ago
Do you have a test case for this functionality that you can attach or provide a
link to that shows the problem?
Original comment by geocodezip
on 25 Jun 2013 at 2:18
I'm afraid I can't, still developing in local and for a intraweb website with
sensitive information. I can attach you some code to help you reproduce the
problem... Basically, I've got a web page with a map and a side-list. When I
click on a link, I load the kml file from a url:
function loadMarkers(sender) { //sender is a form used to filter
var url_kml = $('#container).data('url-kml');
var data = sender.data;
myParser.parse(url_kml + '?' + data);
}
When I click on elements on the side list, I open the infoWindow associated to
the placemark with same 'id':
function rowSelected(sender) {
var id = sender.data('id');
var kml = sender.closest('li.active').data('url-kml');
myParser.docsByUrl[kml].placemarks.forEach(function (e) {
if (e.vars.val.id == id) {
var m = e.marker;
m.infoWindow.open(m.map, m);
}
});
}
I noticed that first time works fine, but when clicking again, some markers in
doc.markes where missing. also, started receiving errors after clicking on list
elements.
Hope this code can help.
Original comment by ava...@jsvrfid.es
on 25 Jun 2013 at 2:48
Can you create a simple example with sanitized data and attach it to this
issue? I will work on a test case, but don't have a lot of time right now.
Original comment by geocodezip
on 25 Jun 2013 at 3:02
Hi! I've created a simple test page. I attach you the html and the kml files.
To run the test, simply open the page and click the 'how many markers?' link.
The alert will show that there are 6 markers, and checks if the first placemark
has a marker object. Then click the 'reload' link and then, the 'kow many
markers?' again. The alert now only shows 4 markers and the first placemark has
no marker.
Hope this helps!
Original comment by ava...@jsvrfid.es
on 26 Jun 2013 at 8:45
Attachments:
Thank you for the test case. Since you have multiple markers at the same
location, seems like might need to look at the id of the placemark (if it has
one, and these do), not the position so the correct one is activated.
Original comment by geocodezip
on 26 Jun 2013 at 1:07
That is what I thought in first place, but at that point, doc.placemarks only
contains the new placemarks, due to initialiation starting in line 436.
Original comment by ava...@jsvrfid.es
on 26 Jun 2013 at 2:13
Online version of the testcase:
http://www.geocodezip.com/geoxml3_test/geoxml3-test.html
Original comment by geocodezip
on 26 Jun 2013 at 5:14
Temporary test version:
http://www.geocodezip.com/geoxml3_test/geoxml3-test_local.html
please test and provide feedback. added an id check (and added the id to the
marker):
doc.markers = doc.markers || [];
if (doc.reload) {
for (var j = 0; j < doc.markers.length; j++) {
- if (doc.markers[j].getPosition().equals(placemark.latlng)) {
+ if (doc.markers[j].getPosition().equals(placemark.latlng) &&
+ (doc.markers[j]._placemarkID == placemark.id) &&
!doc.markers[j].active) {
found = doc.markers[j].active = true;
+ placemark.marker = doc.markers[j];
break;
2 concerns:
1. what if the marker moves in the updated KML? (same id, different location;
definitely not handled correctly in the current implementation)
2. what if the Placemark doesn't have an id?
What is your use case for reloading the KML (as opposed to
hideDocument/showDocument)?
Original comment by geocodezip
on 27 Jun 2013 at 6:07
I though that the point of comparing the position of the placemark and marker
was that it was the only way to perform the matching. If there is an id, such
comparison is not needed in that case. So the modification may be something
like (poor code, I know):
if (doc.reload) {
for (var j = 0; j < doc.markers.length; j++) {
if (doc.markers[j]._placemarkID != undefined) {
if (doc.markers[j]._placemarkID == placemark.id) {
found = doc.markers[j].active = true;
placemark.marker = doc.markers[j];
break;
}
}
else {
if (doc.markers[j].getPosition().equals(placemark.latlng) && !doc.markers[j].active) {
found = doc.markers[j].active =? true;
placemark.marker = doc.markers[j];
break;
}
}
}
}
For reloading KML, I simply call the same url again, but with a different
string query. This results in the new KML file.
Original comment by ava...@jsvrfid.es
on 28 Jun 2013 at 2:33
Original comment by geocodezip
on 30 Jun 2013 at 8:19
Proposed change:
if (doc.reload) {
for (var j = 0; j < doc.markers.length; j++) {
if (((placemark.id && (doc.markers[j]._placemarkID == placemark.id)) ||
(doc.markers[j].getPosition().equals(placemark.latlng)) &&
!doc.markers[j].active) {
found = doc.markers[j].active = true;
placemark.marker = doc.markers[j];
break;
}
}
}
Temporary test case:
http://www.geocodezip.com/geoxml3_test/geoxml3-test_local.html
Original comment by geocodezip
on 15 Jul 2013 at 9:19
fixed in revision 114 kmz branch. Use id of marker if has one rather than
position. Issue was 2 markers had same position.
Original comment by geocodezip
on 16 Aug 2014 at 5:33
fixed in polys branch revision 115
Original comment by geocodezip
on 16 Aug 2014 at 5:48
Original issue reported on code.google.com by
ava...@jsvrfid.es
on 25 Jun 2013 at 10:37