diff --git a/examples/geojson-reprojected.html b/examples/geojson-reprojected.html new file mode 100644 index 0000000000..2e606387ca --- /dev/null +++ b/examples/geojson-reprojected.html @@ -0,0 +1,46 @@ + + + + + + + OpenLayers GeoJSON Reprojected Example + + + + + +

GeoJSON Reprojected

+ +
+ geojson, bing, projection +
+ +
Display GeoJSON data over Bing tiles
+ +
+ +
+

This example demonstrates the use of GeoJSON over Bing tiles. The + GeoJSON vector data is in geographic coordinates (EPSG:4326). The Bing + tiles are in a spherical mercator projection (EPSG:900913). By setting + the projection property of the GeoJSON layer to the source + projection (EPSG:4326), the features are properly displayed over the + base layer. In general, the map projection determines how raster or + vector data is displayed. The layer projection corresponds to the + projection of the data source. +

See the + geojson-reprojected.js + source for details on how this is done.

+
+ + + + diff --git a/examples/geojson-reprojected.js b/examples/geojson-reprojected.js new file mode 100644 index 0000000000..d54c6e9d9d --- /dev/null +++ b/examples/geojson-reprojected.js @@ -0,0 +1,27 @@ +// API key for http://openlayers.org. Please get your own at +// http://bingmapsportal.com/ and use that instead. +var apiKey = "AqTGBsziZHIJYYxgivLBf0hVdrAk9mWO5cQcb8Yux8sW5M8c8opEC2lZqKR1ZZXf"; + +var hybrid = new OpenLayers.Layer.Bing({ + key: apiKey, + type: "AerialWithLabels", + name: "Bing Aerial With Labels" +}); + +var vector = new OpenLayers.Layer.Vector("GeoJSON", { + projection: "EPSG:4326", + strategies: [new OpenLayers.Strategy.Fixed()], + protocol: new OpenLayers.Protocol.HTTP({ + url: "geojson-reprojected.json", + format: new OpenLayers.Format.GeoJSON() + }) +}); + +var center = new OpenLayers.LonLat(-109.6, 46.7).transform("EPSG:4326", "EPSG:900913"); + +var map = new OpenLayers.Map({ + div: "map", + layers: [hybrid, vector], + center: center, + zoom: 4 +}); diff --git a/examples/geojson-reprojected.json b/examples/geojson-reprojected.json new file mode 100644 index 0000000000..82153faa67 --- /dev/null +++ b/examples/geojson-reprojected.json @@ -0,0 +1 @@ +{"type":"FeatureCollection","features":[{"type":"Feature","id":"USA-MT","properties":{"fips":"30","name":"Montana"},"geometry":{"type":"Polygon","coordinates":[[[-104.047534,49.000239],[-104.042057,47.861036],[-104.047534,45.944106],[-104.042057,44.996596],[-104.058488,44.996596],[-105.91517,45.002073],[-109.080842,45.002073],[-111.05254,45.002073],[-111.047063,44.476286],[-111.227803,44.580348],[-111.386634,44.75561],[-111.616665,44.547487],[-111.819312,44.509148],[-111.868605,44.563917],[-112.104113,44.520102],[-112.241036,44.569394],[-112.471068,44.481763],[-112.783254,44.48724],[-112.887315,44.394132],[-113.002331,44.448902],[-113.133778,44.772041],[-113.341901,44.782995],[-113.456917,44.865149],[-113.45144,45.056842],[-113.571933,45.128042],[-113.736241,45.330689],[-113.834826,45.522382],[-113.807441,45.604536],[-113.98818,45.703121],[-114.086765,45.593582],[-114.333228,45.456659],[-114.546828,45.560721],[-114.497536,45.670259],[-114.568736,45.774321],[-114.387997,45.88386],[-114.492059,46.037214],[-114.464674,46.272723],[-114.322274,46.645155],[-114.612552,46.639678],[-114.623506,46.705401],[-114.886399,46.809463],[-114.930214,46.919002],[-115.302646,47.187372],[-115.324554,47.258572],[-115.527201,47.302388],[-115.718894,47.42288],[-115.724371,47.696727],[-116.04751,47.976051],[-116.04751,49.000239],[-111.50165,48.994762],[-109.453274,49.000239],[-104.047534,49.000239]]]}}]}