Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VIPSWeb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VIPS
VIPSWeb
Merge requests
!12
feat: Add test page (spatial) with mapserver layer in openlayers map
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
feat: Add test page (spatial) with mapserver layer in openlayers map
feature/gridv-6-mapserver-layer
into
develop
Overview
0
Commits
51
Pipelines
0
Changes
2
Merged
Lene Wasskog
requested to merge
feature/gridv-6-mapserver-layer
into
develop
2 years ago
Overview
0
Commits
51
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Viewing commit
c08ce2f1
Prev
Next
Show latest version
2 files
+
39
−
12
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
c08ce2f1
feat: Add simple feature info box under maps
· c08ce2f1
Lene Wasskog
authored
2 years ago
spatial/static/spatial/js/spatialMap.js
0 → 100644
+
150
−
0
Options
/*
* Copyright (c) 2018 NIBIO <http://www.nibio.no/>.
*
* This file is part of VIPSWeb.
* VIPSWeb is free software: you can redistribute it and/or modify
* it under the terms of the NIBIO Open Source License as published by
* NIBIO, either version 1 of the License, or (at your option) any
* later version.
*
* VIPSWeb is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* NIBIO Open Source License for more details.
*
* You should have received a copy of the NIBIO Open Source License
* along with VIPSWeb. If not, see <http://www.nibio.no/licenses/>.
*
*/
/**
* @copyright 2018 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
/* ----------------------- Global elements ------------------- */
var
maxMapZoom
=
10
;
var
warningStatusText
=
{
0
:
'
Sverming av 1. generasjon er over og varslingen er avsluttet
'
,
1
:
'
Mangler data
'
,
2
:
'
Sverming har ikke begynt
'
,
3
:
'
Svermingen er i startfasen
'
,
4
:
'
Svermingen er på sitt mest aktive
'
}
/**
* Initializes the spatial map
* @param {ol.Coordinate} lonLat - coordinates for the map's center (WGS84)
* @param {int} zoomLevel - the zoom level (1-15, 1 is world wide view, 15 is greatest zoom)
* @param {string} mapAttribution - The text in the corner of the map giving credits where it's due
* @param {string} mapId - The unique id of this map
*/
function
initSpatialMap
(
lonLat
,
zoomLevel
,
mapAttribution
,
mapId
)
{
var
map
;
var
carrotLayer
;
var
featureInfoId
=
mapId
+
"
Info
"
;
var
featureInfoDiv
=
document
.
getElementById
(
featureInfoId
);
// ---------- Background layer is OpenStreetMap --------------
var
backgroundLayer
=
new
ol
.
layer
.
Tile
({
source
:
new
ol
.
source
.
OSM
({
attributions
:
[
new
ol
.
Attribution
({
html
:
mapAttribution
})
]
})
});
// Create projection for carrot layer
proj4
.
defs
(
'
EPSG:25833
'
,
'
+proj=utm +zone=33 +ellps=GRS80 +units=m +no_defs
'
);
// Create wms source
var
carrotLayerSource
=
new
ol
.
source
.
ImageWMS
({
url
:
'
https://testvips.nibio.no/cgi-bin/PSILARTEMP
'
,
params
:
{
'
LAYERS
'
:
'
PSILARTEMP_
'
+
(
mapId
==
"
mapToday
"
?
"
TODAY
"
:
"
TOMORROW
"
),
'
TRANSPARENT
'
:
'
TRUE
'
},
serverType
:
'
mapserver
'
,
ratio
:
1
,
projection
:
ol
.
proj
.
get
(
'
EPSG:25833
'
)
})
carrotLayer
=
new
ol
.
layer
.
Image
({
source
:
carrotLayerSource
,
visible
:
true
,
opacity
:
(
mapId
==
"
mapToday
"
?
0.5
:
0.4
)
})
// Creating the map
map
=
new
ol
.
Map
({
target
:
mapId
,
layers
:
[
backgroundLayer
,
carrotLayer
],
renderer
:
'
canvas
'
});
// Setting zoom and center for the map (need to do this after creating map. so that we can transform our
// center to correct map projection)
var
view
=
new
ol
.
View
({
center
:
ol
.
proj
.
transform
(
lonLat
,
'
EPSG:4326
'
,
map
.
getView
().
getProjection
().
getCode
()),
zoom
:
zoomLevel
,
maxMapZoom
:
maxMapZoom
,
});
map
.
setView
(
view
);
map
.
on
(
'
singleclick
'
,
function
(
evt
)
{
const
coordinate
=
proj4
(
'
EPSG:3857
'
,
'
EPSG:25833
'
,
evt
.
coordinate
)
const
url
=
carrotLayerSource
.
getGetFeatureInfoUrl
(
coordinate
,
view
.
getResolution
(),
'
EPSG:25833
'
,
{
'
INFO_FORMAT
'
:
'
text/xml
'
}
);
if
(
url
)
{
fetch
(
url
)
.
then
((
response
)
=>
response
.
text
())
.
then
((
body
)
=>
{
const
parser
=
new
DOMParser
();
const
xmlDOM
=
parser
.
parseFromString
(
body
,
"
text/xml
"
);
const
result
=
xmlDOM
.
getElementsByTagName
(
"
vipsResult
"
)[
0
]
if
(
result
)
{
const
modelName
=
result
.
getElementsByTagName
(
"
modelName
"
)[
0
]
const
warningStatus
=
result
.
getElementsByTagName
(
"
warningStatus
"
)[
0
];
// Calculate position of feature info div
const
mapRect
=
document
.
getElementById
(
mapId
).
getBoundingClientRect
();
const
mapLeft
=
mapRect
.
left
+
window
.
scrollX
;
const
mapTop
=
mapRect
.
top
+
window
.
scrollY
;
const
pixel
=
map
.
getEventPixel
(
evt
.
originalEvent
);
const
clickLeft
=
mapLeft
+
pixel
[
0
]
-
180
;
const
clickTop
=
mapTop
+
pixel
[
1
]
-
100
;
// Hide when warning status is 0
if
(
warningStatus
.
getAttribute
(
'
value
'
)
in
warningStatusText
)
{
featureInfoDiv
.
innerHTML
=
warningStatusText
[
warningStatus
.
getAttribute
(
'
value
'
)];
featureInfoDiv
.
style
.
display
=
'
block
'
;
featureInfoDiv
.
style
.
opacity
=
"
1
"
featureInfoDiv
.
style
.
left
=
clickLeft
+
"
px
"
;
featureInfoDiv
.
style
.
top
=
clickTop
+
"
px
"
;
// Hide the feature info div after the specified duration
var
duration
=
2500
;
setTimeout
(
function
()
{
featureInfoDiv
.
style
.
opacity
=
"
0
"
;
},
duration
);
}
else
{
featureInfoDiv
.
style
.
display
=
'
none
'
;
}
}
});
}
});
}
Loading