-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds function that inserts missing namespace into KML #5860
Changes from 22 commits
912b44e
42482ae
ed093b5
8c9fc84
17c16d5
debc70d
1d424f8
11e2e9d
8107abb
b1122d4
c917ed9
18453b4
ff417d9
b0e69c3
4a82295
b6a2f81
4bc5ba4
c0090b6
d083f44
c782808
24ee426
eafd921
fb67eed
379f27c
af60ced
f65257d
83cd5f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,6 +255,33 @@ define([ | |
return deferred.promise; | ||
} | ||
|
||
function insertNamespaces(text) { | ||
var namespaceMap = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be cleaner to have the following then build the search strings in the loop.
|
||
xsi : 'http://www.w3.org/2001/XMLSchema-instance' | ||
}; | ||
var firstPart, lastPart, reg, declaration; | ||
|
||
for (var key in namespaceMap) { | ||
if (namespaceMap.hasOwnProperty(key)) { | ||
reg = RegExp('[<| ]' + key + ':'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
declaration = 'xmlns:' + key + '='; | ||
if (reg.test(text) && text.indexOf(declaration) === -1) { | ||
if (!firstPart) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tfili do you mean this line should actually use 'defined'? or just check if it's defined? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The magic of javascript's implicit type conversion would cause |
||
firstPart = text.substr(0, text.indexOf('<kml') + 4); | ||
lastPart = text.substr(firstPart.length); | ||
} | ||
firstPart += ' ' + declaration + '"' + namespaceMap[key] + '"'; | ||
} | ||
} | ||
} | ||
|
||
if (firstPart) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
text = firstPart + lastPart; | ||
} | ||
|
||
return text; | ||
} | ||
|
||
function loadXmlFromZip(reader, entry, uriResolver, deferred) { | ||
entry.getData(new zip.TextWriter(), function(text) { | ||
uriResolver.kml = parser.parseFromString(text, 'application/xml'); | ||
|
@@ -2322,6 +2349,9 @@ define([ | |
//There's no official way to validate if a parse was successful. | ||
//The following check detects the error on various browsers. | ||
|
||
//Insert missing namespaces | ||
text = insertNamespaces(text); | ||
|
||
//IE raises an exception | ||
var kml; | ||
var error; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<kml xmlns="http://www.opengis.net/kml/2.2"> | ||
<Document xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd http://www.google.com/kml/ext/2.2 http://code.google.com/apis/kml/schema/kml22gx.xsd"> | ||
<Placemark> | ||
<Style> | ||
<IconStyle> | ||
<Icon> | ||
<href>image.png</href> | ||
</Icon> | ||
</IconStyle> | ||
</Style> | ||
<description><![CDATA[image.png <a href="./image.png">image.png</a><img src="image.png"/>]]></description> | ||
<Point> | ||
<coordinates>1,2,3</coordinates> | ||
</Point> | ||
</Placemark> | ||
</Document> | ||
</kml> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.38 Came out already. Needs to be updated for 1.39 which will be released Nov 1.