From 587512cac841e85095ed08d530cf1309c2883a17 Mon Sep 17 00:00:00 2001 From: Petr Pridal Date: Sat, 23 Jun 2012 23:06:45 +0200 Subject: [PATCH] Introduced "ol.API" @define which will allow in future to compile HPI apps with the OL. Discussed in ol3-sprint mailing-list. --- api.json | 3 ++- src/api/bounds.js | 10 +++++----- src/api/feature.js | 6 +++--- src/api/geom/point.js | 8 ++++---- src/api/layer/wms.js | 6 +++--- src/api/layer/xyz.js | 2 +- src/api/loc.js | 8 ++++---- src/api/map.js | 22 +++++++++++----------- src/api/popup.js | 10 +++++----- src/api/projection.js | 8 ++++---- src/ol/base.js | 7 +++++++ 11 files changed, 49 insertions(+), 41 deletions(-) diff --git a/api.json b/api.json index 9e591fcf31..7bd07e492e 100644 --- a/api.json +++ b/api.json @@ -16,7 +16,8 @@ "define": { // "goog.dom.ASSUME_STANDARDS_MODE": true, // "goog.userAgent.ASSUME_MOBILE_WEBKIT": true, - "goog.DEBUG": false + "goog.DEBUG": false, + "ol.API" : true }, "mode": "ADVANCED", diff --git a/src/api/bounds.js b/src/api/bounds.js index 378b3d2914..9575ba0c7b 100644 --- a/src/api/bounds.js +++ b/src/api/bounds.js @@ -39,11 +39,11 @@ ol.bounds = function(opt_arg){ maxY = opt_arg[3]; } else if (goog.isObject(opt_arg)) { ol.base.checkKeys(opt_arg, ['minX', 'minY', 'maxX', 'maxY', 'projection']); - minX = opt_arg['minX']; - minY = opt_arg['minY']; - maxX = opt_arg['maxX']; - maxY = opt_arg['maxY']; - projection = ol.projection(opt_arg['projection']); + minX = ol.API ? opt_arg['minX'] : opt_arg.minX; + minY = ol.API ? opt_arg['minY'] : opt_arg.minY; + maxX = ol.API ? opt_arg['maxX'] : opt_arg.maxX; + maxY = ol.API ? opt_arg['maxY'] : opt_arg.maxY; + projection = ol.projection(ol.API ? opt_arg['projection'] : opt_arg.projection); } else { throw new Error('ol.bounds'); diff --git a/src/api/feature.js b/src/api/feature.js index 6006f3259f..62b3b8ce26 100644 --- a/src/api/feature.js +++ b/src/api/feature.js @@ -31,9 +31,9 @@ ol.feature = function(opt_arg){ } else if (goog.isObject(opt_arg)) { ol.base.checkKeys(opt_arg, ['geometry', 'properties', 'type']); - properties = opt_arg['properties']; - geometry = opt_arg['geometry']; - type = opt_arg['type']; + properties = ol.API ? opt_arg['properties'] : opt_arg.properties; + geometry = ol.API ? opt_arg['geometry'] : opt_arg.geometry; + type = ol.API ? opt_arg['type'] : opt_arg.type; } else { throw new Error('ol.feature'); diff --git a/src/api/geom/point.js b/src/api/geom/point.js index bf8434b243..e9dab7648c 100644 --- a/src/api/geom/point.js +++ b/src/api/geom/point.js @@ -32,10 +32,10 @@ ol.geom.point = function(opt_arg){ projection = opt_arg[3]; } else if (goog.isObject(opt_arg)) { - x = opt_arg['x']; - y = opt_arg['y']; - z = opt_arg['z']; - projection = opt_arg['projection']; + x = ol.API ? opt_arg['x'] : opt_arg.x; + y = ol.API ? opt_arg['y'] : opt_arg.y; + z = ol.API ? opt_arg['z'] : opt_arg.z; + projection = ol.API ? opt_arg['projection'] : opt_arg.projection; } else { throw new Error('ol.geom.point'); } diff --git a/src/api/layer/wms.js b/src/api/layer/wms.js index ee48e9d232..dc4cfe22a4 100644 --- a/src/api/layer/wms.js +++ b/src/api/layer/wms.js @@ -21,9 +21,9 @@ ol.layer.wms = function(opt_arg) { if (goog.isObject(opt_arg)) { ol.base.checkKeys(opt_arg, ['url', 'layers', 'format']); - url = opt_arg['url']; - layers = opt_arg['layers']; - format = opt_arg['format']; + url = ol.API ? opt_arg['url'] : opt_arg.url; + layers = ol.API ? opt_arg['layers'] : opt_arg.layers; + format = ol.API ? opt_arg['format'] : opt_arg.format; } var msg; diff --git a/src/api/layer/xyz.js b/src/api/layer/xyz.js index 49967e62cf..ce69d2dc6d 100644 --- a/src/api/layer/xyz.js +++ b/src/api/layer/xyz.js @@ -18,7 +18,7 @@ ol.layer.xyz = function(opt_arg) { var usage = 'ol.layer.xyz accepts an object with a "url" property'; if (goog.isObject(opt_arg)) { - url = opt_arg['url']; + url = ol.API ? opt_arg['url'] : opt_arg.url; } else { throw new Error(usage); } diff --git a/src/api/loc.js b/src/api/loc.js index 5fceac35f6..d0cc3888e0 100644 --- a/src/api/loc.js +++ b/src/api/loc.js @@ -44,10 +44,10 @@ ol.loc = function(opt_arg){ projection = opt_arg[3]; } else if (goog.isObject(opt_arg)) { ol.base.checkKeys(opt_arg, ['projection', 'x', 'y', 'z']); - x = opt_arg['x']; - y = opt_arg['y']; - z = opt_arg['z']; - projection = opt_arg['projection']; + x = ol.API ? opt_arg['x'] : opt_arg.x; + y = ol.API ? opt_arg['y'] : opt_arg.y; + z = ol.API ? opt_arg['z'] : opt_arg.z; + projection = ol.API ? opt_arg['projection'] : opt_arg.projection; } else { throw new Error(usage); } diff --git a/src/api/map.js b/src/api/map.js index 767c8794de..56cfaf9316 100644 --- a/src/api/map.js +++ b/src/api/map.js @@ -50,17 +50,17 @@ ol.map = function(opt_arg) { } else if (goog.isObject(opt_arg)) { ol.base.checkKeys(opt_arg, ['center', 'zoom', 'numZoomLevels', 'projection', 'userProjection', 'maxExtent', 'maxResolution', 'resolutions', 'renderTo', 'layers', 'controls']); - center = opt_arg['center']; - zoom = opt_arg['zoom']; - numZoomLevels = opt_arg['numZoomLevels']; - projection = opt_arg['projection']; - userProjection = opt_arg['userProjection']; - maxExtent = opt_arg['maxExtent']; - maxResolution = opt_arg['maxResolution']; - resolutions = opt_arg['resolutions']; - renderTo = opt_arg['renderTo']; - layers = opt_arg['layers']; - controls = opt_arg['controls']; + center = ol.API ? opt_arg['center'] : opt_arg.center; + zoom = ol.API ? opt_arg['zoom'] : opt_arg.zoom; + numZoomLevels = ol.API ? opt_arg['numZoomLevels'] : opt_arg.numZoomLevels; + projection = ol.API ? opt_arg['projection'] : opt_arg.projection; + userProjection = ol.API ? opt_arg['userProjection'] : opt_arg.userProjection; + maxExtent = ol.API ? opt_arg['maxExtent'] : opt_arg.maxExtent; + maxResolution = ol.API ? opt_arg['maxResolution'] : opt_arg.maxResolution; + resolutions = ol.API ? opt_arg['resolutions'] : opt_arg.resolutions; + renderTo = ol.API ? opt_arg['renderTo'] : opt_arg.renderTo; + layers = ol.API ? opt_arg['layers'] : opt_arg.layers; + controls = ol.API ? opt_arg['controls'] : opt_arg.controls; } else { throw new Error('ol.map'); diff --git a/src/api/popup.js b/src/api/popup.js index d0fbf44259..1d2aa65533 100644 --- a/src/api/popup.js +++ b/src/api/popup.js @@ -39,11 +39,11 @@ ol.popup = function(opt_arg){ if (arguments.length == 1 && goog.isDef(opt_arg)) { if (goog.isObject(opt_arg)) { - map = opt_arg['map']; - anchor = opt_arg['anchor']; - placement = opt_arg['placement']; - content = opt_arg['content']; - template = opt_arg['template']; + map = ol.API ? opt_arg['map'] : opt_arg.map; + anchor = ol.API ? opt_arg['anchor'] : opt_arg.anchor; + placement = ol.API ? opt_arg['placement'] : opt_arg.placement; + content = ol.API ? opt_arg['content'] : opt_arg.content; + template = ol.API ? opt_arg['template'] : opt_arg.template; } } diff --git a/src/api/projection.js b/src/api/projection.js index cd302aafe1..8e067a1efd 100644 --- a/src/api/projection.js +++ b/src/api/projection.js @@ -34,13 +34,13 @@ ol.projection = function(opt_arg){ } else if (goog.isObject(opt_arg)) { ol.base.checkKeys(opt_arg, ['code', 'maxExtent', 'units']); - if (goog.isString(opt_arg['code'])) { - code = opt_arg['code']; + if (goog.isString(ol.API ? opt_arg['code'] : opt_arg.code)) { + code = ol.API ? opt_arg['code'] : opt_arg.code; } else { throw new Error('Projection requires a string code.'); } - units = opt_arg['units']; - extent = opt_arg['maxExtent']; + units = ol.API ? opt_arg['units'] : opt_arg.units; + extent = ol.API ? opt_arg['maxExtent'] : opt_arg.maxExtent; } else { throw new Error('ol.projection'); diff --git a/src/ol/base.js b/src/ol/base.js index 1c2a6bd1ca..bdf3e64037 100644 --- a/src/ol/base.js +++ b/src/ol/base.js @@ -12,12 +12,19 @@ ol.error = function(message) { } }; +/** + * Compilation with public API, let's accept options from external world + * @define {boolean} + */ +ol.API = true; + /** * @define {boolean} */ ol.error.VERBOSE_ERRORS = true; /** + * Options passed in the API from external world are checked for wrong keys * @define {boolean} */ ol.CHECK_KEYS = true;