Hi all,

I have a sample page where a marker can be dragged from one country to another.
The countries are defined in a KML file which is loaded on opening the page.

When the marker is put on a country it colors the country. And when the marker is removed the country should get a different color again.
Coloring the country when the marker is put there is working.
But changing the color when the marker is removed doesn't seem to work consitently.
When the marker is put on an ocean the country gets a different color. When the marker is dragged to another country the original country doesn't get a new color.

It looks like the map.getObjects() method doesn't seem to return the actual polygons at the location.
But it only happens now and then.

Any idea's why this would happen?

The KML file can be found here: http://pastebin.ca/2198764

And here's the HTML file:
HTML Code:
	<title>KML Country color test</title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
	<script type="text/javascript" charset="UTF-8" src="http://api.maps.nokia.com/2.2.1/jsl.js?with=all"></script>
<div style="height:300px" id="mapContainer"></div>
<script type="text/javascript" id="exampleJsSource">

nokia.Settings.set( "appId", "myappid"); 
nokia.Settings.set( "authenticationToken", "mytoken");

// Get the DOM node to which we will append the map
var mapContainer = document.getElementById("mapContainer");

// Create a map inside the map container DOM node
var map = new nokia.maps.map.Display(mapContainer, {
	center: [0, 0],
	zoomLevel: 3,
	components: [
		// We add the behavior component to allow panning / zooming of the map
		new nokia.maps.map.component.Behavior(),new nokia.maps.map.component.TypeSelector(),new nokia.maps.map.component.ZoomBar()

var listener = function (evt) {
	var mapDragType = evt.dataTransfer.getData("application/map-drag-type"); 
	if (mapDragType === "standardmarker") {
		// Get the marker itself.
		var marker = evt.dataTransfer.getData("application/map-drag-object");
		// Get the offset of the mouse relative to the top-left corner of the marker.
		var offset = evt.dataTransfer.getData("application/map-drag-object-offset");
		/* Calculate the current coordinate of the marker, so substract the offset from the 
		 * current displayX/Y position to get the top-left position of the marker and then
		 * add the anchor to get the pixel position of the anchor of the marker and then 
		 * query for the coordinate of that pixel position
		var newx=evt.displayX - offset.x + marker.anchor.x;
		var newy=evt.displayY - offset.y + marker.anchor.y;
				//map.objects.add(new nokia.maps.map.StandardMarker(map.pixelToGeo(this.previousMark.x,this.previousMark.y)));
			this.previousMark=new nokia.maps.util.Point(newx,newy);

var colorCountry=function(x,y,color){
	// Stopped dragging, check for country and color it
	objects = map.getObjectsAt(x, y);
	console.info("Objects at location: "+objects.length);
	for(var i=0;i<objects.length;i++){
		var object=objects[i];
		var countryobject=null;
		if(!(typeof object.n === "undefined") && object.n == "polygon"){
			//a polygon object is found, check the parent to see if there are more polygon's for that country
			if(object.getParent(map).n == "container" && object.getParent(map).objects.getLength()<=150){
				//the marker is place on a country with multiple polygons
				var parent=object.getParent(map);
				for(var j=0;j<parent.objects.getLength();j++){
					var otherpolygon=parent.objects.get(j);
					if(otherpolygon.n == "polygon"){
						otherpolygon.set("brush",new nokia.maps.util.Brush({color:color,fill: "solid"}));
				object.set("brush",new nokia.maps.util.Brush({color:color,fill: "solid"}));

// Create a new standard marker
var standardMarker = new nokia.maps.map.StandardMarker(
	new nokia.maps.geo.Coordinate(-2, -2), {
		//make the marker draggable
		draggable: true

// Add the listener function to the bubbling phase of the "dragend" event
standardMarker.addListener("dragend", listener, false);


var kml = new nokia.maps.kml.Manager();
var resultSet="test";

// We define a callback function for parsing kml file,
// and then push the parsing result to map display
var onParsed = function (kmlManager) {
	var container,
	// KML file was successfully loaded
	if (kmlManager.state == "finished") {
		console.debug("kmlManager state finished");
		// KML file was successfully parsed
		resultSet = new nokia.maps.kml.component.KMLResultSet(kmlManager.kmlDocument, map);
		resultSet.addObserver("state", function (resultSet) {
			if (resultSet.state == "finished") {
				console.debug("resultSet finished");
		// Add the container to the map's object collection so it will be rendered onto the map.
		map.objects.add(container = resultSet.create());
// Add an observer to kml manager
kml.addObserver("state", onParsed);

// Start parsing a kml file with given url
// Note: please adapt the following path to the file you want to parse.