Skip to content

Commit

Permalink
Merge pull request georchestra#26 from neogeo-technologies/srs_custom
Browse files Browse the repository at this point in the history
Allow map SRS customisation
  • Loading branch information
fphg committed Nov 15, 2016
2 parents f5322a6 + b5d7451 commit 1bf049a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
5 changes: 5 additions & 0 deletions etc/customConfig.DIST.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ customConfig = {
*/
geOrchestraBaseUrl: 'https://sdi.georchestra.org/',

/**
* projection
*/
projcode: 'EPSG:3857',

/**
* map bounds
*/
Expand Down
40 changes: 14 additions & 26 deletions js/sviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,13 @@ proj4.defs([
["EPSG:900913", "+title=Web Spherical Mercator, +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs"],
["EPSG:2154", "+title=RGF-93/Lambert 93, +proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"]
]);
// map projection and grids
var projcode = 'EPSG:3857';
var projection = ol.proj.get(projcode);
var projectionExtent = projection.getExtent();
var size = ol.extent.getWidth(projectionExtent) / 256;
var resolutions = new Array(20);
var matrixIds = new Array(20);
for (var z = 0; z < 20; ++z) {
resolutions[z] = size / Math.pow(2, z);
matrixIds[z] =projcode + ':' + z;
}

var config = {};
var customConfig = {};
var hardConfig = {
title: 'geOrchestra mobile',
geOrchestraBaseUrl: 'https://sdi.georchestra.org/',
projection: projection,
projcode: 'EPSG:3857',
initialExtent: [-12880000,-1080000,5890000,7540000],
maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34],
restrictedExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34],
Expand All @@ -33,12 +22,7 @@ var hardConfig = {
openLSGeocodeUrl: "http://gpp3-wxs.ign.fr/[CLEF GEOPORTAIL]/geoportail/ols?",
layersBackground: [
new ol.layer.Tile({
preload: 2,
source: new ol.source.MapQuest({layer: 'osm'})
}),
new ol.layer.Tile({
preload: 2,
source: new ol.source.MapQuest({layer: 'sat'})
source: new ol.source.OSM()
})
],
socialMedia: {
Expand All @@ -49,8 +33,6 @@ var hardConfig = {
};




var SViewer = function() {
var map;
var view;
Expand Down Expand Up @@ -382,7 +364,7 @@ var SViewer = function() {
var vgb = $(wmc).children('General').children('BoundingBox');
var srs = vgb.attr('SRS');
var extent = [vgb.attr('minx'), vgb.attr('miny'), vgb.attr('maxx'), vgb.attr('maxy')];
view.fit(ol.proj.transformExtent(extent, srs, projcode), map.getSize());
view.fit(ol.proj.transformExtent(extent, srs, config.projcode), map.getSize());
}

// we only consider visible and queryable layers
Expand Down Expand Up @@ -547,7 +529,7 @@ var SViewer = function() {
var a = res.getElementsByTagNameNS('http://www.opengis.net/gml', 'pos')[0].textContent.split(' '),
lonlat = [parseFloat(a[1]), parseFloat(a[0])],
matchType = results.find('GeocodeMatchCode').attr('matchType'),
ptResult = ol.proj.transform(lonlat, 'EPSG:4326', projcode),
ptResult = ol.proj.transform(lonlat, 'EPSG:4326', config.projcode),
street = $(res).find("Street").text(),
municipality = $(res).find('[type="Municipality"]').text();
switch (matchType) {
Expand Down Expand Up @@ -695,7 +677,7 @@ ol.extent.getTopRight(extent).reverse().join(" "),
var url = this.wmslayer.getSource().getGetFeatureInfoUrl(
config.gficoord,
viewResolution,
projection,
config.projection,
{'INFO_FORMAT': 'text/html',
'FEATURE_COUNT': config.maxFeatures}
);
Expand Down Expand Up @@ -1112,7 +1094,7 @@ ol.extent.getTopRight(extent).reverse().join(" "),

// recenter on device position
function showPosition(pos) {
var p = ol.proj.transform([pos.coords.longitude, pos.coords.latitude], 'EPSG:4326', projcode),
var p = ol.proj.transform([pos.coords.longitude, pos.coords.latitude], 'EPSG:4326', config.projcode),
start = +new Date(),
pan = ol.animation.pan({
duration: 1000,
Expand Down Expand Up @@ -1217,6 +1199,8 @@ ol.extent.getTopRight(extent).reverse().join(" "),
$.extend(config, hardConfig);
$.extend(config, customConfig);

config.projection = ol.proj.get(config.projcode);

// querystring param: lb (selected background)
if (qs.lb) {
config.lb = parseInt(qs.lb) % config.layersBackground.length;
Expand Down Expand Up @@ -1259,7 +1243,7 @@ ol.extent.getTopRight(extent).reverse().join(" "),
var p = [parseFloat(qs.x), parseFloat(qs.y)];
// is this lonlat ? anyway don't use sviewer for the vendee globe
if (Math.abs(p[0])<=180&&Math.abs(p[1])<=180&&config.z>7) {
p = ol.proj.transform(p, 'EPSG:4326', projcode);
p = ol.proj.transform(p, 'EPSG:4326', config.projcode);
}
config.x = p[0];
config.y = p[1];
Expand Down Expand Up @@ -1298,7 +1282,11 @@ ol.extent.getTopRight(extent).reverse().join(" "),
*/
function doMap() {
// map creation
view = new ol.View();
view = new ol.View({
projection: config.projection
});
console.log(config.projection);
console.log(config.projcode);
map = new ol.Map({
controls: [
new ol.control.ScaleLine(),
Expand Down

0 comments on commit 1bf049a

Please sign in to comment.