Skip to content

Commit

Permalink
Implementation of RFC 106: Support of Geomtransform JavaScript Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Boudreault committed Dec 9, 2013
1 parent a09f2ae commit c465f6c
Show file tree
Hide file tree
Showing 21 changed files with 1,583 additions and 173 deletions.
37 changes: 24 additions & 13 deletions CMakeLists.txt
Expand Up @@ -171,6 +171,17 @@ renderers/agg/src/agg_line_aa_basics.cpp
renderers/agg/src/clipper.cpp
)
include_directories(renderers/agg/include)

set(v8_SOURCES
mapscript/v8/v8_object_wrap.hpp
mapscript/v8/point.cpp
mapscript/v8/line.cpp
mapscript/v8/shape.cpp
mapscript/v8/v8_mapscript.cpp
mapv8.cpp
)
include_directories(mapscript/v8/)

#add_definitions(-DHASH_DEBUG=1)
if(WIN32)
set(REGEX_SOURCES ${REGEX_DIR}/regex.c)
Expand Down Expand Up @@ -201,18 +212,18 @@ mapogcfiltercommon.c maprendering.c mapwcs20.c mapogcsld.c
mapresample.c mapwfs.c mapgdal.c mapogcsos.c mapscale.c mapwfs11.c
mapgeomtransform.c mapogroutput.c mapsde.c mapwfslayer.c mapagg.cpp mapkml.cpp
mapgeomutil.cpp mapkmlrenderer.cpp fontcache.c textlayout.c
mapogr.cpp mapcontour.c mapsmoothing.c mapv8.cpp ${REGEX_SOURCES})
mapogr.cpp mapcontour.c mapsmoothing.c ${REGEX_SOURCES})

if(BUILD_DYNAMIC)
add_library(mapserver SHARED ${mapserver_SOURCES} ${agg_SOURCES})
add_library(mapserver SHARED ${mapserver_SOURCES} ${agg_SOURCES} ${v8_SOURCES})
set_target_properties( mapserver PROPERTIES
VERSION ${MapServer_VERSION_STRING}
SOVERSION 1
)
endif(BUILD_DYNAMIC)

