@@ -123,43 +123,57 @@ CustomDataTypeDANTE.prototype.getJSKOSPreview = (data, mapbox_access_token = fal
123
123
# Karte, zeige nur einen Ort
124
124
location = ' '
125
125
if data .location
126
- if data .location .length > 0
127
126
# if mapbox-token given
128
- if mapbox_access_token
129
- for key, value of data .location
130
- # wrap value in "geometry"
131
- value = JSON .parse (' {"geometry": ' + JSON .stringify (value) + ' }' )
132
-
133
- # generates static mapbox-map via geojson
134
- htmlContent = ' {"type": "FeatureCollection","features": []}'
135
-
136
- # compare to https://www.mapbox.com/mapbox.js/example/v1.0.0/static-map-from-geojson-with-geo-viewport/
137
- jsonStr = ' {"type": "FeatureCollection","features": []}'
138
- json = JSON .parse (jsonStr)
139
-
140
- json .features .push value
141
-
142
- bounds = geojsonExtent (json)
143
- if bounds
144
- size = [
145
- 500
146
- 300
147
- ]
148
- vp = geoViewport .viewport (bounds, size)
149
- encodedGeoJSON = value
150
- encodedGeoJSON .properties = {}
151
- encodedGeoJSON .type = " Feature"
152
- encodedGeoJSON .properties [' stroke-width' ] = 4
153
- encodedGeoJSON .properties [' stroke' ] = ' #C20000'
154
- encodedGeoJSON = JSON .stringify (encodedGeoJSON)
155
- encodedGeoJSON = encodeURIComponent (encodedGeoJSON)
156
- if vp .zoom > 16
157
- vp .zoom = 15 ;
158
- imageSrc = ' https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v12/static/geojson(' + encodedGeoJSON + ' )/' + vp .center .join (' ,' ) + ' ,' + vp .zoom + ' /' + size .join (' x' ) + ' @2x?access_token=' + mapbox_access_token
159
- htmlContent = " <div class=\" mapImage\" style=\" background-image: url('" + imageSrc + " ');\" ></div>"
160
- location += htmlContent
161
- if location != ' '
162
- html += ' <h4>' + $$ (' custom.data.type.dante.modal.form.popup.jskospreview.georef' ) + ' </h4>' + location
127
+ if mapbox_access_token
128
+ # default feature?
129
+ if data .location .type == ' Point' || data .location .type == ' Polygon' || data .location .type == ' LineString'
130
+ data .location = [data .location ]
131
+ # geometryCollection?
132
+ if data .location .type == ' GeometryCollection'
133
+ data .location = data .location .geometries ;
134
+ # MultiPolygon?
135
+ if data .location .type == ' MultiPolygon'
136
+ locations = []
137
+ for key, value of data .location .coordinates
138
+ polygon = JSON .parse (' {"type": "Polygon","coordinates": []}' )
139
+ polygon .coordinates = value[0 ]
140
+ locations .push polygon
141
+ data .location = locations
142
+
143
+ for key, value of data .location
144
+ # wrap value in "geometry"
145
+ value = JSON .parse (' {"geometry": ' + JSON .stringify (value) + ' }' )
146
+
147
+ # generates static mapbox-map via geojson
148
+ htmlContent = ' {"type": "FeatureCollection","features": []}'
149
+
150
+ # compare to https://www.mapbox.com/mapbox.js/example/v1.0.0/static-map-from-geojson-with-geo-viewport/
151
+ jsonStr = ' {"type": "FeatureCollection","features": []}'
152
+ json = JSON .parse (jsonStr)
153
+
154
+ json .features .push value
155
+
156
+ bounds = geojsonExtent (json)
157
+ if bounds
158
+ size = [
159
+ 500
160
+ 300
161
+ ]
162
+ vp = geoViewport .viewport (bounds, size)
163
+ encodedGeoJSON = value
164
+ encodedGeoJSON .properties = {}
165
+ encodedGeoJSON .type = " Feature"
166
+ encodedGeoJSON .properties [' stroke-width' ] = 4
167
+ encodedGeoJSON .properties [' stroke' ] = ' #C20000'
168
+ encodedGeoJSON = JSON .stringify (encodedGeoJSON)
169
+ encodedGeoJSON = encodeURIComponent (encodedGeoJSON)
170
+ if vp .zoom > 16
171
+ vp .zoom = 15 ;
172
+ imageSrc = ' https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v12/static/geojson(' + encodedGeoJSON + ' )/' + vp .center .join (' ,' ) + ' ,' + vp .zoom + ' /' + size .join (' x' ) + ' @2x?access_token=' + mapbox_access_token
173
+ htmlContent = " <div class=\" mapImage\" style=\" background-image: url('" + imageSrc + " ');\" ></div>"
174
+ location += htmlContent
175
+ if location != ' '
176
+ html += ' <h4>' + $$ (' custom.data.type.dante.modal.form.popup.jskospreview.georef' ) + ' </h4>' + location
163
177
164
178
# Definitions ("de" first)
165
179
definition = ' '
0 commit comments