| 1 | [[PageOutline]] |
| 2 | |
| 3 | This page is one of the !MapGuide Community CodeSamples. Visit the CodeSamples page to view more! |
| 4 | |
| 5 | This sample script contains a series of utility functions to batch update a series of Layer Definitions in a folder to conform to a specified minimum/maximum scale range. |
| 6 | |
| 7 | === How to use this script === |
| 8 | |
| 9 | 1. Launch MapGuide Maestro |
| 10 | 2. In the '''IronPython''' console, click '''Run File''' |
| 11 | 3. Browse to '''scale_ranges_utils.py''' and click '''Open''' to load this script |
| 12 | |
| 13 | Once loaded, you will have the following functions available for you to use from the IronPython console: |
| 14 | |
| 15 | {{{ |
| 16 | #!python |
| 17 | def FixScaleRangesMinMax(conn, folder, min, max): |
| 18 | """ |
| 19 | Modifies the first scale range of all Layer Definitions under the specified folder to the specified |
| 20 | minimum and Mmximum scales |
| 21 | """ |
| 22 | def FixScaleRangesZeroToMax(conn, folder, max): |
| 23 | """ |
| 24 | Modifies the first scale range of all Layer Definitions under the specified folder to the specified |
| 25 | maximum scale. The minimum scale is un-set (ie. Set to 0) |
| 26 | """ |
| 27 | def FixScaleRangesMinToInfinity(conn, folder, min): |
| 28 | """ |
| 29 | Modifies the first scale range of all Layer Definitions under the specified folder to the specified |
| 30 | minimum scale. The maximum scale is un-set (ie. Set to infinity) |
| 31 | """ |
| 32 | def FixScaleRangesZeroToInfinity(conn, folder): |
| 33 | """ |
| 34 | Modifies the first scale range of all Layer Definitions under the specified folder to [0, Infinity] |
| 35 | """ |
| 36 | }}} |
| 37 | |
| 38 | To modify all layers under {{{Library://Samples/Sheboygan/Layers/}}} to have a scale range of 50 to 12000, you would run the following snippets in your IronPython console. This assumes a session with only one active site connection: |
| 39 | |
| 40 | {{{ |
| 41 | |
| 42 | >>> conn = app.GetConnection(app.GetConnectionNames()[0]) |
| 43 | >>> FixScaleRangesMinMax(conn, "Library://Samples/Sheboygan/Layers/", 50, 12000) |
| 44 | |
| 45 | }}} |
| 46 | |
| 47 | This will output something similar to this: |
| 48 | |
| 49 | {{{ |
| 50 | |
| 51 | Fixing: Library://Samples/Sheboygan/Layers/CityLimits.LayerDefinition |
| 52 | Scale range set to [50, 12000] |
| 53 | Saved: Library://Samples/Sheboygan/Layers/CityLimits.LayerDefinition |
| 54 | Fixing: Library://Samples/Sheboygan/Layers/Buildings.LayerDefinition |
| 55 | Scale range set to [50, 12000] |
| 56 | Saved: Library://Samples/Sheboygan/Layers/Buildings.LayerDefinition |
| 57 | Fixing: Library://Samples/Sheboygan/Layers/Districts.LayerDefinition |
| 58 | Scale range set to [50, 12000] |
| 59 | Saved: Library://Samples/Sheboygan/Layers/Districts.LayerDefinition |
| 60 | Fixing: Library://Samples/Sheboygan/Layers/Hydrography.LayerDefinition |
| 61 | Scale range set to [50, 12000] |
| 62 | Saved: Library://Samples/Sheboygan/Layers/Hydrography.LayerDefinition |
| 63 | Fixing: Library://Samples/Sheboygan/Layers/Islands.LayerDefinition |
| 64 | Scale range set to [50, 12000] |
| 65 | Saved: Library://Samples/Sheboygan/Layers/Islands.LayerDefinition |
| 66 | Fixing: Library://Samples/Sheboygan/Layers/Parcels.LayerDefinition |
| 67 | Scale range set to [50, 12000] |
| 68 | Saved: Library://Samples/Sheboygan/Layers/Parcels.LayerDefinition |
| 69 | Fixing: Library://Samples/Sheboygan/Layers/Roads.LayerDefinition |
| 70 | Scale range set to [50, 12000] |
| 71 | Saved: Library://Samples/Sheboygan/Layers/Roads.LayerDefinition |
| 72 | Fixing: Library://Samples/Sheboygan/Layers/Tracks.LayerDefinition |
| 73 | Scale range set to [50, 12000] |
| 74 | Saved: Library://Samples/Sheboygan/Layers/Tracks.LayerDefinition |
| 75 | Fixing: Library://Samples/Sheboygan/Layers/Trees.LayerDefinition |
| 76 | Scale range set to [50, 12000] |
| 77 | Saved: Library://Samples/Sheboygan/Layers/Trees.LayerDefinition |
| 78 | >>> |
| 79 | |
| 80 | }}} |
| 81 | |
| 82 | === Limitations === |
| 83 | |
| 84 | This only operates on the first scale range it finds of each Layer Definition in the folder you specify. |