if(BUILD_STATIC)
add_library(mapserver_static STATIC ${mapserver_SOURCES} ${agg_SOURCES})
add_library(mapserver_static STATIC ${mapserver_SOURCES} ${agg_SOURCES} ${v8_SOURCES})
set_target_properties( mapserver_static PROPERTIES
VERSION ${MapServer_VERSION_STRING}
SOVERSION 1
Expand Down Expand Up @@ -732,18 +743,18 @@ if(WITH_PYTHON)
endif(WITH_PYTHON)

if(WITH_V8)
find_package(V8)
if(V8_FOUND EQUAL 1)
set(USE_V8 1)
include_directories(${V8_INCLUDE})
ms_link_libraries( ${V8_LIBS})
else(V8_FOUND)
message(SEND_ERROR "V8 JavaScript support requested but not found.
FIND_PACKAGE(V8)
IF(V8_FOUND EQUAL 1)
SET(USE_V8_MAPSCRIPT 1)
INCLUDE_DIRECTORIES(${V8_INCLUDE})
MS_LINK_LIBRARIES( ${V8_LIBS})
ELSE(V8_FOUND)
MESSAGE(SEND_ERROR "V8 JavaScript support requested but not found.
HINTS:
- set V8_ROOT environment variable to the installation path of V8.
- add the V8 install directory to the CMAKE_PREFIX_PATH variable (-DCMAKE_PREFIX_PATH=\"/path/to/${component}-install-dir;/path/to/other/dirs\") ")
endif()
endif(WITH_V8)
ENDIF()
ENDIF(WITH_V8)

if(WITH_PHP)
add_subdirectory("mapscript/php")
Expand Down Expand Up @@ -867,7 +878,6 @@ status_optional_feature("Thread-safety support" "${USE_THREAD}")
status_optional_feature("KML output" "${USE_KML}")
status_optional_feature("Z+M point coordinate support" "${USE_POINT_Z_M}")
status_optional_feature("XML Mapfile support" "${USE_XMLMAPFILE}")
status_optional_feature("V8 JavaScript" "${USE_V8}")

message(STATUS " * Mapscripts")
status_optional_feature("Python" "${USE_PYTHON_MAPSCRIPT}")
Expand All @@ -876,6 +886,7 @@ status_optional_feature("PERL" "${USE_PERL_MAPSCRIPT}")
status_optional_feature("RUBY" "${USE_RUBY_MAPSCRIPT}")
status_optional_feature("JAVA" "${USE_JAVA_MAPSCRIPT}")
status_optional_feature("C#" "${USE_CSHARP_MAPSCRIPT}")
status_optional_feature("V8 Javascript" "${USE_V8_MAPSCRIPT}")
status_optional_feature("Apache Module (Experimental)" "${USE_APACHE_MODULE}")

message(STATUS "")
Expand Down
2 changes: 1 addition & 1 deletion maperror.c
Expand Up @@ -572,7 +572,7 @@ char *msGetVersion()
#ifdef USE_POINT_Z_M
strcat(version, " SUPPORTS=POINT_Z_M");
#endif
#ifdef USE_V8
#ifdef USE_V8_MAPSCRIPT
strcat(version, " SUPPORTS=V8");
#endif
#ifdef USE_JPEG
Expand Down
2 changes: 1 addition & 1 deletion mapfile.c
Expand Up @@ -5896,7 +5896,7 @@ int initMap(mapObj *map)

msInitQuery(&(map->query));

#ifdef USE_V8
#ifdef USE_V8_MAPSCRIPT
map->v8context = NULL;
#endif

Expand Down
17 changes: 15 additions & 2 deletions mapgeomtransform.c
Expand Up @@ -221,8 +221,21 @@ int msDrawTransformedShape(mapObj *map, imageObj *image, shapeObj *shape, styleO
int msGeomTransformShape(mapObj *map, layerObj *layer, shapeObj *shape)
{
int i;
expressionObj *e = &layer->_geomtransform;

expressionObj *e = &layer->_geomtransform;

#ifdef USE_V8_MAPSCRIPT
if (!map->v8context) {
msV8CreateContext(map);
if (!map->v8context)
{
msSetError(MS_V8ERR, "Unable to create v8 context.", "msGeomTransformShape()");
return MS_FAILURE;
}
}

msV8ContextSetLayer(map, layer);
#endif

switch(e->type) {
case MS_GEOMTRANSFORM_EXPRESSION: {
int status;
Expand Down
10 changes: 9 additions & 1 deletion maplayer.c
Expand Up @@ -271,6 +271,14 @@ int msLayerNextShape(layerObj *layer, shapeObj *shape)
return rv;
}

#ifdef USE_V8_MAPSCRIPT
/* we need to force the GetItems for the geomtransform attributes */
if(!layer->items &&
layer->_geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION &&
strstr(layer->_geomtransform.string, "javascript"))
msLayerGetItems(layer);
#endif

/* At the end of switch case (default -> break; -> return MS_FAILURE),
* was following TODO ITEM:
*/
Expand Down Expand Up @@ -868,7 +876,7 @@ int msLayerGetFeatureStyle(mapObj *map, layerObj *layer, classObj *c, shapeObj*
stylestring = msStrdup(shape->values[layer->styleitemindex]);
}
else if (strncasecmp(layer->styleitem,"javascript://",13) == 0) {
#ifdef USE_V8
#ifdef USE_V8_MAPSCRIPT
char *filename = layer->styleitem+13;

if (!map->v8context) {
Expand Down
1 change: 1 addition & 0 deletions maplexer.l
Expand Up @@ -189,6 +189,7 @@ char path[MS_MAXPATHLEN];
<EXPRESSION_STRING>simplifypt { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_SIMPLIFYPT); }
<EXPRESSION_STRING>generalize { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_GENERALIZE); }
<EXPRESSION_STRING>smoothsia { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_SMOOTHSIA); }
<EXPRESSION_STRING>javascript { MS_LEXER_RETURN_TOKEN(MS_TOKEN_FUNCTION_JAVASCRIPT); }

<EXPRESSION_STRING>intersects { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_INTERSECTS); }
<EXPRESSION_STRING>disjoint { MS_LEXER_RETURN_TOKEN(MS_TOKEN_COMPARISON_DISJOINT); }
Expand Down
2 changes: 1 addition & 1 deletion mapobject.c
Expand Up @@ -137,7 +137,7 @@ void msFreeMap(mapObj *map)

msFreeQuery(&(map->query));

#ifdef USE_V8
#ifdef USE_V8_MAPSCRIPT
if (map->v8context)
msV8FreeContext(map);
#endif
Expand Down
16 changes: 14 additions & 2 deletions mapparser.y
Expand Up @@ -46,7 +46,7 @@ int yyerror(parseObj *, const char *);
%left INTERSECTS DISJOINT TOUCHES OVERLAPS CROSSES WITHIN CONTAINS BEYOND DWITHIN
%left AREA LENGTH COMMIFY ROUND
%left TOSTRING
%left YYBUFFER DIFFERENCE SIMPLIFY SIMPLIFYPT GENERALIZE SMOOTHSIA
%left YYBUFFER DIFFERENCE SIMPLIFY SIMPLIFYPT GENERALIZE SMOOTHSIA JAVASCRIPT
%left '+' '-'
%left '*' '/' '%'
%left NEG
Expand Down Expand Up @@ -629,6 +629,17 @@ shape_exp: SHAPE
s->scratch = MS_TRUE;
$$ = s;
}
| JAVASCRIPT '(' shape_exp ',' string_exp ')' {
shapeObj *s;
s = msV8TransformShape($3, $5);
free($5);
if(!s) {
yyerror(p, "Executing javascript failed.");
return(-1);
}
s->scratch = MS_TRUE;
$$ = s;
}
;

string_exp: STRING
Expand Down Expand Up @@ -752,7 +763,8 @@ int yylex(YYSTYPE *lvalp, parseObj *p)
case MS_TOKEN_FUNCTION_SIMPLIFY: token = SIMPLIFY; break;
case MS_TOKEN_FUNCTION_SIMPLIFYPT: token = SIMPLIFYPT; break;
case MS_TOKEN_FUNCTION_GENERALIZE: token = GENERALIZE; break;
case MS_TOKEN_FUNCTION_SMOOTHSIA: token = SMOOTHSIA; break;
case MS_TOKEN_FUNCTION_SMOOTHSIA: token = SMOOTHSIA; break;
case MS_TOKEN_FUNCTION_JAVASCRIPT: token = JAVASCRIPT; break;

default:
break;
Expand Down

0 comments on commit c465f6c

Please sign in to comment.