I've got a problem with (the title says it) integrating a geojson file in my openlayers map. I have to use the openlayers.protocol.http way. I examined lots of examples on the web (and on stackexchange) but I cannot figure out what the problem with my exact code is. it shows the layer in the layerswitcher, but it doesn't show the features.
I hope someone can find the error. Here's my code (relating geojson):
WebMapping - Übung 12
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
var map;
function initMap() {
map = new OpenLayers.Map("openlayers");
var mapnik = new OpenLayers.Layer.OSM();
map.addLayer(mapnik);
var mapCenter = new OpenLayers.LonLat(8.692, 49.412);
mapCenter.transform(
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection
)
ZoomLevel 15 setzen
map.setCenter(mapCenter, 15);
map.addControl(new OpenLayers.Control.ScaleLine());
map.addControl(new OpenLayers.Control.OverviewMap());
map.addControl(new OpenLayers.Control.MousePosition());
map.addControl(new OpenLayers.Control.LayerSwitcher());
// map.addControl(new OpenLayers.Control.SelectFeature(cities,{autoActivate:true, hover:true, onSelect:addPopup, onUnselect:removePopup}));
var geojsonURL = "wikiCities.geojson";
cities = new OpenLayers.Layer.Vector("Städte", {
styleMap: new OpenLayers.StyleMap({
"default": new OpenLayers.Style({
pointRadius: 5,
fillColor: "#ffcc66",
fillOpacity: 0.8,
strokeColor: "#cc6633",
strokeWidth: 2,
strokeOpacity: 0.8 } ),
"select": { fillColor: "#8aeeef",
strokeColor: "#32a8a9",
labelYOffset:13,
label:"${name}"} //Text entspricht feature.attributes.name
}),
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: geojsonURL,
format: new OpenLayers.Format.GeoJSON({
externalProjection: new OpenLayers.Projection("EPSG:4326"),
internalProjection: new OpenLayers.Projection("EPSG:900913")
})
})
});
map.addLayer(cities);
}
window.onload = initMap;
</script>
<style type="text/css">
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
#header{
height:3em;
}
#wiki {
position: absolute;
right: 10px;
height:91%;
width: 49%;
top:3em;
}
#openlayers {
position: absolute;
width: 49%;
top: 3em;
left: 10;
bottom: 2em;
}
#info {
position: absolute;
height: 1em;
left: 10;
right: 0;
bottom: 0;
padding: 0.5em;
text-align: right;
}
</style>
Ihr Browser unterstützt keine Inlineframes
Wikipedia-Integration in OpenLayers
</div>
<div id="info">
</div>