Code Monkey home page Code Monkey logo

wicket's Introduction

Wicket

Travis CI CDNJS

Wicket is a lightweight library for translating between Well-Known Text (WKT) and various client-side mapping frameworks:

  • Leaflet (demo)
  • Google Maps API (demo)
  • ESRI ArcGIS JavaScript API
  • Potentially any other web mapping framework through serialization and de-serialization of GeoJSON (with JSON.parse)

The core Wicket library and the Leaflet extension are both compatible with Node.js; the Google Maps and ArcGIS API extensions will not work in Node.js because they require a browser.

If you are looking for Apache Wicket, the web-app development framework for Java, you'll find it here.

License

Wicket is released under the GNU General Public License version 3 (GPLv3). Accordingly:

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Installation

$ npm install wicket

Example

The following examples work in any of the mapping environments, as Wicket has a uniform API regardless of the client-side mapping library you're using.

// Create a new Wicket instance
var wkt = new Wkt.Wkt();

// Read in any kind of WKT string
wkt.read("POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))");

// Or a GeoJSON string
wkt.read('{"coordinates": [[[30, 10], [10, 20], [20, 40], [40, 40], [30, 10]]], "type": "Polygon"}');

// Access and modify the underlying geometry
console.log(wkt.components);
// "[ [ {x: 30, y: 10}, {x: 10, y: 30}, ...] ]"
wkt.components[0][1].x = 15;

wkt.merge(new Wkt.Wkt('POLYGON((35 15,15 25,25 45,45 45,35 15))'));
wkt.write();
// MULTIPOLYGON(((30 10,10 20,20 40,40 40,30 10)),((35 15,15 25,25 45,45 45,35 15)))

// Create a geometry object, ready to be mapped!
wkt.toObject();

// Convert to GeoJSON
wkt.toJson(); // Outputs an object
JSON.stringify(wkt.toJson()); // Outputs a string

Wicket will read from the geometry objects of any mapping client it understands. Note: Don't use the deconstruct() method! This is used internally by Wkt.Wkt() instances. Use fromObject() instead, as in the following example.

var wkt = new Wkt.Wkt();

// Deconstruct an existing point feature e.g. google.maps.Marker instance
wkt.fromObject(somePointObject);

console.log(wkt.components);
// "[ {x: 10, y: 30} ]"

// Serialize a WKT string from that geometry
wkt.write();
// "POINT(10 30)"

See Also

Dependencies and Build Information

Wicket has zero dependencies, however, JSON parsing (from strings) is not provided. Wicket looks for the function JSON.parse, which is provided in most modern browsers (get it with this library, if you need to support older browsers).

Minified versions can be generated via:

npm run build

Testing

npm test

Documentation

Read the documentation here. Documentation can be generated with JSDoc 3.

git clone git://github.com/jsdoc3/jsdoc.git
./jsdoc /var/www/static/wicket/wicket.src.js

Or, with Node installed:

sudo npm install -g git://github.com/jsdoc3/jsdoc.git
jsdoc /var/www/static/wicket/wicket.src.js

Either way, make sure you invoke jsdoc from a directory in which you have write access; it will output documentation to your current working directory.

Colophon

Motivation

Wicket was created out of the need for a lightweight Javascript library that can translate Well-Known Text (WKT) strings into geographic features. This problem arose in the context of OpenClimateGIS, a web framework for accessing and subsetting online climate data.

OpenClimateGIS emits WKT representations of user-defined geometry. The API Explorer allowed users to define arbitrary areas-of-interest (AOIs) and view predefined AOIs on a Google Maps API instance. So, initially, the problem was converting between WKT strings and Google Maps API features. While other mapping libraries, such as OpenLayers, have very nice WKT libraries built-in, the Google Maps API, as of this writing, does not. In the (apparent) absence of a lightweight, easy-to-use WKT library in Javascript, I set out to create one.

That is what Wicket aspires to be: lightweight, framework-agnostic, and useful. I hope it achieves these goals. If you find it isn't living up to that and you have ideas on how to improve it, please fork the code or drop me a line.

Acknowledgements

Wicket borrows heavily from the experiences of others who came before us:

Conventions

The base library, wicket.js, contains the Wkt.Wkt base object. This object doesn't do anything on its own except read in WKT strings, allow the underlying geometry to be manipulated programmatically, and write WKT strings. By loading additional libraries, such as wicket-gmap3.js, users can transform between between WKT and the features of a given framework (e.g. google.maps.Polygon instances). The intent is to add support for new frameworks as additional Javascript files that alter the Wkt.Wkt prototype.

To extend Wicket, nominally by writing bindings for a new mapping library, add a new file with a name like wicket-libname.src.js (and corresponding minified version wicket-libname.js) where "libname" is some reasonably short, well-known name for the mapping library.

Concepts

WKT geometries are stored internally using the following convention. The atomic unit of geometry is the coordinate pair (e.g. latitude and longitude) which is represented by an Object with x and y properties. An Array with a single coordinate pair represents a a single point (i.e. POINT feature):

[ {x: -83.123, y: 42.123} ]

// POINT(-83.123 42.123)

An Array of multiple points (an Array of Arrays) specifies a "collection" of points (i.e. a MULTIPOINT feature):

