-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathopenlayersReader.py
59 lines (51 loc) · 2.37 KB
/
openlayersReader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
"""
/***************************************************************************
openlayers
A QGIS plugin
Load a webmap directly into QGIS
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
-------------------
begin : 2018-05-11
git sha : $Format:%H$
copyright : (C) 2018 by Tom Chadwin
email : tom.chadwin@nnpa.org.uk
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
import os
from web2qgis.utils import getTempDir, getScript
from web2qgis.qgisWriter import addWMS, addXYZ, addVector, setExtent
def detectOpenlayers(mainframe):
detectResult = mainframe.evaluateJavaScript("ol")
if detectResult is None:
result = False
else:
result = True
return result
def getOpenlayersMap(mainframe, iface):
tempDir = getTempDir()
scriptFolder = os.path.join(os.path.dirname(__file__), "js")
getMapScript = getScript(scriptFolder, "getOpenlayersMap.js")
lyrs = mainframe.evaluateJavaScript(getMapScript)
for count, lyr in enumerate(lyrs):
if lyr[0] == "wms":
addWMS(lyr[1], lyr[2], lyr[3], iface)
elif lyr[0] == "xyz":
addXYZ(lyr[1], lyr[2], iface)
elif lyr[0] == "vector":
addVector(lyr[1], count, tempDir)
else:
print("Unsupported layer type")
getOpenlayersView(scriptFolder, mainframe, iface)
def getOpenlayersView(scriptFolder, mainframe, iface):
getExtentScript = getScript(scriptFolder, "getOpenlayersView.js")
extent = mainframe.evaluateJavaScript(getExtentScript)
setExtent(extent[0], extent[1], extent[2], extent[3], iface)