From 7cf2e54790571e160541b65aab2326fbf2c470e0 Mon Sep 17 00:00:00 2001 From: Keith Moss Date: Wed, 25 Apr 2018 14:51:25 +0800 Subject: [PATCH] Adding layers to the map once it has been created now works --- dist/layers/vector-tile.js | 4 ++++ dist/layers/vector-tile.js.map | 2 +- package.json | 5 ++++- src/layers/vector-tile.tsx | 5 +++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/dist/layers/vector-tile.js b/dist/layers/vector-tile.js index 2312fae..3876aa1 100644 --- a/dist/layers/vector-tile.js +++ b/dist/layers/vector-tile.js @@ -72,6 +72,10 @@ var VectorTile = /** @class */ (function (_super) { this.layer.setZIndex(this.props.zIndex); } this.props.mapComp.layers.push(this.layer); + // If the map has already been mounted then we need to manually add the layer to the OL Map + if ("map" in this.props.mapComp) { + this.props.mapComp.map.addLayer(this.layer); + } var olEvents = util_1.Util.getEvents(this.events, this.props); for (var eventName in olEvents) { this.layer.on(eventName, olEvents[eventName]); diff --git a/dist/layers/vector-tile.js.map b/dist/layers/vector-tile.js.map index 7431ce7..d033946 100644 --- a/dist/layers/vector-tile.js.map +++ b/dist/layers/vector-tile.js.map @@ -1 +1 @@ -{"version":3,"file":"vector-tile.js","sourceRoot":"","sources":["../../src/layers/vector-tile.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,6BAA8B;AAE9B,kDAAmD;AACnD,gCAA8B;AAC9B,8BAAwC;AAExC;IAAyB,8BAAyB;IAoC9C,oBAAY,KAAK;QAAjB,YACI,kBAAM,KAAK,CAAC,SACf;QAnCD,aAAO,GAAQ;YACX,YAAY,EAAE,SAAS;YACvB,UAAU,EAAE,SAAS;YACrB,WAAW,EAAE,SAAS;YACtB,MAAM,EAAE,SAAS;YACjB,aAAa,EAAE,SAAS;YACxB,aAAa,EAAE,SAAS;YACxB,OAAO,EAAE,SAAS;YAClB,OAAO,EAAE,SAAS;YAClB,MAAM,EAAE,SAAS;YACjB,KAAK,EAAE,SAAS;YAChB,oBAAoB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SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;aACzC;YACD,IAAI,QAAQ,IAAI,SAAS,IAAI,SAAS,CAAC,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;gBACjE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;aACzC;YAED,yEAAyE;YACzE,iDAAiD;YACjD,8CAA8C;YAC9C,+BAA+B;YAC/B,wCAAwC;YACxC,IAAI;YACJ,2BAA2B;YAC3B,8CAA8C;YAC9C,IAAI;YACJ,8CAA8C;YAE9C,yDAAyD;YACzD,oCAAoC;YACpC,oDAAoD;YACpD,IAAI;SACP;IACL,CAAC;IAED,yCAAoB,GAApB;QACI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAClD,CAAC;IACL,iBAAC;AAAD,CAAC,AA1GD,CAAyB,KAAK,CAAC,SAAS,GA0GvC;AAED,mBAAe,UAAA,KAAK,IAAI,OAAA,oBAAC,gBAAU,CAAC,QAAQ,QAAE,UAAA,OAAO,IAAI,OAAA,oBAAC,UAAU,eAAK,KAAK,IAAE,OAAO,EAAE,OAAO,IAAI,EAA3C,CAA2C,CAAuB,EAAnG,CAAmG,EAAA"} \ No newline at end of file +{"version":3,"file":"vector-tile.js","sourceRoot":"","sources":["../../src/layers/vector-tile.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,6BAA8B;AAE9B,kDAAmD;AACnD,gCAA8B;AAC9B,8BAAwC;AAExC;IAAyB,8BAAyB;IAoC9C,oBAAY,KAAK;QAAjB,YACI,kBAAM,KAAK,CAAC,SACf;QAnCD,aAAO,GAAQ;YACX,YAAY,EAAE,SAAS;YACvB,UAAU,EAAE,SAAS;YACrB,WAAW,EAAE,SAAS;YACtB,MAAM,EAAE,SAAS;YACjB,aAAa,EAAE,SAAS;YACxB,aAAa,EAAE,SAAS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AY,IAAI,SAAS,IAAI,SAAS,CAAC,UAAU,KAAK,SAAS,EAAE;gBACjE,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,UAAU,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAA;aACxE;YACD,IAAI,QAAQ,IAAI,SAAS,IAAI,SAAS,CAAC,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;gBACjE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;aACzC;YACD,IAAI,QAAQ,IAAI,SAAS,IAAI,SAAS,CAAC,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;gBACjE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;aACzC;YAED,yEAAyE;YACzE,iDAAiD;YACjD,8CAA8C;YAC9C,+BAA+B;YAC/B,wCAAwC;YACxC,IAAI;YACJ,2BAA2B;YAC3B,8CAA8C;YAC9C,IAAI;YACJ,8CAA8C;YAE9C,yDAAyD;YACzD,oCAAoC;YACpC,oDAAoD;YACpD,IAAI;SACP;IACL,CAAC;IAED,yCAAoB,GAApB;QACI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAClD,CAAC;IACL,iBAAC;AAAD,CAAC,AA/GD,CAAyB,KAAK,CAAC,SAAS,GA+GvC;AAED,mBAAe,UAAA,KAAK,IAAI,OAAA,oBAAC,gBAAU,CAAC,QAAQ,QAAE,UAAA,OAAO,IAAI,OAAA,oBAAC,UAAU,eAAK,KAAK,IAAE,OAAO,EAAE,OAAO,IAAI,EAA3C,CAA2C,CAAuB,EAAnG,CAAmG,EAAA"} \ No newline at end of file diff --git a/package.json b/package.json index a1174ed..7aa4e9b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-openlayers", - "version": "0.2.4", + "version": "0.2.5", "description": "OpenLayer React Components", "license": "MIT", "main": "dist/index.js", @@ -16,6 +16,9 @@ "build:app": "cross-env NODE_ENV=production webpack --config app/webpack.config", "types": "dts-generator --name react-openlayers --project . --out dist/index.d.ts", "copy:static": "cp src/map.css dist/map.css && cp src/custom/popup.css dist/custom/popup.css", + "packy": "npm pack && mv react-openlayers-0.2.1.tgz /Users/keithmoss/Downloads/react-openlayers-0.2.1.tgz", + "wml:add": "wml add ./ /Users/keithmoss/Documents/Work/GitHub/ealgis-yarn/frontend/node_modules/react-openlayers", + "wml:start": "wml start", "upgrade": "npm-check-updates -a/--upgradeAll && npm i" }, "repository": { diff --git a/src/layers/vector-tile.tsx b/src/layers/vector-tile.tsx index 40caad5..e93f2b0 100644 --- a/src/layers/vector-tile.tsx +++ b/src/layers/vector-tile.tsx @@ -57,7 +57,12 @@ class VectorTile extends React.Component { if (this.props.zIndex) { this.layer.setZIndex(this.props.zIndex) } + this.props.mapComp.layers.push(this.layer) + // If the map has already been mounted then we need to manually add the layer to the OL Map + if ("map" in this.props.mapComp) { + this.props.mapComp.map.addLayer(this.layer) + } let olEvents = Util.getEvents(this.events, this.props) for (let eventName in olEvents) {