Skip to content

Commit

Permalink
Moved domparser outside of the wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
aviklai committed May 1, 2020
1 parent 6761b86 commit f1237a3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { Map } from 'react-leaflet';
import ReactLeafletKml from 'react-leaflet-kml';
const kmlText='YOUR KML FILE AS TEXT';
const parser = new DOMParser();
const kml = parser.parseFromString(kmlText, 'text/xml');
export class App extends React.Component {
render() {
Expand All @@ -22,7 +24,7 @@ export class App extends React.Component {
<TileLayer url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
attribution="&copy; <a href=&quot;http://osm.org/copyright&quot;>OpenStreetMap</a> contributors"
/>
<ReactLeafletKml kml={kmlText} />
<ReactLeafletKml kml={kml} />
</Map>
);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-leaflet-kml",
"version": "1.0.2",
"version": "1.0.3",
"description": "React leaflet wrapper of leaflet-kml",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/ReactLeafletKml.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test('ReactLeafletKml', () => {

const component = ReactTestUtils.renderIntoDocument(
<Map>
<ReactLeafletKml kml='' />
<ReactLeafletKml kml={new Document()}/>
</Map>
) as any;
expect(component.leafletElement._container).toBeDefined()
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { ContextProps, MapLayer, withLeaflet } from 'react-leaflet';
import 'leaflet-kml';

interface IProps extends ContextProps {
kml: string;
kml: XMLDocument;
}

class ReactLeafletKml extends MapLayer<IProps> {
public createLeafletElement(props: IProps) {
const { kml } = props;
this.leafletElement = new L.KML(new DOMParser().parseFromString(kml, "text/xml"));
this.leafletElement = new L.KML(kml);
if (this.props.leaflet.map.options.preferCanvas) {
setTimeout((map: LeafletContext.map) => {
// Handling react-leaflet bug of canvas renderer not updating
Expand Down

0 comments on commit f1237a3

Please sign in to comment.