openlayers+geojson

/**

必须设置一个vector图层为基层图层,不能加鹰眼,否则vector里的对象显示不了,但是鹰眼里可以显示,奇怪?

如果加多个vector,鹰眼中会显示基础图层,地图中不显示,其他图层可以正常显示



* 使用了openlayers、xuhy.VT.js,
*/
var xuhy = xuhy ? xuhy : {};
xuhy.Map = xuhy.Map ? xuhy.Map
: {




    Map: function() {
        var _this = this;
        var gmap, styles, map, draw, modify, snap, split, vectors;
        _this.Fix = function(number, num) {
            with (Math) return round(number.valueOf() * pow(10, num)) / pow(10, num);
        };
        _this.Initialize = function() {
            try {
                OpenLayers.DOTS_PER_INCH = 72; //90.71428571428572;//25.4 / 0.28
                OpenLayers.Util.onImageLoadErrorColor = 'transparent';
                OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
                OpenLayers.INCHES_PER_UNIT["公里"] = OpenLayers.INCHES_PER_UNIT["km"];
                OpenLayers.INCHES_PER_UNIT["米"] = OpenLayers.INCHES_PER_UNIT["m"];
                OpenLayers.INCHES_PER_UNIT["尺"] = OpenLayers.INCHES_PER_UNIT.m / 3.0;
                styles = new OpenLayers.StyleMap({
                    "default": new OpenLayers.Style(null, {
                        rules: [
                        new OpenLayers.Rule({
                            symbolizer: {
                                "Point": {
                                    pointRadius: 5,
                                    graphicName: "square",
                                    fillColor: "white",
                                    fillOpacity: 0.25,
                                    strokeWidth: 1,
                                    strokeOpacity: 1,
                                    strokeColor: "#3333aa"
                                },
                                "Line": {
                                    strokeWidth: 3,
                                    strokeOpacity: 1,
                                    strokeColor: "#6666aa"
                                },
                                "Polygon": {
                                    strokeWidth: 1,
                                    strokeOpacity: 1,
                                    fillColor: "#9999aa",
                                    strokeColor: "#6666aa"
                                }
                            }
                        })
                      ]
                    }),
                    "select": new OpenLayers.Style(null, {
                        rules: [
                        new OpenLayers.Rule({
                            symbolizer: {
                                "Point": {
                                    pointRadius: 5,
                                    graphicName: "square",
                                    fillColor: "white",
                                    fillOpacity: 0.25,
                                    strokeWidth: 2,
                                    strokeOpacity: 1,
                                    strokeColor: "#0000ff"
                                },
                                "Line": {
                                    strokeWidth: 3,
                                    strokeOpacity: 1,
                                    strokeColor: "#0000ff"
                                },
                                "Polygon": {
                                    strokeWidth: 2,
                                    strokeOpacity: 1,
                                    fillColor: "#0000ff",
                                    strokeColor: "#0000ff"
                                }
                            }
                        })
                    ]
                    }),
                    "temporary": new OpenLayers.Style(null, {
                        rules: [
                        new OpenLayers.Rule({
                            symbolizer: {
                                "Point": {
                                    graphicName: "square",
                                    pointRadius: 5,
                                    fillColor: "white",
                                    fillOpacity: 0.25,
                                    strokeWidth: 2,
                                    strokeColor: "#0000ff"
                                },
                                "Line": {
                                    strokeWidth: 3,
                                    strokeOpacity: 1,
                                    strokeColor: "#0000ff"
                                },
                                "Polygon": {
                                    strokeWidth: 2,
                                    strokeOpacity: 1,
                                    strokeColor: "#0000ff",
                                    fillColor: "#0000ff"
                                }
                            }
                        })
                    ]
                    })
                });




            } catch (e) {
                throw new Error("Initialize->:\n" + e.name + ":" + e.message)
            }
        };








        _this.MousePositionFormatOutput = function(lonLat) {
            var templon = "东经:"
            var templat = "北纬:"
            if (lonLat.lon < 0) {
                templon = "西经:";
            }
            if (lonLat.lat < 0) {
                templat = "南纬:"
            }
            templon += _this.Fix(Math.abs(lonLat.lon), 4);
            templat += _this.Fix(Math.abs(lonLat.lat), 4);
            return templon + "," + templat;
        };




        //加载google地图
        _this.loadMap = function() {
            try {
                var options = {




                    controls: [
       new OpenLayers.Control.Navigation(),
new OpenLayers.Control.MousePosition({ formatOutput: _this.MousePositionFormatOutput }),
new OpenLayers.Control.LayerSwitcher()
, new OpenLayers.Control.PanZoomBar()//
                    // , new OpenLayers.Control.OverviewMap({ maximized: true })
               , new OpenLayers.Control.ScaleLine({ topOutUnits: "公里", topInUnits: "米", bottomOutUnits: "米", bottomInUnits: "尺" })
   ]
                    //,allOverlays: true
                   , projection: new OpenLayers.Projection("EPSG:4326")//900913
                   , displayProjection: new OpenLayers.Projection("EPSG:4326")
                   , units: "dd"
                   , maxResolution: 1.40625
                   , maxExtent: new OpenLayers.Bounds(-180, -90, 180, 90)//20037508.34




                };
                map = new OpenLayers.Map('map', options); //
                gmap = new OpenLayers.Layer.Google(
                   "Road", // the default
                   {numZoomLevels: 20
                   , isBaseLayer: true
               }
               );
                // map.addLayer(gmap);
               var ovictrl = new OpenLayers.Control.OverviewMap();
              // map.addControl(ovictrl);


                // create three vector layers
                vectors = new OpenLayers.Layer.Vector("Lines", {


                    strategies: [new OpenLayers.Strategy.Fixed()],
                    protocol: new OpenLayers.Protocol.HTTP({
                        url: "../data/test.json",
                        format: new OpenLayers.Format.GeoJSON()
                    }),
                    styleMap: styles
                     , isBaseLayer: true
                    // ,maxExtent: new OpenLayers.Bounds(1549471.9221, 6403610.94, 1550001.32545, 6404015.8)
                });
                map.addLayer(vectors);
                map.zoomToMaxExtent();
              
            } catch (e) {
                throw new Error("loadMap->:\n" + e.name + ":" + e.message)
            }
        };








    }




}








// 文档初始化
$(document).ready(function() {
    try {
        //  document.body.clientWidth;// ==> BODY对象宽度 
        var newheight = document.documentElement.clientHeight - 2; // ==> BODY对象高度 
        document.getElementById("map").style.height = newheight + 'px';
        //alert("create map");
        var MapInstance = new xuhy.Map.Map();
        MapInstance.Initialize();
        MapInstance.loadMap();




    } catch (e) {
        alert("初始化出错:\n" + e.name + ":" + e.message)
    }
});
/*
 
// configure the snapping agent
snap = new OpenLayers.Control.Snapping({ layer: vectors });
map.addControl(snap);
snap.activate();




// configure split agent
split = new OpenLayers.Control.Split({
layer: vectors,
source: vectors,
tolerance: 0.0001,
eventListeners: {
aftersplit: function(event) {
flashFeatures(event.features);
}
}
});
map.addControl(split);
split.activate();




// add some editing tools to a panel
var panel = new OpenLayers.Control.Panel({
displayClass: "olControlEditingToolbar"
});
draw = new OpenLayers.Control.DrawFeature(
vectors, OpenLayers.Handler.Path,
{ displayClass: "olControlDrawFeaturePoint", title: "Draw Features" }
);
modify = new OpenLayers.Control.ModifyFeature(
vectors, { displayClass: "olControlModifyFeature", title: "Modify Features" }
);
panel.addControls([
new OpenLayers.Control.Navigation({ title: "Navigate" }),
draw, modify
]);
map.addControl(panel);




map.addControl(new OpenLayers.Control.MousePosition());
*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值