javascript - Detect if a Bing Map AJAX point is contained in a Polygon -



javascript - Detect if a Bing Map AJAX point is contained in a Polygon -

few days ago, made c# function, observe if point in within of polygon. after drawbacks, made function. after using first time, found approach slower. phone call c# code behind function, javascript, troublesome, since javascript continues execution of code, , don't wait result of c# code.

below, posted solution this.

i forced build new function, time in plain javascript. after browsing while, found couple of examples (using google maps functions) , in microsoft site (http://msdn.microsoft.com/en-us/library/cc451895.aspx), function contained in ms site homecoming false. then, using reference code posted here in stackoverflow, have efficient javascript function, adapted bing maps ajax v7. hope can useful others. don't forget mark useful!

loc = pushpin.getlocation(); var isinside = false; var j = 0; var x = loc.longitude; var y = loc.latitude; var paths = polygon.getlocations(); (var = 0; < paths.length ; i++) { j++; if (j == paths.length) { j = 0; } if (((paths[i].latitude < y) && (paths[j].latitude >= y)) || ((paths[j].latitude < y) && (paths[i].latitude >= y))) { if (paths[i].longitude + (y - paths[i].latitude) / (paths[j].latitude - paths[i].latitude) * (paths[j].longitude - paths[i].longitude) < x) { isinside = !isinside } } } if (isinside == true) { pushpin.setoptions({ visible: true }); };

javascript bing-maps

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -