@@ -2129,129 +2129,16 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
2129
2129
break ;
2130
2130
2131
2131
case 'geojson' :
2132
- // has a source with this id already been defined? If so, then it is an error (because attempting
2133
- // to add another source with the same id will crash the app.
2134
-
2135
2132
if ( theMap . style . sourceWithIdentifier ( id ) ) {
2136
2133
reject ( "Remove the layer with this id first with 'removeLayer': " + id ) ;
2137
2134
return ;
2138
2135
}
2139
2136
2140
- // under iOS we handle lines and circles differently
2141
-
2142
- if ( options . data . geometry . type === 'LineString' ) {
2143
- // after hours and hours of trial and error, I finally stumbled upon how to set things
2144
- // up so that MGLPolylineFeature.polylineWithCoordinatesCount works.
2145
- //
2146
- // Allocating an NSArray and passing it in would cause the app to crash.
2147
- // Creating a javascript array of CLLocationCoodinate2D entries would cause random
2148
- // lines to be drawn on the map.
2149
- //
2150
- // However, allocating a raw C buffer and accessing it through a reference cast to CLLocationCoordinate2D
2151
- // works (to my shock and horror).
2152
-
2153
- const coordinates = options . data . geometry . coordinates ;
2154
-
2155
- const buffer = malloc ( coordinates . length * 2 * interop . sizeof ( interop . types . double ) ) ;
2156
- const clCoordsArray = new interop . Reference ( CLLocationCoordinate2D , buffer ) ;
2157
-
2158
- // We need to convert our coordinate array into an array of CLLocationCoodinate2D elements
2159
- // which are in lat/lng order and not lng/lat
2160
-
2161
- for ( let i = 0 ; i < coordinates . length ; i ++ ) {
2162
- const newCoord : CLLocationCoordinate2D = CLLocationCoordinate2DMake ( coordinates [ i ] [ 1 ] , coordinates [ i ] [ 0 ] ) ;
2163
- clCoordsArray [ i ] = newCoord ;
2164
- }
2165
-
2166
- if ( Trace . isEnabled ( ) ) {
2167
- CLog ( CLogTypes . info , 'Mapbox:addSource(): after CLLocationCoordinate2D array before creating polyline source from clCoordsArray' ) ;
2168
- }
2169
-
2170
- const polyline = MGLPolylineFeature . polylineWithCoordinatesCount ( new interop . Reference ( CLLocationCoordinate2D , clCoordsArray ) , coordinates . length ) ;
2171
-
2172
- source = MGLShapeSource . alloc ( ) . initWithIdentifierShapeOptions ( id , polyline , null ) ;
2173
-
2174
- theMap . style . addSource ( source ) ;
2175
-
2176
- // To support handling click events on lines and circles, we keep the underlying
2177
- // feature.
2178
- //
2179
- // FIXME: There should be a way to get the original feature back out from the source
2180
- // but I have not yet figured out how.
2181
-
2182
- this . lines . push ( {
2183
- type : 'line' ,
2184
- id,
2185
- clCoordsArray,
2186
- numCoords : coordinates . length ,
2187
- source,
2188
- } ) ;
2189
- } else if ( options . data . geometry . type === 'Point' ) {
2190
- // FIXME: should be able to just call addSource here for type geoJson
2191
-
2192
- if ( Trace . isEnabled ( ) ) {
2193
- CLog ( CLogTypes . info , 'Mapbox:addSource(): before addSource with options:' , options ) ;
2194
- }
2195
-
2196
- const geoJSON = `{"type": "FeatureCollection", "features": [ ${ JSON . stringify ( options . data ) } ]}` ;
2197
-
2198
- // this would otherwise crash the app
2199
-
2200
- if ( theMap . style . sourceWithIdentifier ( id ) ) {
2201
- reject ( "Remove the layer with this id first with 'removeLayer': " + id ) ;
2202
- return ;
2203
- }
2204
-
2205
- if ( Trace . isEnabled ( ) ) {
2206
- CLog ( CLogTypes . info , 'Mapbox:addSource(): after checking for existing style' ) ;
2207
- }
2208
-
2209
- const geoDataStr = NSString . stringWithString ( geoJSON ) ;
2210
-
2211
- if ( Trace . isEnabled ( ) ) {
2212
- CLog ( CLogTypes . info , 'Mapbox:addSource(): after string' ) ;
2213
- }
2214
-
2215
- const geoData = geoDataStr . dataUsingEncoding ( NSUTF8StringEncoding ) ;
2216
-
2217
- if ( Trace . isEnabled ( ) ) {
2218
- CLog ( CLogTypes . info , 'Mapbox:addSource(): after encoding' ) ;
2219
- }
2220
-
2221
- const geoDataBase64Enc = geoData . base64EncodedStringWithOptions ( 0 ) ;
2222
-
2223
- if ( Trace . isEnabled ( ) ) {
2224
- CLog ( CLogTypes . info , 'Mapbox:addSource(): before alloc' ) ;
2225
- }
2226
-
2227
- const geo = NSData . alloc ( ) . initWithBase64EncodedStringOptions ( geoDataBase64Enc , null ) ;
2228
-
2229
- if ( Trace . isEnabled ( ) ) {
2230
- CLog ( CLogTypes . info , "Mapbox:addSource(): before shape with id '" + id + "'" ) ;
2231
- }
2232
-
2233
- const shape = MGLShape . shapeWithDataEncodingError ( geo , NSUTF8StringEncoding ) ;
2234
-
2235
- if ( Trace . isEnabled ( ) ) {
2236
- CLog ( CLogTypes . info , "Mapbox:addSource(): after shape before second alloc with id '" + id + "' and shape '" + shape + "'" ) ;
2237
- }
2238
-
2239
- const source = MGLShapeSource . alloc ( ) . initWithIdentifierShapeOptions ( id , shape , null ) ;
2240
-
2241
- if ( Trace . isEnabled ( ) ) {
2242
- CLog ( CLogTypes . info , 'Mapbox:addSource(): before addSource' ) ;
2243
- }
2244
-
2245
- theMap . style . addSource ( source ) ;
2246
-
2247
- // probably a circle
2248
-
2249
- this . circles . push ( {
2250
- type : 'line' ,
2251
- id,
2252
- center : options . data . geometry . coordinates ,
2253
- } ) ;
2254
- }
2137
+ const content : NSString = NSString . stringWithString ( JSON . stringify ( options . data ) ) ;
2138
+ const nsData : NSData = content . dataUsingEncoding ( NSUTF8StringEncoding ) ;
2139
+ const geoJsonShape = MGLShape . shapeWithDataEncodingError ( nsData , NSUTF8StringEncoding ) ;
2140
+
2141
+ source = MGLShapeSource . alloc ( ) . initWithIdentifierShapeOptions ( id , geoJsonShape , null ) ;
2255
2142
2256
2143
break ;
2257
2144
@@ -2719,10 +2606,6 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
2719
2606
reject ( 'Non circle style passed to addCircleLayer()' ) ;
2720
2607
}
2721
2608
2722
- if ( typeof style . source != 'undefined' ) {
2723
- reject ( 'Missing source.' ) ;
2724
- }
2725
-
2726
2609
// the source may be of type geojson, vector, or it may be the id of a source added by addSource().
2727
2610
2728
2611
let sourceId = null ;
0 commit comments