将OpenStreetMap构建为WordPress自定义插件

时间:2019-05-22 02:06:02

标签: javascript wordpress plugins openlayers openstreetmap

我正在构建一个WordPress插件,涉及使用地图和用户创建的自定义标记。我想将地图与标记分开,以便用户可以跨地图平台创建自定义标记,并将标记数据保留在该页面上。

我在树莓派3 B上设置了一个开发服务器,它带有一个2 TB的硬盘驱动器。我设置了北美的OpenStreetMap磁贴服务器进行练习,并在/ var / www / html中找到并通过html文件运行该文件,该文件通过一个LAMP服务器运行,该服务器还包括我的WordPress开发Web服务器。

    <html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
    <title>Public Transport Lines - &Ouml;V-Linien - openptmap.org</title>
    <link rel="shortcut icon" href="favicon_pt.png">
    <link rel="stylesheet" href="style.css" type="text/css">
    <style>  /* avoid empty tiles */ .olImageLoadError {display: none;} 
    </style>
    <script src="OpenLayers.js" type="text/javascript"></script>
    <script src="OpenStreetMap.js" type="text/javascript"></script>
    <script type="text/javascript">
    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);
}
</script>
</head>
<body onload="init();">
<div style="width:100%; height:100%;" id="map"></div><br></body>
    </html>

这是我创建的示例标记的示例,可以使用短代码链接到我的插件中,但是我无法让脚本在插件本身中运行并在地图上显示结果。

例如,当我在仅连接到纯map.html iframe的插件中运行此脚本时,它什么都不做。

0 个答案:

没有答案