[OpenLayers-Users] Newby: Display geoJSON Layer
Arnd Wippermann
arnd.wippermann at web.de
Tue Jun 4 13:00:33 PDT 2013
Hi,
there is nothing wrong, but something missing. You use an unusual projection
for OpenLayers.
OL needs to calculate the resolutions for the zoomlevels. For projection
EPSG:4326 and EPSG:900913 there are default resolutions.
Add maxExtent to your map options, then your features should displayed.
To get the extends of a geoJSON file, you can register "loadend" for the
layer and calculate the extent.
GeoJSONLayer.events.register('loadend', GeoJSONLayer, function(){
var extent = GeoJSONLayer.getDataExtent().toBBOX().replace(/,/g,", ");
alert("GeoJSONLayer dataExtent: " + extent);
});
little example with features from GeoJSON in projection EPSG:31466:
http://gis.ibbeck.de/ginfo/apps/OLExamples/OL212/BaseLayers/geoJson%20BaseLa
yer.asp
Arnd
_____
Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von Helmut
Seidel M.A.
Gesendet: Dienstag, 4. Juni 2013 13:52
An: openlayers-users at lists.osgeo.org
Betreff: [OpenLayers-Users] Newby: Display geoJSON Layer
Hello everybody,
Im absolutely new to OpenLayers For a start I wanted to check out the
possibilities of OpenLayers and display a geoJSON-Layer which should act as
the base layer. The layer uses the projection ESPSG 31468 / DHDN /
Gauss-Krüger 4.
To say it in plain words Im not too successfull in this, as nothing is
displayed.
I tried the following code which I copied from various sources:
<html>
<head>
<script src="Lib/OpenLayers.js"></script>
<script type="text/javascript">
var map;
function init(){
var lon = 4596651.93;
var lat = 5355977.11;
map = new
OpenLayers.Map('map', {
projection:
"EPSG:31468"
});
var kmlLayer = new
OpenLayers.Layer.Vector("GeoJSON", {
isBaseLayer:
true,
strategies:
[new OpenLayers.Strategy.Fixed()],
protocol: new
OpenLayers.Protocol.HTTP({
url: "flurstuecke.json",
format: new OpenLayers.Format.GeoJSON()
})
});
map.addLayers([kmlLayer]);
map.addControl(new
OpenLayers.Control.MousePosition());
map.setCenter(new
OpenLayers.LonLat(lon, lat), 10);
}
</script>
</head>
<body onload="init()">
<div id="map" style="width:300px;
height:300px;
border: 1px solid
black;"></div>
</body>
</html>
Can anybody tell me whats wrong with it?
By the way, how is it possible to retrive the extends of a geoJSON file?
Thank you all and regards
---
KnowHow - Helmut Seidel M.A.
Softwareentwicklung & Coaching
Gabelsbergerstraße 17 B
84034 Landshut
Telefon: 0871 9665230
Internet: www.knowhow-la.de
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20130604/c15534fb/attachment.html>
More information about the Users
mailing list