Created
March 7, 2018 16:50
-
-
Save tryadelion/488d641cbcbe076489eb9ad261824113 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getCoordinates : function(xPixelCoordinate,yPixelCoordinate,map){ | |
var pxTopLeft = this._map.latLngToLayerPoint(this._topLeft); | |
var pxTopRight = this._map.latLngToLayerPoint(this._topRight); | |
var pxBottomLeft = this._map.latLngToLayerPoint(this._bottomLeft); | |
var vectorX = pxTopRight.subtract(pxTopLeft); | |
var vectorY = pxBottomLeft.subtract(pxTopLeft); | |
var imgW = this._rawImage.width; | |
var imgH = this._rawImage.height; | |
var vectorXperPx = vectorX.divideBy(imgW); | |
var vectorYperPx = vectorY.divideBy(imgW); | |
var deltaVector = xPixelCoordinate.scaleBy(vectorXperPx).add(yPixelCoordinate.scaleBy(vectorYperPx)); | |
var finalCoordinateForImagePixel = pxTopLeft.add(deltaVector); | |
console.log(finalCoordinateForImagePixel); | |
try{ | |
var finalCoordinateForImagePixelInLatLong = | |
map.layerPointToLatLng(finalCoordinateForImagePixel); | |
return finalCoordinateForImagePixelInLatLong; | |
}catch(exception){ | |
return {lat: 0.0, lng: 0.0}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment