配置了Geoserver和PostGIS DB的Openshift ......现在怎样?

时间:2015-07-08 21:48:08

标签: openshift geoserver

我已经在openshift上设置了geoserver和POSTGIS数据库。我可以确认我在数据库中有数据,因为我可以使用QGIS连接到它并添加图层....现在我正在尝试使用一个图层创建一个简单的地图但是找不到任何关于此的教程...下面代码与本地数据实例一起工作以创建一个简单的地图...我在openshift上创建的图层使用什么网址?我似乎无法找到它们。

<!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">
<head>
<title>OGR2Layers</title>
<style>
 #map{width:400px;height:400px;}
</style>
<script src="http://www.openlayers.org/api/2.13/OpenLayers.js"></script>
<script type="text/javascript">
var map, selectsControls
function init(){
    var option = {
        projection: new OpenLayers.Projection("EPSG:900913"),
        displayProjection: new OpenLayers.Projection("EPSG:4326")
    };
    map = new OpenLayers.Map('map', option);
    var attribution = {attribution:"&copy; <a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a> contributors"};
    olmapnik = new OpenLayers.Layer.OSM("OpenStreetMap Mapnik", "http://tile.openstreetmap.org/${z}/${x}/${y}.png", attribution);
    map.addLayer(olmapnik);
    map.setBaseLayer(olmapnik);
    var ls= new OpenLayers.Control.LayerSwitcher(); 
    map.addControl(ls); 
    ls.maximizeControl(); 
    map.addControl(new OpenLayers.Control.MousePosition());
    map.addControl(new OpenLayers.Control.Navigation());
    var block = new OpenLayers.Layer.Vector("block GeoJSON", {
        protocol: new OpenLayers.Protocol.HTTP({
            url: "block.GeoJSON",
            format: new OpenLayers.Format.GeoJSON()
        }),
        strategies: [
            new OpenLayers.Strategy.Fixed()
        ]
    });
    map.addLayer(block);
    extent = new OpenLayers.Bounds(-97.640446,21.693337,-80.768595,32.375889).transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
    map.zoomToExtent(extent);
};
</script>
</head>
<body onload="init()">
<h1>this is a test</h1>
<div id="map"></div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

基于此example,我认为您需要将http://demo.boundlessgeo.com/geoserver更改为您为openshift实例提供的域名:

// format used to parse WFS GetFeature responses
var geojsonFormat = new ol.format.GeoJSON();

var vectorSource = new ol.source.Vector({
  loader: function(extent, resolution, projection) {
    var url = 'http://demo.boundlessgeo.com/geoserver/wfs?service=WFS&' +
        'version=1.1.0&request=GetFeature&typename=osm:water_areas&' +
        'outputFormat=text/javascript&format_options=callback:loadFeatures' +
        '&srsname=EPSG:3857&bbox=' + extent.join(',') + ',EPSG:3857';
    // use jsonp: false to prevent jQuery from adding the "callback"
    // parameter to the URL
    $.ajax({url: url, dataType: 'jsonp', jsonp: false});
  },
  strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({
    maxZoom: 19
  }))
});