[
    [ {x: -83.123, y: 42.123} ],
    [ {x: -83.234, y: 42.234} ]
]
// MULTIPOINT(-83.123 42.123,-83.234 42.234)

An Array of multiple coordinates specifies a collection of connected points in an ordered sequence (i.e. LINESTRING feature):

[
    {x: -83.12, y: 42.12},
    {x: -83.23, y: 42.23},
    {x: -83.34, y: 42.34}
]
// LINESTRING(-83.12 42.12,-83.23 42.23,-83.34 42.34)

An Array can also contain other Arrays. In these cases, the contained Array(s) can each represent one of two geometry types. The contained Array might reprsent a single polygon (i.e. POLYGON feature):

[
    [
        {x: -83, y: 42},
        {x: -83, y: 43},
        {x: -82, y: 43},
        {x: -82, y: 42},
        {x: -83, y: 42}
    ]
]
// POLYGON(-83 42,-83 43,-82 43,-82 42,-83 42)

The above example cannot represent a LINESTRING feature (one of the few type-based constraints on the internal representations), however it may represent a MULTILINESTRING feature. Both POLYGON and MULTILINESTRING features are internally represented the same way. The difference between the two is specified elsewhere (in the Wkt instance's type) and must be retained. In this particular example (above), we can see that the first coordinate in the Array is repeated at the end, meaning that the geometry is closed. We can therefore infer it represents a POLYGON and not a MULTILINESTRING even before we plot it. Wicket retains the type of the feature and will always remember which it is.

Similarly, multiple nested Arrays might reprsent a MULTIPOLYGON feature:

[
    [
        [
            {x: -83, y: 42},
            {x: -83, y: 43},
            {x: -82, y: 43},
            {x: -82, y: 42},
            {x: -83, y: 42}
        ]
    ],
    [
        [
            {x: -70, y: 40},
            {x: -70, y: 41},
            {x: -69, y: 41},
            {x: -69, y: 40},
            {x: -70, y: 40}
        ]
    ]
]
// MULTIPOLYGON(((-83 42,-83 43,-82 43,-82 42,-83 42),(-70 40,-70 41,-69 41,-69 40,-70 40)))

Or a POLYGON with inner rings (holes) in it where the outer ring is the polygon envelope and comes first; subsequent Arrays are inner rings (holes):

[
    [
        {x: 35, y: 10},
        {x: 10, y: 20},
        {x: 15, y: 40},
        {x: 45, y: 45},
        {x: 35, y: 10}
    ],
    [
        {x: 20, y: 30},
        {x: 35, y: 35},
        {x: 30, y: 20},
        {x: 20, y: 30}
    ]
]
// POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 35,30 20,20 30))

Or they might represent a MULTILINESTRING where each nested Array is a different LINESTRING in the collection. Again, Wicket remembers the correct type of feature even though the internal representation is ambiguous.

wicket's People

Contributors

arthur-e avatar atogle avatar braco avatar cancastilho avatar crash-dive avatar davisjam avatar destus90 avatar devdattat avatar ecoffman avatar ffflabs avatar foolmoron avatar formigarafa avatar freewind avatar frewsxcv avatar jseppi avatar kbejnar avatar kennynaoh avatar knock-in avatar michaeljkchoi avatar mpschaeuble avatar mvhenten avatar nickescallon avatar scottlepp avatar songjiahong avatar stevenlambion avatar steveoh avatar tcql avatar uqix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wicket's Issues

Add support for 3D WKT

Hi, very cool project! The demo page really takes the pain out of generating simple bbox WKT.

It would be nice if 3D WKT geometries were supported. Obviously the Z coordinate doesn't apply to a 2D map, but it would be convenient (and presumably easy) for POINT Z to be interpreted as a 2D POINT, etc. Currently the demo complains if POINT Z geoms are pasted into it.

Add to bower index?

This was suggested by someone. I don't have enough information at the present time.

Esri JS API - Wicket generates lat/long instead of web mercator coords for point features

I'm testing your library with a co-worker using the Esri JavsScript API. We allow the user to draw on the map and then we save to a database by passing the WKT generated by Wicket. We use the following code to convert the Esri geometry to WKT:

wkt.fromObject(geometry);
var geodata = wkt.write();

It seems that when we draw point features on the map, the coordinates generated by Wicket in the WKT come back in lat/long coordinates instead of meters (we're drawing on a typical basemap in web mercator). When we examine the spatial reference object of the point geometry it looks like this:

{wkid: 102100, latestWkid: 3857}

This is consistent with what we see on line and polygon geometries that we draw, and indeed Wicket generates the WKT properly for those feature types using coordinates in meters, but for points it is converting to lat/long.

Please let me know: are we doing something wrong, or is there a problem with the library?

Standardize the way in which Wicket write WKT vertices

Currently, Wicket writes WKT strings two different ways, depending on the geometry type. Both are valid, but Wicket ought to do it just one way for consistency. As stated before, I'd like to expose a configuration parameter that allows users to tell Wicket to write WKT strings the other way (consistently). Here is an example of two ways of writing the same string, both valid:

LINESTRING(30 10,10 30,40 40)
LINESTRING((30 10),(10 30),(40 40))

I believe the POLYGONs are written the second way, always; LINESTRINGs are always written the first way, however. Nothing is consistent!

TypeScript definitions

Hi All,
I have searched for typescript definitions for Wicket library but haven't found any. Does anyone knows if definitions exist anywhere?

Unfortunate name clash

Are you aware that there is already an extremely popular UI framework called Wicket which is nothing like your's but still is in the Web UI space and has been around since 2005ish?

I code in Wicket (original one) all day long and do about 5-10 Wicket searches a day so I hope google is not going to start throwing matches with your product up when I really want the original Wicket.

Chainable contructor, read and merge methods

At this point, Wkt.read() returns Wkt's components, while Wkt's constructor and Wkt.merge() doesn't have a return object.

¿Do you think it would be a sensible to return this in all those methods? That would allow to chain methods in the following way:

new Wkt.Wkt().read("POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))").merge(new Wkt.Wkt('POLYGON((35 15,15 25,25 45,45 45,35 15))')).write();

"MULTIPOLYGON(((30 10,10 20,20 40,40 40,30 10)),((35 15,15 25,25 45,45 45,35 15)))"

While preserving the current functionality, except for those who are now operating on the return value of the read method.

For those cases, the read method could accept a seccond, boolean parameter, and return this.components when the parameter is falsy, or this when the parameter is true. This particular solution doesn't seem so appealing, for I'd like to treat all three methods equally.

Problems with fromObject() method

Hi,

I have a problem with fromObject method.

My WKT:

POLYGON((15.5848687374 53.1204806794,15.5849691018 53.1205107954,15.5852754108 53.1206446442,15.5853709188 53.1206961327,15.5857148196 53.120816812,15.5858446817 53.1208672209,15.5859952282 53.1209139596,15.5864089163 53.1210141294,15.5865033451 53.121048023,15.5865760104 53.1210888249,15.5868271011 53.1213199265,15.587030168 53.1214767641,15.587152116 53.1215335406,15.5872710064 53.1215681894,15.5874675982 53.1216058605,15.5876965656 53.1216394298,15.5878874017 53.1216845487,15.5879645636 53.1216952347,15.5881557594 53.1217085113,15.5885541591 53.1217152035,15.5888944625 53.1216709482,15.5889320542 53.1216728912,15.5890957308 53.1217136924,15.5892757751 53.1217855802,15.5894425094 53.1218401975,15.5896477347 53.1218794875,15.5898700471 53.1218955704,15.5900975756 53.1218991324,15.5903472274 53.1218842368,15.5904680962 53.1218612457,15.5906868114 53.1218283242,15.5911645312 53.1217688495,15.591390261 53.1217454267,15.5916319988 53.1217317183,15.5920579177 53.1216966379,15.5922464156 53.1216859519,15.5923845515 53.1216656592,15.5933023995 53.1215746658,15.5934851418 53.1215471411,15.593613565 53.1215178893,15.5936817336 53.121491444,15.5938342586 53.1213999105,15.5939499114 53.1213249997,15.5941923686 53.1211498116,15.5944215159 53.1209627493,15.5946213452 53.1207710446,15.5946486846 53.1207143749,15.5946522819 53.1206836114,15.5946495839 53.1206602959,15.5946053373 53.120598121,15.5945540759 53.1205588299,15.5944936415 53.1205245042,15.5943252884 53.1204498078,15.5942171899 53.1204079259,15.5939759917 53.1203288036,15.5936632075 53.1202378074,15.5930243292 53.1200887373,15.5929975294 53.1200790223,15.5929723484 53.120062399,15.5929036402 53.1199789583,15.5928543573 53.1198915235,15.5928253991 53.1197943736,15.5927701808 53.1196894514,15.5927527339 53.119621662,15.5927235959 53.119548907,15.5927068685 53.1195179267,15.5926708956 53.1194751804,15.5926261094 53.1193940054,15.5924834769 53.119097586,15.5924586556 53.1190323864,15.5923314915 53.1187991135,15.5921895785 53.1185576353,15.5920386722 53.118376175,15.5919595319 53.1182482563,15.5917920781 53.1179104844,15.591743155 53.117826068,15.591732543 53.1178236931,15.5917185136 53.1178021032,15.5915062736 53.1173470935,15.5914631061 53.1172729313,15.5914077079 53.1171522421,15.5913758719 53.1171024766,15.5913255099 53.1170441828,15.5911109316 53.1166986289,15.5910377268 53.1165325979,15.5908632583 53.1162115454,15.5907188272 53.1159719958,15.5906409459 53.11579657,15.5906139663 53.1157645075,15.5905893248 53.1157086949,15.5905720579 53.1156947687,15.5905524526 53.1156888312,15.5904607218 53.1156837573,15.5904224107 53.115686888,15.5894662515 53.1158429904,15.5888831311 53.1159270869,15.5885376116 53.1159812799,15.5885307767 53.1159853821,15.5876145474 53.1161095292,15.5868893341 53.1162305452,15.5866112638 53.1162708118,15.5860344386 53.1163370951,15.5851725284 53.1164797011,15.5842183477 53.1166010399,15.5839917186 53.1166338575,15.5833211841 53.1167397587,15.5826616213 53.1168290351,15.5823882274 53.1168705966,15.581255981 53.1170557336,15.5807859953 53.1171212601,15.5804185323 53.117179014,15.579622992 53.1172881524,15.5790422098 53.1173796946,15.5776921476 53.1175620227,15.577531169 53.1175775676,15.5771917648 53.1176295995,15.5769404943 53.1176787167,15.576841389 53.1177071075,15.5768171073 53.1177441342,15.5768367125 53.1177676673,15.5768577566 53.1177817007,15.5772689267 53.1179589536,15.5776964644 53.1181137523,15.578008709 53.1182188943,15.578231561 53.1182811805,15.5786107151 53.1184022984,15.5786889562 53.1184234562,15.5788979586 53.1184936223,15.5789882505 53.1185300007,15.5793873696 53.1186641795,15.579409493 53.1186675259,15.580054127 53.1188822326,15.5807696276 53.1191419519,15.5809253902 53.119191823,15.5812646144 53.1193153131,15.5824074729 53.1196883719,15.5829116328 53.1198591402,15.5834318007 53.1200638023,15.5837559163 53.1201823245,15.5838417117 53.1202206444,15.5841656475 53.1203361437,15.584362599 53.1203898994,15.5844883242 53.1204181805,15.5848687374 53.1204806794),(15.5852495104 53.1187050915,15.585126663 53.1187559347,15.585081517 53.1187638148,15.58506425 53.1187630592,15.585048422 53.1187536678,15.5850316946 53.1187180452,15.5850322342 53.1187059551,15.5850581346 53.1186453966,15.585100043 53.1185982236,15.5851620963 53.118549971,15.5853376439 53.1184377053,15.5853736168 53.1184372735,15.5854480807 53.118463289,15.5854621101 53.1184856342,15.5854567142 53.1185246033,15.5853889053 53.1186112852,15.5852495104 53.1187050915),(15.5902364309 53.1184313364,15.5901310303 53.1184156839,15.5900812079 53.1183974407,15.5900196943 53.1183618179,15.5899110562 53.1182680108,15.5898786806 53.1182142525,15.589862133 53.1181726923,15.5898686082 53.1181489436,15.589882098 53.1181326434,15.5899743684 53.1180805041,15.5900678979 53.1180360292,15.5901810326 53.1180048319,15.590254777 53.1180000822,15.5903011821 53.1180062353,15.5903508246 53.1180222117,15.5903939921 53.1180442333,15.5905713384 53.1182197579,15.5906123475 53.1182889528,15.5906062321 53.118324036,15.5905256528 53.118357392,15.5904278066 53.1184058607,15.5903421911 53.1184272344,15.5902839151 53.1184326318,15.5902364309 53.1184313364),(15.590562525 53.1206705504,15.5906742208 53.1205506263,15.5912138141 53.1202400742,15.5912720901 53.1202305752,15.5912889974 53.1202381312,15.591318675 53.1202669521,15.5913587848 53.120347046,15.5913640008 53.1204216346,15.5913553673 53.1204733393,15.5913632814 53.1205432862,15.5913911604 53.1206001719,15.5914357667 53.120645076,15.5916775045 53.1207693175,15.5917320034 53.1208061257,15.5918077263 53.1208457404,15.5920726666 53.1210019321,15.5921480298 53.1210399274,15.5923131453 53.1211086861,15.5923993004 53.1211181849,15.5924563174 53.1211159181,15.5925712507 53.1211002666,15.5926023673 53.1210902281,15.5927081275 53.1210454325,15.592760648 53.1210165042,15.5930326029 53.1209120167,15.5930683959 53.1209088864,15.5931178587 53.120911477,15.5931495148 53.1209187091,15.5932047332 53.1209664193,15.5931982581 53.1210314001,15.5932068915 53.1210927108,15.5931968191 53.1211219628,15.5931759549 53.1211567199,15.5931495148 53.1211832734,15.5931124627 53.1212112301,15.593052388 53.1212329262,15.5929842194 53.1212415615,15.5929191085 53.121240698,15.5928232408 53.1212300118,15.5927005732 53.121224183,15.5924850957 53.1212358406,15.5923885085 53.121246095,15.5923419236 53.121266172,15.5922778919 53.1213077292,15.5921793262 53.121418908,15.5920983872 53.1214661859,15.5920577379 53.1214766561,15.5919372287 53.1214942504,15.5916393732 53.1215504872,15.5914791141 53.1215962538,15.5912506863 53.1216421283,15.5911783808 53.1216482809,15.5910855707 53.1216453665,15.5909810695 53.1216351122,15.5906098294 53.1215843804,15.5905375239 53.121559878,15.590419353 53.1214806499,15.5903855385 53.1214478361,15.5903508246 53.1213759477,15.5904011867 53.1209871441,15.5904231301 53.1209273444,15.5904731324 53.1208327874,15.590561266 53.1206920309,15.590562525 53.1206705504),(15.589504023 53.1183745557,15.5893106688 53.1184020825,15.5890453688 53.1184098547,15.5889924886 53.1184067243,15.5888550722 53.1183858903,15.5888356469 53.1183619258,15.5888480575 53.1183413077,15.5888637057 53.118330189,15.5889583144 53.1182879813,15.589039793 53.1182590511,15.5891237897 53.1182465291,15.5891971743 53.1182484722,15.5893203815 53.1182832315,15.589504023 53.1183745557))

I'm calling fromObject method:

var wkt = new Wkt.Wkt();
    wkt.fromObject(nowEditingShape);
    console.log(wkt.components);
    wktdata = wkt.write();
    console.log(wktdata);

wkddata returns on my object Polygon but with undefined on the end:

POLYGON((15.58486873740003 53.1204806794,15.58496910179997 53.1205107954,15.585275410800023 53.1206446442,15.585370918799981 53.1206961327,15.58571481960007 53.120816812,15.585844681699996 53.1208672209,15.585995228199977 53.1209139596,15.586408916300002 53.1210141294,15.586503345100027 53.121048023,15.586576010399995 53.1210888249,15.58682710109997 53.1213199265,15.587030167999956 53.1214767641,15.58715211599997 53.1215335406,15.587271006399988 53.1215681894,15.587467598199964 53.1216058605,15.587696565600027 53.1216394298,15.587887401699959 53.1216845487,15.587964563600053 53.1216952347,15.588155759400024 53.1217085113,15.5885541591 53.1217152035,15.58889446249998 53.1216709482,15.588932054199972 53.1216728912,15.589095730799954 53.1217136924,15.589275775099964 53.1217855802,15.589442509399987 53.1218401975,15.589647734700065 53.1218794875,15.589870047100021 53.1218955704,15.590097575599998 53.1218991324,15.590347227400002 53.1218842368,15.59046809619997 53.1218612457,15.590686811400019 53.1218283242,15.59116453119998 53.1217688495,15.591390261000015 53.1217454267,15.59163199880004 53.1217317183,15.592057917700004 53.1216966379,15.592246415600016 53.1216859519,15.592384551500004 53.1216656592,15.593302399499976 53.1215746658,15.593485141799988 53.1215471411,15.593613564999941 53.1215178893,15.593681733599965 53.121491444,15.593834258600054 53.1213999105,15.593949911399932 53.1213249997,15.594192368600034 53.1211498116,15.594421515899967 53.1209627493,15.59462134520004 53.1207710446,15.594648684599974 53.1207143749,15.59465228190004 53.1206836114,15.594649583900036 53.1206602959,15.594605337299981 53.120598121,15.594554075899964 53.1205588299,15.59449364149998 53.1205245042,15.5943252884 53.1204498078,15.594217189900064 53.1204079259,15.593975991700063 53.1203288036,15.593663207499958 53.1202378074,15.593024329200034 53.1200887373,15.592997529400009 53.1200790223,15.592972348400053 53.120062399,15.592903640200007 53.1199789583,15.592854357299984 53.1198915235,15.59282539909998 53.1197943736,15.592770180800017 53.1196894514,15.592752733899943 53.119621662,15.592723595899997 53.119548907,15.592706868500045 53.1195179267,15.592670895600008 53.1194751804,15.592626109400044 53.1193940054,15.592483476900043 53.119097586,15.592458655600012 53.1190323864,15.592331491499976 53.1187991135,15.592189578499983 53.1185576353,15.592038672200033 53.118376175,15.591959531899988 53.1182482563,15.59179207810007 53.1179104844,15.591743155000017 53.117826068,15.591732543000035 53.1178236931,15.591718513599972 53.1178021032,15.591506273599975 53.1173470935,15.591463106100036 53.1172729313,15.591407707899975 53.1171522421,15.591375871900027 53.1171024766,15.591325509900003 53.1170441828,15.591110931600042 53.1166986289,15.591037726799982 53.1165325979,15.590863258300033 53.1162115454,15.590718827200021 53.1159719958,15.590640945899963 53.11579657,15.590613966299998 53.1157645075,15.590589324800021 53.1157086949,15.590572057899976 53.1156947687,15.590552452600036 53.1156888312,15.590460721800014 53.1156837573,15.590422410700057 53.115686888,15.589466251499971 53.1158429904,15.588883131100033 53.1159270869,15.588537611600032 53.1159812799,15.588530776700054 53.1159853821,15.587614547399994 53.1161095292,15.586889334099965 53.1162305452,15.586611263800023 53.1162708118,15.586034438599995 53.1163370951,15.585172528399994 53.1164797011,15.584218347700016 53.1166010399,15.583991718600032 53.1166338575,15.583321184099987 53.1167397587,15.582661621299962 53.1168290351,15.582388227399974 53.1168705966,15.581255981000027 53.1170557336,15.580785995299948 53.1171212601,15.580418532299973 53.117179014,15.57962299199994 53.1172881524,15.579042209800036 53.1173796946,15.577692147600033 53.1175620227,15.57753116899994 53.1175775676,15.577191764799977 53.1176295995,15.576940494300061 53.1176787167,15.576841389000037 53.1177071075,15.57681710730003 53.1177441342,15.57683671250004 53.1177676673,15.57685775660002 53.1177817007,15.577268926700071 53.1179589536,15.577696464399992 53.1181137523,15.57800870899996 53.1182188943,15.578231560999939 53.1182811805,15.578610715100012 53.1184022984,15.57868895620004 53.1184234562,15.57889795860001 53.1184936223,15.57898825050006 53.1185300007,15.5793873696 53.1186641795,15.579409492999957 53.1186675259,15.58005412700004 53.1188822326,15.580769627600034 53.1191419519,15.580925390200036 53.119191823,15.58126461439997 53.1193153131,15.582407472900059 53.1196883719,15.582911632800005 53.1198591402,15.583431800700055 53.1200638023,15.583755916299992 53.1201823245,15.58384171169996 53.1202206444,15.584165647499958 53.1203361437,15.584362598999974 53.1203898994,15.584488324200038 53.1204181805,15.58486873740003 53.1204806794),(15.585388905299965 53.1186112852,15.585456714200063 53.1185246033,15.585462110100025 53.1184856342,15.585448080699962 53.118463289,15.585373616799984 53.1184372735,15.585337643899948 53.1184377053,15.585162096299996 53.118549971,15.585100043000011 53.1185982236,15.58505813459999 53.1186453966,15.585032234200071 53.1187059551,15.585031694600048 53.1187180452,15.585048422 53.1187536678,15.58506424999996 53.1187630592,15.585081516999935 53.1187638148,15.585126662999983 53.1187559347,15.58524951039999 53.1187050915,15.585388905299965 53.1186112852),(undefined undefined),(undefined undefined),(undefined undefined)) 

I'm stuck on this, any help will be appreciated!

please remove for-in loops

I had to remove about 10 for-in loops in both Wicket.js and Wicket.gmap.js in order to make it function properly.

For-In has the side effect that it also iterate prototype functions on Array's - even though safe measure has been put in place : hasOwnProperty checks, it can still fail !

there are several alternatives which is better code:

eg:
MDM / ES6
Array.forEach(function (obj) { ... })

shortcut for-loop
for(var i=0, obj; obj = arr[i] ; i++)

high performance:
var i = arr.length
do{
var obj = arr[i]
}while(--i)

wicket-arcgis AMD update

this component only works with the global esri namespace instead of the AMD modules which is the not recommended route for working with esri js.

My take is that it doesn't really fit nicely into your project because you are not on the AMD train and new objects are being created from the global namespace. In AMD land you would need to require that class in to create instances of it. It could come in as a parameter or a property of your global though.

What are your thoughts on this?

Add serialization/de-serialization for GeoJSON?

I suppose the internal representation should have been GeoJSON, though it can be verbose. It's very similar to GeoJSON, however, and it shouldn't be difficult to serialize the internal representation to JSON.

Rename to wicket.js?

In the light of increased confusion between this project and apache's what do you think about renaming wicket to wicket.js ?

Wicket generates invalid WKT from Google Maps v3 Polygon with hole

Initially, we retrieve this from PostGIS:

POLYGON((-87.6031179311616 41.7888101645398,-87.6029387172624 41.7888127767185,-87.6029387172624 41.7888354825745,-87.6027529456616 41.7888384966255,-87.6025688808599 41.7888417116132,-87.6023627175022 41.7888435200437,-87.6022213226765 41.7888454624319,-87.6022205141927 41.7887902048123,-87.602156643976 41.7887896020017,-87.6021579016174 41.7888429172335,-87.6019916234583 41.7888447926429,-87.6019855149144 41.7887056103279,-87.6019681774294 41.7878378908616,-87.6021392166595 41.7878362163627,-87.6021473913286 41.7881626088692,-87.6022056919905 41.7881620730323,-87.6022049733383 41.7881415772659,-87.6023982009559 41.7881395678767,-87.6023978416298 41.7881035997991,-87.6024115858537 41.7881035997991,-87.6024116756852 41.7881086902545,-87.6024692576949 41.7881078195188,-87.6024692576949 41.7881030639617,-87.6024843493917 41.7881030639617,-87.6024853375385 41.7881390990192,-87.6026992264076 41.7881368217113,-87.6026992264076 41.7881440555125,-87.6027375844703 41.788143787594,-87.6027360573343 41.7880701099508,-87.6026865601621 41.7880705788088,-87.6026865601621 41.7879936190718,-87.6027340810407 41.7879930832334,-87.6027313860948 41.7878297193064,-87.6029088033634 41.7878287146069,-87.602905838923 41.7878460624158,-87.6029323392239 41.7886963002393,-87.6031155955418 41.7886944918046,-87.6031179311616 41.7888101645398),(-87.6027596830263 41.7886993812759,-87.6027498913897 41.7882650206224,-87.6021457743611 41.7882691063724,-87.6021543981878 41.7887024623125,-87.6027596830263 41.7886993812759))

Then we use Wicket to construct a google maps polygon and render it. It appears correctly and we can even edit its vertices. When attempting to serialize it back to WKT to send to our back-end, this is what we get:

MULTIPOLYGON(((),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),()),((),(),(),(),()))

Any ideas / workarounds?

Error: this.construct is undefined

I always get this error message when using the method toObject():

In Firefox: Error: this.construct is undefined
In Chrome: Uncaught TypeError: Cannot read property 'polygon' of undefined

The line referenced in both cases is wicket.js 237 (tried v1.2 and latest):
https://github.com/arthur-e/Wicket/blob/master/wicket.js#L237
var obj = this.construct[this.type].call(this, config);

This is the code I used:

<!DOCTYPE HTML>
<html>
<script src="bower_components/Wicket/wicket.js"></script> 
<script type="text/javascript">
    var wkt = new Wkt.Wkt();
    wkt.read("POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))");
    console.log(wkt.toObject());
</script>
</html>

The examples on your website work without issues. Am I doing something wrong?

Parsing POLYGONS with extra parentheses around parts doesn't work

Consider this POLYGON:
POLYGON(((-15 53),(16 53),(16 36),(-15 36),(-15 53)))

It was generated with the default (and only I guess) mode: extra parentheses around parts. If you try to parse it on any of the sandboxes, it doesn't work.

Whereas it works when you remove the parentheses:
POLYGON((-15 53,16 53,16 36,-15 36,-15 53))

really really really weird problem with multipolygon / polygon

I've made a polygon editing tool using Google Maps api, JSTS and Wicket

JSTS allows me to cut (difference) and add (union) parts to a polygon shown on Google Maps.

BUT... there's a weird problem !!

if the first polygon i show, is a WKT:POLYGON - then i'm not allowed to render a WKT:MULTIPOLYGON afterwords !!

on the other hand, if the first polygon i show is a WKT:MULTIPOLYGON, then i can freely add / remove WKT:POLYGONs and WKT:MULTIPOLYGONs

i've copied most of the code from the demo: http://arthur-e.github.io/Wicket/sandbox-gmaps3.html

var mapIt = function (wktpoly)
{
var wkt = wktpoly;
var obj = wkt.toObject(map.defaults);
if (Wkt.isArray(obj))
{
obj.forEach(function (o)
{
if (!Wkt.isArray(o))
{
o.setMap(map);
features.push(o);
}
});
}
else
{
obj.setMap(map);
features.push(obj);
}

          return obj;
      };

and Wicket instances is made this way:

var polygon = (new Wkt.Wkt()).read("MULTIPOLYGON(((12.343662987509497 55.55056767251673,12.343662987509497 55.80130975155818,12.504501342773438 55.80130975155818,12.504501342773438 55.795877445664104,12.504501342773438 55.785454243141885,12.506561279296875 55.774642049830206,12.509994506835938 55.75919085473824,12.514114379882812 55.74953074789918,12.5189208984375 55.74102787471819,12.525787353515625 55.73213652597944,12.533340454101562 55.72401656896143,12.541580200195312 55.71628170645908,12.544759065339964 55.714132762561235,12.5408935546875 55.71086639119249,12.536773681640625 55.70777158827011,12.53265380859375 55.702355093270924,12.53265380859375 55.697711785689854,12.53265380859375 55.691519850785426,12.53265380859375 55.68610110318786,12.534027099609375 55.6799073292233,12.535400390625 55.67448697232047,12.536773681640625 55.669840354308725,12.536973031290898 55.66961549462442,12.536773681640625 55.66945311123117,12.530593872070312 55.66325670077184,12.5244140625 55.65628456619121,12.5189208984375 55.650086070637734,12.512741088867188 55.64001142229069,12.508621215820312 55.632647540285284,12.504501342773438 55.62450690239057,12.49969482421875 55.616364573379,12.495574951171875 55.60860840190929,12.492141723632812 55.60085069621599,12.489395141601562 55.593867449197575,12.486648559570312 55.58688295920994,12.484588623046875 55.58067348009016,12.484588623046875 55.57446301869603,12.484588623046875 55.56902805913944,12.484588623046875 55.563592347410776,12.4859619140625 55.55737918433739,12.488021850585938 55.5534954584537,12.489903963062195 55.55056767251673,12.343662987509497 55.55056767251673)),((12.587048140645559 55.65512242302239,12.59033203125 55.65512242302239,12.59307861328125 55.65512242302239,12.61505126953125 55.655897188968034,12.616424560546875 55.655897188968034,12.62054443359375 55.65667193958129,12.624664306640625 55.65822139481129,12.63153076171875 55.6597707887137,12.635650634765625 55.66286939254093,12.638397216796875 55.66674230238031,12.64251708984375 55.672163732295054,12.64251708984375 55.67293816096562,12.654190063476562 55.669840354308725,12.667922973632812 55.667516838357216,12.68096923828125 55.66596775107334,12.6947021484375 55.66519318443606,12.707748413085938 55.664805895368524,12.721481323242188 55.66519318443606,12.737274169921875 55.667129572285006,12.753067016601562 55.66906586432124,12.770919799804688 55.67371257430738,12.786712646484375 55.6791330385063,12.78739550263763 55.6793832806291,12.78739550263763 55.55056767251673,12.551947872976596 55.55056767251673,12.553939819335938 55.55582574004364,12.555313110351562 55.56242745417594,12.557373046875 55.57058098147687,12.560806274414062 55.57950909340291,12.564926147460938 55.59037535958225,12.567672729492188 55.60085069621599,12.57659912109375 55.62838360752494,12.578659057617188 55.63574829088387,12.580718994140625 55.64194905593519,12.586212158203125 55.65241062146783,12.587048140645559 55.65512242302239)))")

...

IT SEEMS that the global Wkt object is acting like a singleton, keeping some data / settings / stuff for too long !

the source i use are:

http://arthur-e.github.io/Wicket/wicket-gmap3.js
http://arthur-e.github.io/Wicket/wicket.js

Licensing

It's nice that you've been explicit about your license, but your choice of license has more or less ruined my day. :( I was so excited about such a neat library, played around with your demo web site. Your site was cool, and the mode of integration (WKT) made great sense, and happens to jibe perfectly with spacial search in Solr, so I told my client I had a likely solution, and even wrote some code to produce WKT formatted shapes (not that much work, but an hour or two), and then... I go to download your library and start integrating it and I see what I missed... it's GPL :( :( :( :( :(.

It might be that those who are lawyers and experts can figure out if the way I want to use it is legal, but I don't have money to pay lawyers, especially not ones who have enough clue about programing, javascript and GPL to be useful. Could you please consider releasing this under a license that is usable. (such as the BSD style license for OpenClimateGIS?)

It's totally unclear (to me let alone my client) if calling your code constitutes "linking" in the javascript context, and the issue of the browser interpreters running it and whether calling it from events such as a window resize event is linking it to the browser..... etc. etc.

The big problem is that the GPL tries to draw lines in muddy icky gooey grey areas, and nobody can be sure if the lines are being crossed or not (without spending many thousands of dollars to figure out if they can use the supposedly "free" software). Putting GPL on your code makes it even less usable than proprietary software (for which a known fee is often stated and can usually be paid).

If you are morally opposed to folks doing any programming that makes money and only wish to work towards an unobtainable utopia that's fine too. You have that right of course. In that case it would be considerate to at least put "This library is GPL V3" on your demo page where it can't be easily missed so people don't waste time considering wicket for purposes you disallow.

Licensing

I'd like to bundle this as a dependency for a Leaflet plugin that I am developing. Have you considered any particular open source license?

Closed paths do not need duplicate vertex in Leaflet

From the Leaflet documentation: "Note that points you pass when creating a polygon shouldn't have an additional last point equal to the first one — it's better to filter out such points," (http://leafletjs.com/reference.html#polygon).

These are not being filtered out and, as a result, closed paths (Polygons and MultiPolygons) have one vertex that, when edited (moved), creates a new, adjoining polygon. This can be seen clearly in the Leaflet Sandbox by moving the point over the country of Turkey on the map.

Geometries with Spaces are not parsed properly.

When the WKT Text has a space before the first coordinate in the xy pair, then the geometry is not parsed at all.

For example, the following does not work: POLYGON (( 30 10, 40 40, 20 40, 10 20, 30 10))

Note the space before the first 30. This is valid WKT, and is parsed correctly by PostGIS as well OpenLayers

Mulipolygon with single ring won't render in demo

It seems like wicket (at least the demo) hates wkt that's a single-loop multipolygon:

MULTIPOLYGON (((30.986898442269066 70.28585936935058, 30.989558933833557 70.28843123397311, 31.004516080503592 70.28678730243136, 31.00362864051688 70.28593009131207, 31.00612119310801 70.28565600571979, 31.005233743671045 70.28479880314164, 31.007726145933614 70.28452469857963, 31.0059513071118 70.28281030680907, 31.00844347069729 70.28253619551562, 31.006668770857026 70.28082181343342, 31.00417678398592 70.281095900258, 31.00506400609191 70.28195310538081, 30.997587408937164 70.28277521534345, 30.99936155962802 70.2844896879051, 30.986898442269066 70.28585936935058)))

doesn't render, but this does:
POLYGON ((30.986898442269066 70.28585936935058, 30.989558933833557 70.28843123397311, 31.004516080503592 70.28678730243136, 31.00362864051688 70.28593009131207, 31.00612119310801 70.28565600571979, 31.005233743671045 70.28479880314164, 31.007726145933614 70.28452469857963, 31.0059513071118 70.28281030680907, 31.00844347069729 70.28253619551562, 31.006668770857026 70.28082181343342, 31.00417678398592 70.281095900258, 31.00506400609191 70.28195310538081, 30.997587408937164 70.28277521534345, 30.99936155962802 70.2844896879051, 30.986898442269066 70.28585936935058))

how to require('wicket')

Hi,

Just tried to "require" wicket, node is throwing errors and looking at your code I can see some references to 'this' and 'global' - AFAIK not there in current node.js environment.

Am I missing something?
Thanks,
Matthijs.

Wicket writes non-standard POLYGON strings in the Google Maps extension

I have confirmed that the Google Maps API exhibits bad behavior, as originally reported by issue #22.

The following is one example of a bad WKT string; it can't be drawn in the sandbox (on Chromium in Linux I get a weird error with the Maps API):

POLYGON(((-15 53),(16 53),(16 36),(-15 36),(-15 53)))

This string can be drawn:

POLYGON((-15 53,16 53,16 36,-15 36,-15 53))

So far, this behavior is fine. The problem is that the Maps API sandbox, when the correct string is modified, will re-write the string with extra parens, the wrong way.

AMD/Require.js example

Does anyone have an example of how I can use the Gmap extension with Wicket importing them both with require.js?

I've tried several approaches with shims with deps and exports and can't get passed:

ReferenceError: Wkt is not defined

Has anyone done this?

Google Maps API extension can return Rectangle instance instead of Polygon instance

Feature request from a user: "Exploring the code, I fond this boolean flag called 'isRectangle' and then a comment saying that 'rectangles are not supported yet'. Is this still the case? Is there any way of achieving this that I am not seeing? If not available... do you plan to add support to it in the near future?"

This is easy enough to implement; just need to return a Rectangle instance in the Google Maps API extension.

Version problem

Hello @arthur-e ,
I am the member in cdnjs project
We want to host this library.
But there are some version problems.
The latest git tag version is v1.3, but the latest version in packe.json is v1.1.0.
Please confirm this.
Thanks.

cdnjs/cdnjs#6746

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.