`

google maps与arcgis结合

阅读更多
google maps提供了与arcgis的接口,实现了google maps 与arcgis结合

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Google Maps Adapter to ArcGIS Server Map Cache</title>
    <!-- replace your key -->

    <script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAGY8Xhrw1zw6Ia3dwUJVxKRT_Dik9yxNP5XbRDcNbZKLa1CrDkxRDjJast2WNsqXjiEGPt_8s229nyw"
        type="text/javascript"></script>
    <style type="text/css">
             html, body {     margin: 0px;     height: 100%;}
             </style>

    <script type="text/javascript">


function LCC(params){
    /*=========parameters=================*/
    params=params||{};
    this.name=params.name||"LCC";
    var _a = (params.semi_major ||6378137.0 )/(params.unit||0.3048006096012192);
    var _f_i=params.inverse_flattening||298.257222101;//this.
    var _phi1 = (params.standard_parallel_1||34.33333333333334) * (Math.PI / 180);
    var _phi2 = (params.standard_parallel_2||36.16666666666666) * (Math.PI / 180);
    var _phiF = (params.latitude_of_origin||33.75) * (Math.PI / 180);
    var _lamdaF = (params.central_meridian||-79.0)* (Math.PI / 180);
    var _FE = params.false_easting||2000000.002616666;//this.
    var _FN = params.false_northing||0.0;//this.
    /*========== functions to calc values, potentially can move outside as static methods=========*/
    var calc_m = function(phi, es){
        var sinphi = Math.sin(phi);
        return Math.cos(phi) / Math.sqrt(1 - es * sinphi * sinphi);
    };
    var calc_t = function(phi, e){
        var esinphi = e * Math.sin(phi);
        return Math.tan(Math.PI / 4 - phi / 2) / Math.pow((1 - esinphi) / (1 + esinphi), e / 2);
    };
    var calc_r = function(a, F, t, n){
        return a * F * Math.pow(t, n)
    };
    var calc_phi = function(t_i, e, phi){
        var esinphi = e * Math.sin(phi);
       return Math.PI / 2 - 2 * Math.atan(t_i * Math.pow((1 - esinphi) / (1 + esinphi), e / 2));
    };
   
    var solve_phi = function(t_i, e, init){
        // iteration
       var i = 0;
        var phi = init;
        var newphi = calc_phi(t_i, e, phi);//this.
        while (Math.abs(newphi - phi) > 0.000000001 && i < 10) {
            i++;
            phi = newphi;
            newphi = calc_phi(t_i, e, phi);//this.
        }
        return newphi;
    }

/*=========shared, not point specific params or intermediate values========*/
    var _f = 1.0 /_f_i;//this.
    /*e: eccentricity of the ellipsoid where e^2 = 2f - f^2 */
    var _es = 2 * _f - _f * _f;
    var _e = Math.sqrt(_es);
    var _m1 = calc_m(_phi1, _es);//this.
    var _m2 = calc_m(_phi2, _es);//this.
    var _tF = calc_t(_phiF, _e);//this.
    var _t1 = calc_t(_phi1, _e);//this.
    var _t2 = calc_t(_phi2, _e);//this.
    var _n = Math.log(_m1 / _m2) / Math.log(_t1 / _t2);
    var _F = _m1 / (_n * Math.pow(_t1, _n));
    var _rF = calc_r(_a, _F, _tF, _n);//this.
   
    this.forward = function(latlng){
        var phi = latlng[1] * (Math.PI / 180);
        var lamda = latlng[0] * (Math.PI / 180);
        var t = calc_t(phi, _e);//this.
        var r = calc_r(_a, _F, t, _n);//this.
        var theta = _n * (lamda - _lamdaF);
        var E = _FE + r * Math.sin(theta);
        var N = _FN + _rF - r * Math.cos(theta);
        return [E, N];
    };
    this.inverse = function(xy){
        var E = xy[0];
        var N = xy[1];
        var theta_i = Math.atan((E - _FE) / (_rF - (N - _FN)));
        var r_i = (_n > 0 ? 1 : -1) * Math.sqrt((E - _FE) * (E - _FE) + (_rF - (N - _FN)) * (_rF - (N - _FN)));
        var t_i = Math.pow((r_i / (_a * _F)), 1 / _n);
        var phi = solve_phi(t_i, _e, 0);//this.
        var lamda = theta_i / _n + _lamdaF;
        return [lamda * (180 / Math.PI), phi * (180 / Math.PI)];
    };
    this.circum = function(){
        return Math.PI * 2 * _a;
    };
   
}


function GMapCacheProjection(params){
params = params||{};
    this.zoomOffset = params.zoomOffset||10;
    this.originX = params.originX || 0;
    this.originY = params.originY || 2000000;// pixel Y increase downwards.
    this.projection = params.projection||new LCC();
    this.resolutions = params.resolutions||[434.027777777778,
217.013888888889, 108.506944444444,  55.5555555555556,
27.7777777777778, 13.8888888888889, 6.94444444444444,
3.47222222222222,1.73611111111111,1,0.5] ; // units/pixel
    this.bounds = params.bounds||null;
}

GMapCacheProjection.prototype = new GProjection();
GMapCacheProjection.prototype.fromLatLngToPixel = function(latlng, zoom){
    if (latlng == null)
        return null;
    var coords = this.projection.forward([latlng.lng(), latlng.lat()]);
    var zoomInx = zoom - this.zoomOffset;
    var x = Math.round((coords[0] - this.originX) / this.resolutions[zoomInx]);
    var y = Math.round((this.originY - coords[1]) / this.resolutions[zoomInx]);
    return new GPoint(x, y);
};
GMapCacheProjection.prototype.fromPixelToLatLng = function(pixel, zoom, unbound){
    if (pixel == null)
        return null;
    var zoomInx = zoom - this.zoomOffset;
    var x = pixel.x * this.resolutions[zoomInx] + this.originX;
    var y = this.originY - pixel.y * this.resolutions[zoomInx];
    var geo = this.projection.inverse([x, y]);
    return new GLatLng(geo[1], geo[0]);
};

GMapCacheProjection.prototype.tileCheckRange = function(tile, zoom, tilesize){
    var b=this.bounds;
    if (!b||b==null)     return true;
    var zoomInx = zoom - this.zoomOffset;
    var minX = tile.x * tilesize * this.resolutions[zoomInx] + this.originX;
    var minY = this.originY - (tile.y + 1) * tilesize * this.resolutions[zoomInx];
    var maxX = (tile.x + 1) * tilesize * this.resolutions[zoomInx] + this.originX;
    var maxY = this.originY - tile.y * tilesize * this.resolutions[zoomInx];
    return ! (b.minX>maxX||b.maxX<minX||b.maxY<minY||b.minY>maxY);
};

// This is the X sizes in pixel of the earth under this projection.
GMapCacheProjection.prototype.getWrapWidth = function(zoom){
    var zoomInx = zoom - this.zoomOffset;
    return this.projection.circum() / this.resolutions[zoomInx];
}

// To realworld coordinates, not required for GProjection implementation
GMapCacheProjection.prototype.fromLatLngToCoords = function(latlng){
    var xy = this.projection.forward([latlng.lng(), latlng.lat()]);
    return new GPoint(xy[0], xy[1]);
};

GMapCacheProjection.prototype.fromCoordsToLatLng = function(coords){
    var geo = this.projection.inverse([coords.x, coords.y]);
    return new GLatLng(geo[1], geo[0]);
};
//==========end  GMapCacheProjection code ==================/


function initialize() {
     
      if (GBrowserIsCompatible()) {
//This is state plane north carolina NAD83 feet.
      var prj=new LCC({semi_major:6378137.0,
inverse_flattening:298.257222101,
standard_parallel_1:34.33333333333334,
standard_parallel_2:36.16666666666666,
central_meridian:-79.0,
latitude_of_origin: 33.75,
false_easting:2000000.002616666,
false_northing:0,
unit:0.3048006096012192});
// This is the tile scheme info. values can be derived from conf.xml in the cache folder
var params={
zoomOffset:10,
        originX:0,
        originY:2000000,
projection:prj,
        resolutions:[
  434.027777777778, 217.013888888889, 108.506944444444,
   55.5555555555556,27.7777777777778,13.8888888888889,
   6.94444444444444,3.47222222222222,1.73611111111111]
};
var gprj=new GMapCacheProjection(params);
//create a layer
var acopy=new GCopyrightCollection('Data ');

        acopy.addCopyright(new GCopyright(1, new GLatLngBounds(new GLatLng(34.9642,-81.1470), new GLatLng(35.5870,-80.5079)), 0, 'Copyright(c) 2008 City of Charlotte, Mecklenburg County, NC'));

        var agsLayer1= new GTileLayer(acopy, params.zoomOffset, (params.zoomOffset+params.resolutions.length-1));
        agsLayer1.getTileUrl = function(tile,zoom){
                  return 'http://mt'+((tile.x+tile.y)%4)+'.charmeck.org/mapcache/PLAN_zoning/Layers/_alllayers/L'+('00'+(zoom-params.zoomOffset).toString(10)).substring(('00'+(zoom-params.zoomOffset).toString(10)).length-2)+'/R'+('00000000'+tile.y.toString(16)).substring(('00000000'+tile.y.toString(16)).length-8)+'/C'+('00000000'+tile.x.toString(16)).substring(('00000000'+tile.x.toString(16)).length-8)+'.png';
        }
// create a MapType
       var agsMap1 = new GMapType([agsLayer1],gprj,'Zoning', {tileSize: 512});
      
       var agsLayer2= new GTileLayer(acopy, 10, 17);
       agsLayer2.getTileUrl = function(tile,zoom){
                  return 'http://mt'+((tile.x+tile.y)%4)+'.charmeck.org/mapcache/GET_Aerial/Layers/_alllayers/L'+('00'+(zoom-10).toString(10)).substring(('00'+(zoom-10).toString(10)).length-2)+'/R'+('00000000'+tile.y.toString(16)).substring(('00000000'+tile.y.toString(16)).length-8)+'/C'+('00000000'+tile.x.toString(16)).substring(('00000000'+tile.x.toString(16)).length-8)+'.jpg';
       }
       var agsMap2 = new GMapType([agsLayer2],gprj,'2007 Aerial', {tileSize: 512});
        var map= new GMap2(document.getElementById("map_canvas"), {mapTypes:[agsMap1, agsMap2]});
       
// make sure change to your latlng if not in Charlotte, NC.
        map.setCenter(new GLatLng(35.249208, -80.843099), 11);
        map.addControl(new GMapTypeControl());
        map.addControl(new GLargeMapControl  ());
        map.addControl(new GScaleControl());
        map.enableDoubleClickZoom();
        map.enableContinuousZoom();
        map.enableScrollWheelZoom();
    
      }
     
     
    }

    </script>

</head>
<body onload="initialize()" onunload="GUnload();">
  
                <div id="map_canvas" style="width: 100%; height: 100%">
                </div>
          
</body>

</html>




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics