OpenLayers:在asp .net网页中嵌入地图

时间:2014-08-27 11:14:52

标签: javascript asp.net maps openlayers openstreetmap

我要求在地图上使用lat和long在带有标记的开放街道地图上显示地点。我在谷歌搜索后尝试了一些代码。但什么都没有。我提供了我的代码和一些我尝试过的示例链接。

<head runat="server">
  <title>OpenLayers Simplest Example</title>
  <script src="OpenLayers.js" type="text/javascript"></script>
  <script src="osm-marker-popup.js" type="text/javascript"></script>
</head>
<body onload="init()">
  <form id="form1" runat="server">
    <h1 id="title">
     OSM with Marker and Popup</h1>
     <p id="shortdesc">
       Demonstrate use of an OSM layer with a marker and a popup.
     </p>
     <div id="tags">
        openstreetmap osm marker popup
     </div>
     <div id="map">
     </div>
     <div id="docs">
        <p>
            A common use case for OpenLayers is to display a marker at a location on the map,
            and add some information in a popup. It is also easy to add a tooltip with a short
            description. See the <a href="osm-marker-popup.js" target="_blank">osm-marker-popup.js
            source</a> to see how this is done.
        </p>
    </div>
</form>

osm-marker-popup.js代码

var map;
function init() {

// The overlay layer for our marker, with a simple diamond as symbol
var overlay = new OpenLayers.Layer.Vector('Overlay', {
    styleMap: new OpenLayers.StyleMap({
        externalGraphic: '../img/marker.png',
        graphicWidth: 20, graphicHeight: 24, graphicYOffset: -24,
        title: '${tooltip}'
    })
});

// The location of our marker and popup. We usually think in geographic
// coordinates ('EPSG:4326'), but the map is projected ('EPSG:3857').
var myLocation = new OpenLayers.Geometry.Point(10.2, 48.9)
    .transform('EPSG:4326', 'EPSG:3857');

// We add the marker with a tooltip text to the overlay
overlay.addFeatures([
    new OpenLayers.Feature.Vector(myLocation, { tooltip: 'OpenLayers' })
]);

// A popup with some information about our location
var popup = new OpenLayers.Popup.FramedCloud("Popup",
    myLocation.getBounds().getCenterLonLat(), null,
    '<a target="_blank" href="http://openlayers.org/">We</a> ' +
    'could be here.<br>Or elsewhere.', null,
    true // <-- true if we want a close (X) button, false otherwise
);

// Finally we create the map
map = new OpenLayers.Map({
    div: "map", projection: "EPSG:3857",
    layers: [new OpenLayers.Layer.OSM(), overlay],
    center: myLocation.getBounds().getCenterLonLat(), zoom: 15
});
// and add the popup to it.
  map.addPopup(popup);
}

链接。 http://wiki.openstreetmap.org/wiki/OpenLayers_Simple_Example http://wiki.openstreetmap.org/wiki/Openlayers_POI_layer_example http://wiki.openstreetmap.org/wiki/OpenLayers_Marker

1 个答案:

答案 0 :(得分:0)

变化

 <script src="OpenLayers.js" type="text/javascript"></script>

 <script src="http://openlayers.org/api/OpenLayers.js"></script>