Despite all my attempts to correct the situation with the technology of loading data onto a map, people all continue and continue to work the old-fashioned way, either downloading all the viewport data at the slightest movement of the map, or simply downloading all the data in general.$.get( "ajax/load-map-data?SE=" +MySECorner.toString()+ "&NE=" +MyNECorner.toString()+ "&zoom=" +currentZoom, function (data){ //wow! i got the data for map! //for whole visible viewport( and just for it) }); * This source code was highlighted with Source Code Highlighter .
$.get( "ajax/load-map-data?SE=" +MySECorner.toString()+ "&NE=" +MyNECorner.toString()+ "&zoom=" +currentZoom, function (data){ //wow! i got the data for map! //for whole visible viewport( and just for it) }); * This source code was highlighted with Source Code Highlighter .$.get( "ajax/load-map-data?SE=" +MySECorner.toString()+ "&NE=" +MyNECorner.toString()+ "&zoom=" +currentZoom, function (data){ //wow! i got the data for map! //for whole visible viewport( and just for it) }); * This source code was highlighted with Source Code Highlighter .$.get( "ajax/load-map-data?SE=" +MySECorner.toString()+ "&NE=" +MyNECorner.toString()+ "&zoom=" +currentZoom, function (data){ //wow! i got the data for map! //for whole visible viewport( and just for it) }); * This source code was highlighted with Source Code Highlighter .$.get( "ajax/load-map-data?SE=" +MySECorner.toString()+ "&NE=" +MyNECorner.toString()+ "&zoom=" +currentZoom, function (data){ //wow! i got the data for map! //for whole visible viewport( and just for it) }); * This source code was highlighted with Source Code Highlighter .$.get( "ajax/load-map-data?SE=" +MySECorner.toString()+ "&NE=" +MyNECorner.toString()+ "&zoom=" +currentZoom, function (data){ //wow! i got the data for map! //for whole visible viewport( and just for it) }); * This source code was highlighted with Source Code Highlighter .$.get( "ajax/load-map-data?SE=" +MySECorner.toString()+ "&NE=" +MyNECorner.toString()+ "&zoom=" +currentZoom, function (data){ //wow! i got the data for map! //for whole visible viewport( and just for it) }); * This source code was highlighted with Source Code Highlighter .
* This source code was highlighted with Source Code Highlighter .
- function ServerFetchMapType () {
- }
- ServerFetchMapType.prototype.tileSize = new google.maps.Size (256,256);
- ServerFetchMapType.prototype.maxZoom = 32;
- ServerFetchMapType.prototype.name = "Server Tile #s" ;
- ServerFetchMapType.prototype.alt = "Server Data Tile Map Type" ;
- ServerFetchMapType.prototype.getTile = function (coord, zoom, ownerDocument) {
- var addr = this .getAddr (coord, zoom);
- // test - may be we all load this block?
- if (ServerFetchedTiles [addr]) {
- return
- }
- $ .get ( "ajax / load-map-tile?" + addr,
- function (data) {
- ServerFetchedTiles [addr] = data;
- // wow! i got the data just for this tile
- });
- };
- // and add this tile overlay to current map type
- map.overlayMapTypes.insertAt (0, new ServerFetchMapType ());
* This source code was highlighted with Source Code Highlighter .
- // we can request tile as tile (x, y, z)
- ServerFetchMapType.prototype.getAddrXY = function (coord, zoom) {
- return "x =" + coord.x + "& y =" + coor.y + "& z =" + zoom;
- }
- // or as latlng box
- ServerFetchMapType.prototype.getAddrLatLng = function (coord, zoom) {
- // helper function for mercator projection
- var mercator = function (point) {
- //
- var numtiles = Math.pow (2, point.zoom);
- var bitmapsize = numtiles * 256;
- var bitmaporigo = bitmapsize / 2;
- var pixelsperlondegree = bitmapsize / 360;
- var pixelsperlonradian = bitmapsize / (2 * Math.PI);
- var lat = bitmaporigo + (pixelsperlondegree * point.x);
- var ged2rad = ((point.t * Math.PI) /180.0);
- var sn = Math.sin (deg2rad);
- var lng = ((bitmaporigo - 0.5 * log ((1 + sn) / (1-sn)) * pixelsperlonradian));
- return new google.maps.LatLng (lat, lng);
- }
- var point1 = {x: coord.x * 256, y: coord.y * 256, z: zoom};
- var point2 = {x: (coord.x + 1) * 256, y: (coord.y + 1) * 256, z: zoom};
- var ne = mercator (point1);
- var sw = mercator (point2);
- return "NE =" + ne.toString () + "& SW =" + sw.toString () + "& z =" + zoom;
- }
Source: https://habr.com/ru/post/87894/
All Articles