Ho creato un tipo di mappa personalizzato utilizzando lAPI di Google Maps.

Ho utilizzato maptiler per creare i diversi zoomlayers e lo 0 il livello (veramente ingrandito) è un riquadro di 256 x 256. Limmagine copre solo 134 x 112 tuttavia.

Voglio essere in grado di rendere le coordinate della mappa relative allintera mappa e non le coordinate terrestri predefinite di Google Maps. Ad esempio, langolo in alto a sinistra dovrebbe essere (0,0) mentre quello in basso a destra dovrebbe essere (50,50).

Ho ricevuto aiuto da Heitor Chang qui: https://stackoverflow.com/questions/11192281/can-i-reset-latlng-coordinates-for-a-custom-map-type

Il problema sta qui:

dayzProjection.prototype.fromLatLngToPoint = function(latlng) { // pixel size of tile at zoom 0 var max = 134; // define bottom-right corner as (50, 50) var x = max * latlng.lng() / 50; var y = max * latlng.lat() / 50; return new google.maps.Point(x, y); }; dayzProjection.prototype.fromPointToLatLng = function(pixel) { // inverse conversion var lng = pixel.x / max * 50; var lat = pixel.y / max * 50; return new google.maps.LatLng(lat, lng); }; 

Qualcuno può aiutarmi a trasformare queste coordinate.

Questo può aiutare: https://developers.google.com/maps/documentation/javascript/maptypes#Projections

Risposta

In realtà è possibile posizionare langolo superiore sinistro a 0,0 e quello inferiore destro a 50,50, se vuoi questo. Ovviamente puoi posizionare anche langolo in basso a destra a 10,10, o qualsiasi altra cosa, entro i limiti: -90 / + 90 per latitudine e -180 / + 180 per longitudine.

La proporzione dovrebbe essere:

/* ****************************************** Custom Projection - CARTESIAN ****************************************** */ function CartesianProjection() { // map size at zoom 0 is equal to tile size this.tileSize = 256; }; CartesianProjection.prototype.fromLatLngToPoint = function(latLng) { var x = (latLng.lng() / 50) * this.tileSize; var y = (latLng.lat() / 50) * this.tileSize; return new google.maps.Point(x, y); }; CartesianProjection.prototype.fromPointToLatLng = function(point, noWrap) { var lng = (point.x / this.tileSize) * 50; var lat = (point.y / this.tileSize) * 50; return new google.maps.LatLng(lat, lng, noWrap); }; 

Quindi dovresti posizionare il centro della mappa su LatLng (25,25) nelle Opzioni mappa.

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *