Skip to content

Instantly share code, notes, and snippets.

@tryadelion
Created March 7, 2018 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tryadelion/488d641cbcbe076489eb9ad261824113 to your computer and use it in GitHub Desktop.
Save tryadelion/488d641cbcbe076489eb9ad261824113 to your computer and use it in GitHub Desktop.
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